10a8165d7SJaegeuk Kim /* 239a53e0cSJaegeuk Kim * fs/f2fs/f2fs.h 339a53e0cSJaegeuk Kim * 439a53e0cSJaegeuk Kim * Copyright (c) 2012 Samsung Electronics Co., Ltd. 539a53e0cSJaegeuk Kim * http://www.samsung.com/ 639a53e0cSJaegeuk Kim * 739a53e0cSJaegeuk Kim * This program is free software; you can redistribute it and/or modify 839a53e0cSJaegeuk Kim * it under the terms of the GNU General Public License version 2 as 939a53e0cSJaegeuk Kim * published by the Free Software Foundation. 1039a53e0cSJaegeuk Kim */ 1139a53e0cSJaegeuk Kim #ifndef _LINUX_F2FS_H 1239a53e0cSJaegeuk Kim #define _LINUX_F2FS_H 1339a53e0cSJaegeuk Kim 1439a53e0cSJaegeuk Kim #include <linux/types.h> 1539a53e0cSJaegeuk Kim #include <linux/page-flags.h> 1639a53e0cSJaegeuk Kim #include <linux/buffer_head.h> 1739a53e0cSJaegeuk Kim #include <linux/slab.h> 1839a53e0cSJaegeuk Kim #include <linux/crc32.h> 1939a53e0cSJaegeuk Kim #include <linux/magic.h> 20c2d715d1SJaegeuk Kim #include <linux/kobject.h> 217bd59381SGu Zheng #include <linux/sched.h> 2239307a8eSJaegeuk Kim #include <linux/vmalloc.h> 23740432f8SJaegeuk Kim #include <linux/bio.h> 24d0239e1bSJaegeuk Kim #include <linux/blkdev.h> 250abd675eSChao Yu #include <linux/quotaops.h> 2646f47e48SEric Biggers #ifdef CONFIG_F2FS_FS_ENCRYPTION 2746f47e48SEric Biggers #include <linux/fscrypt_supp.h> 2846f47e48SEric Biggers #else 2946f47e48SEric Biggers #include <linux/fscrypt_notsupp.h> 3046f47e48SEric Biggers #endif 3143b6573bSKeith Mok #include <crypto/hash.h> 3239a53e0cSJaegeuk Kim 335d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 349850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 355d56b671SJaegeuk Kim #else 369850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 379850cf4aSJaegeuk Kim do { \ 389850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 399850cf4aSJaegeuk Kim WARN_ON(1); \ 40caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 419850cf4aSJaegeuk Kim } \ 429850cf4aSJaegeuk Kim } while (0) 435d56b671SJaegeuk Kim #endif 445d56b671SJaegeuk Kim 452c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 462c63feadSJaegeuk Kim enum { 472c63feadSJaegeuk Kim FAULT_KMALLOC, 48c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 49cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 50cb78942bSJaegeuk Kim FAULT_ORPHAN, 51cb78942bSJaegeuk Kim FAULT_BLOCK, 52cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5353aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 5414b44d23SJaegeuk Kim FAULT_TRUNCATE, 558b038c70SChao Yu FAULT_IO, 560f348028SChao Yu FAULT_CHECKPOINT, 572c63feadSJaegeuk Kim FAULT_MAX, 582c63feadSJaegeuk Kim }; 592c63feadSJaegeuk Kim 6008796897SSheng Yong struct f2fs_fault_info { 6108796897SSheng Yong atomic_t inject_ops; 6208796897SSheng Yong unsigned int inject_rate; 6308796897SSheng Yong unsigned int inject_type; 6408796897SSheng Yong }; 6508796897SSheng Yong 662c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX]; 6768afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 682c63feadSJaegeuk Kim #endif 692c63feadSJaegeuk Kim 7039a53e0cSJaegeuk Kim /* 7139a53e0cSJaegeuk Kim * For mount options 7239a53e0cSJaegeuk Kim */ 7339a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 7439a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7539a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 80444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 811001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8234d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8334d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8434d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 85d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8689672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 876aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 88343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 8973faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 9036abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 9136abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 920abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA 0x00080000 930abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA 0x00100000 945c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA 0x00200000 954b2414d0SChao Yu #define F2FS_MOUNT_QUOTA 0x00400000 9639a53e0cSJaegeuk Kim 9768afcf2dSTomohiro Kusumi #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) 9868afcf2dSTomohiro Kusumi #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) 9968afcf2dSTomohiro Kusumi #define test_opt(sbi, option) ((sbi)->mount_opt.opt & F2FS_MOUNT_##option) 10039a53e0cSJaegeuk Kim 10139a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 10239a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 10339a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 10439a53e0cSJaegeuk Kim 105a9841c4dSJaegeuk Kim typedef u32 block_t; /* 106a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 107a9841c4dSJaegeuk Kim * address format, __le32. 108a9841c4dSJaegeuk Kim */ 10939a53e0cSJaegeuk Kim typedef u32 nid_t; 11039a53e0cSJaegeuk Kim 11139a53e0cSJaegeuk Kim struct f2fs_mount_info { 11239a53e0cSJaegeuk Kim unsigned int opt; 11339a53e0cSJaegeuk Kim }; 11439a53e0cSJaegeuk Kim 115cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1160bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 117e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1187a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1195c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 120704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 121cde4de12SJaegeuk Kim 12276f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 12376f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 12476f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 125c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 12676f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 127c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 12876f105a2SJaegeuk Kim 12939a53e0cSJaegeuk Kim /* 13039a53e0cSJaegeuk Kim * For checkpoint manager 13139a53e0cSJaegeuk Kim */ 13239a53e0cSJaegeuk Kim enum { 13339a53e0cSJaegeuk Kim NAT_BITMAP, 13439a53e0cSJaegeuk Kim SIT_BITMAP 13539a53e0cSJaegeuk Kim }; 13639a53e0cSJaegeuk Kim 137c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 138c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 139c473f1a9SChao Yu #define CP_SYNC 0x00000004 140c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 141c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1421f43e2adSChao Yu #define CP_TRIMMED 0x00000020 14375ab4cb8SJaegeuk Kim 14447b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 145bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 1464ddb1a4dSJaegeuk Kim (GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections)) 147a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 148a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 1494ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 15015469963SJaegeuk Kim #define DISCARD_ISSUE_RATE 8 151969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 152969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 15360b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 154dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 155bba681cbSJaegeuk Kim 15675ab4cb8SJaegeuk Kim struct cp_control { 15775ab4cb8SJaegeuk Kim int reason; 1584b2fecc8SJaegeuk Kim __u64 trim_start; 1594b2fecc8SJaegeuk Kim __u64 trim_end; 1604b2fecc8SJaegeuk Kim __u64 trim_minlen; 1614b2fecc8SJaegeuk Kim __u64 trimmed; 16275ab4cb8SJaegeuk Kim }; 16375ab4cb8SJaegeuk Kim 164662befdaSChao Yu /* 16581c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 166662befdaSChao Yu */ 167662befdaSChao Yu enum { 168662befdaSChao Yu META_CP, 169662befdaSChao Yu META_NAT, 17081c1a0f1SChao Yu META_SIT, 1714c521f49SJaegeuk Kim META_SSA, 1724c521f49SJaegeuk Kim META_POR, 173662befdaSChao Yu }; 174662befdaSChao Yu 1756451e041SJaegeuk Kim /* for the list of ino */ 1766451e041SJaegeuk Kim enum { 1776451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 178fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 179fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1806451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1816451e041SJaegeuk Kim }; 1826451e041SJaegeuk Kim 1836451e041SJaegeuk Kim struct ino_entry { 18439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18539a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 18639a53e0cSJaegeuk Kim }; 18739a53e0cSJaegeuk Kim 1882710fd7eSChao Yu /* for the list of inodes to be GCed */ 18906292073SChao Yu struct inode_entry { 19039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 19139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 19239a53e0cSJaegeuk Kim }; 19339a53e0cSJaegeuk Kim 194a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 1957fd9e544SJaegeuk Kim struct discard_entry { 1967fd9e544SJaegeuk Kim struct list_head list; /* list head */ 197a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 198a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 1997fd9e544SJaegeuk Kim }; 2007fd9e544SJaegeuk Kim 201969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 202969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 203969d1b18SChao Yu 204ba48a33eSChao Yu /* max discard pend list number */ 205ba48a33eSChao Yu #define MAX_PLIST_NUM 512 206ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 207ba48a33eSChao Yu (MAX_PLIST_NUM - 1) : (blk_num - 1)) 208ba48a33eSChao Yu 209969d1b18SChao Yu #define P_ACTIVE 0x01 210969d1b18SChao Yu #define P_TRIM 0x02 211969d1b18SChao Yu #define plist_issue(tag) (((tag) & P_ACTIVE) || ((tag) & P_TRIM)) 212969d1b18SChao Yu 21315469963SJaegeuk Kim enum { 21415469963SJaegeuk Kim D_PREP, 21515469963SJaegeuk Kim D_SUBMIT, 21615469963SJaegeuk Kim D_DONE, 21715469963SJaegeuk Kim }; 21815469963SJaegeuk Kim 219004b6862SChao Yu struct discard_info { 220b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 221b01a9201SJaegeuk Kim block_t len; /* length */ 222004b6862SChao Yu block_t start; /* actual start address in dev */ 223004b6862SChao Yu }; 224004b6862SChao Yu 225b01a9201SJaegeuk Kim struct discard_cmd { 226004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 227004b6862SChao Yu union { 228004b6862SChao Yu struct { 229004b6862SChao Yu block_t lstart; /* logical start address */ 230004b6862SChao Yu block_t len; /* length */ 231004b6862SChao Yu block_t start; /* actual start address in dev */ 232004b6862SChao Yu }; 233004b6862SChao Yu struct discard_info di; /* discard info */ 234004b6862SChao Yu 235004b6862SChao Yu }; 236b01a9201SJaegeuk Kim struct list_head list; /* command list */ 237b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 238c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 239ec9895adSChao Yu unsigned short ref; /* reference count */ 2409a744b92SChao Yu unsigned char state; /* state */ 241c81abe34SJaegeuk Kim int error; /* bio error */ 242275b66b0SChao Yu }; 243275b66b0SChao Yu 2440b54fb84SJaegeuk Kim struct discard_cmd_control { 24515469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 24646f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 247ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 248969d1b18SChao Yu unsigned char pend_list_tag[MAX_PLIST_NUM];/* tag for pending entries */ 24946f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 25015469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 251969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 25215469963SJaegeuk Kim struct mutex cmd_lock; 253d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 254d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 255969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 256d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 2578b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 2588b8dd65fSChao Yu atomic_t issing_discard; /* # of issing discard */ 2595f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 260004b6862SChao Yu struct rb_root root; /* root of discard rb-tree */ 26139a53e0cSJaegeuk Kim }; 26239a53e0cSJaegeuk Kim 26339a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 26439a53e0cSJaegeuk Kim struct fsync_inode_entry { 26539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 26639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 267c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 268c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 26939a53e0cSJaegeuk Kim }; 27039a53e0cSJaegeuk Kim 27168afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 27268afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 27339a53e0cSJaegeuk Kim 27468afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 27568afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 27668afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 27768afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 27839a53e0cSJaegeuk Kim 279dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 280dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 281309cc2b6SJaegeuk Kim 282dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 28339a53e0cSJaegeuk Kim { 284dfc08a12SChao Yu int before = nats_in_cursum(journal); 285cac5a3d8SDongOh Shin 286dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 28739a53e0cSJaegeuk Kim return before; 28839a53e0cSJaegeuk Kim } 28939a53e0cSJaegeuk Kim 290dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 29139a53e0cSJaegeuk Kim { 292dfc08a12SChao Yu int before = sits_in_cursum(journal); 293cac5a3d8SDongOh Shin 294dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 29539a53e0cSJaegeuk Kim return before; 29639a53e0cSJaegeuk Kim } 29739a53e0cSJaegeuk Kim 298dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 299dfc08a12SChao Yu int size, int type) 300184a5cd2SChao Yu { 301184a5cd2SChao Yu if (type == NAT_JOURNAL) 302dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 303dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 304184a5cd2SChao Yu } 305184a5cd2SChao Yu 30639a53e0cSJaegeuk Kim /* 307e9750824SNamjae Jeon * ioctl commands 308e9750824SNamjae Jeon */ 309e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 310e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 311d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 312e9750824SNamjae Jeon 31388b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 31488b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 31588b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 31602a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 3171e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 3181e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 319d07efb50SJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32) 320456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 321d07efb50SJaegeuk Kim #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \ 322d07efb50SJaegeuk Kim struct f2fs_defragment) 3234dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 3244dd6f977SJaegeuk Kim struct f2fs_move_range) 325e066b83cSJaegeuk Kim #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ 326e066b83cSJaegeuk Kim struct f2fs_flush_device) 32734dc77adSJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ 32834dc77adSJaegeuk Kim struct f2fs_gc_range) 329e65ef207SJaegeuk Kim #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) 33088b88a66SJaegeuk Kim 3310b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 3320b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 3330b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 334f424f664SJaegeuk Kim 3351abff93dSJaegeuk Kim /* 3361abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 3371abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 3381abff93dSJaegeuk Kim */ 3391abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 3401abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 3411abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 3421abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 343c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 3441abff93dSJaegeuk Kim 345e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 346e9750824SNamjae Jeon /* 347e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 348e9750824SNamjae Jeon */ 349e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 350e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 35104ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 352e9750824SNamjae Jeon #endif 353e9750824SNamjae Jeon 3542c1d0305SChao Yu #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR 3552c1d0305SChao Yu #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR 3562c1d0305SChao Yu 35734dc77adSJaegeuk Kim struct f2fs_gc_range { 35834dc77adSJaegeuk Kim u32 sync; 35934dc77adSJaegeuk Kim u64 start; 36034dc77adSJaegeuk Kim u64 len; 36134dc77adSJaegeuk Kim }; 36234dc77adSJaegeuk Kim 363d323d005SChao Yu struct f2fs_defragment { 364d323d005SChao Yu u64 start; 365d323d005SChao Yu u64 len; 366d323d005SChao Yu }; 367d323d005SChao Yu 3684dd6f977SJaegeuk Kim struct f2fs_move_range { 3694dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3704dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3714dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3724dd6f977SJaegeuk Kim u64 len; /* size to move */ 3734dd6f977SJaegeuk Kim }; 3744dd6f977SJaegeuk Kim 375e066b83cSJaegeuk Kim struct f2fs_flush_device { 376e066b83cSJaegeuk Kim u32 dev_num; /* device number to flush */ 377e066b83cSJaegeuk Kim u32 segments; /* # of segments to flush */ 378e066b83cSJaegeuk Kim }; 379e066b83cSJaegeuk Kim 380f2470371SChao Yu /* for inline stuff */ 381f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 3827a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 3837a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 3847a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 3857a2af766SChao Yu DEF_INLINE_RESERVED_SIZE - \ 386f2470371SChao Yu F2FS_INLINE_XATTR_ADDRS)) 387f2470371SChao Yu 388f2470371SChao Yu /* for inline dir */ 389f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 390f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 391f2470371SChao Yu BITS_PER_BYTE + 1)) 392f2470371SChao Yu #define INLINE_DENTRY_BITMAP_SIZE(inode) ((NR_INLINE_DENTRY(inode) + \ 393f2470371SChao Yu BITS_PER_BYTE - 1) / BITS_PER_BYTE) 394f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 395f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 396f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 397f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 398f2470371SChao Yu 399e9750824SNamjae Jeon /* 40039a53e0cSJaegeuk Kim * For INODE and NODE manager 40139a53e0cSJaegeuk Kim */ 4027b3cd7d6SJaegeuk Kim /* for directory operations */ 4037b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 404d8c6822aSJaegeuk Kim struct inode *inode; 40576a9dd85SChao Yu void *bitmap; 4067b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 4077b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 4087b3cd7d6SJaegeuk Kim int max; 40976a9dd85SChao Yu int nr_bitmap; 4107b3cd7d6SJaegeuk Kim }; 4117b3cd7d6SJaegeuk Kim 41264c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 41364c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 4147b3cd7d6SJaegeuk Kim { 415d8c6822aSJaegeuk Kim d->inode = inode; 4167b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 41776a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 4187b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 4197b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 4207b3cd7d6SJaegeuk Kim d->filename = t->filename; 42164c24ecbSTomohiro Kusumi } 422cac5a3d8SDongOh Shin 42364c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 424f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 42564c24ecbSTomohiro Kusumi { 426f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 427f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 428f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 429f2470371SChao Yu 43064c24ecbSTomohiro Kusumi d->inode = inode; 431f2470371SChao Yu d->max = entry_cnt; 432f2470371SChao Yu d->nr_bitmap = bitmap_size; 433f2470371SChao Yu d->bitmap = t; 434f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 435f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 436f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 4377b3cd7d6SJaegeuk Kim } 4387b3cd7d6SJaegeuk Kim 439dbe6a5ffSJaegeuk Kim /* 440dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 441dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 442dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 44339a53e0cSJaegeuk Kim */ 444dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 445dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 446266e97a8SJaegeuk Kim enum { 447266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 448266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 449266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 450266e97a8SJaegeuk Kim * look up a node with readahead called 4514f4124d0SChao Yu * by get_data_block. 45239a53e0cSJaegeuk Kim */ 453266e97a8SJaegeuk Kim }; 454266e97a8SJaegeuk Kim 455a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 45639a53e0cSJaegeuk Kim 457817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 458817202d9SChao Yu 45913054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 46013054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 46113054c54SChao Yu 46239a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 46313054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 46413054c54SChao Yu 46513054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 46613054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 467c11abd1aSJaegeuk Kim 46854c2258cSChao Yu struct rb_entry { 46954c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 47054c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 47154c2258cSChao Yu unsigned int len; /* length of the entry */ 47254c2258cSChao Yu }; 47354c2258cSChao Yu 47439a53e0cSJaegeuk Kim struct extent_info { 47539a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 476111d2495SMasanari Iida unsigned int len; /* length of the extent */ 47754c2258cSChao Yu u32 blk; /* start block address of the extent */ 47839a53e0cSJaegeuk Kim }; 47939a53e0cSJaegeuk Kim 48013054c54SChao Yu struct extent_node { 48154c2258cSChao Yu struct rb_node rb_node; 48254c2258cSChao Yu union { 48354c2258cSChao Yu struct { 48454c2258cSChao Yu unsigned int fofs; 48554c2258cSChao Yu unsigned int len; 48654c2258cSChao Yu u32 blk; 48754c2258cSChao Yu }; 48813054c54SChao Yu struct extent_info ei; /* extent info */ 48954c2258cSChao Yu 49054c2258cSChao Yu }; 49154c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 492201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 49313054c54SChao Yu }; 49413054c54SChao Yu 49513054c54SChao Yu struct extent_tree { 49613054c54SChao Yu nid_t ino; /* inode number */ 49713054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 49862c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 4993e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 500137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 50113054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 50268e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 50313054c54SChao Yu }; 50413054c54SChao Yu 50539a53e0cSJaegeuk Kim /* 506003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 507003a3e1dSJaegeuk Kim * 508003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 509003a3e1dSJaegeuk Kim */ 510003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 511003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 5127f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 5137f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 5147f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 515003a3e1dSJaegeuk Kim 516003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 517003a3e1dSJaegeuk Kim block_t m_pblk; 518003a3e1dSJaegeuk Kim block_t m_lblk; 519003a3e1dSJaegeuk Kim unsigned int m_len; 520003a3e1dSJaegeuk Kim unsigned int m_flags; 521da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 522003a3e1dSJaegeuk Kim }; 523003a3e1dSJaegeuk Kim 524e2b4e2bcSChao Yu /* for flag in get_data_block */ 525f2220c7fSQiuyang Sun enum { 526f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 527f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 528f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 529f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 530f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 531f2220c7fSQiuyang Sun }; 532e2b4e2bcSChao Yu 533003a3e1dSJaegeuk Kim /* 53439a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 53539a53e0cSJaegeuk Kim */ 53639a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 537354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 538cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 539e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 54026787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 54139a53e0cSJaegeuk Kim 542b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 543b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 544b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 545b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 546b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 547b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 548cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 549cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 550cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 551e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 552e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 55326787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 55426787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 555cde4de12SJaegeuk Kim 556ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 557ab9fa662SJaegeuk Kim 55839a53e0cSJaegeuk Kim struct f2fs_inode_info { 55939a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 56039a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 56139a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 56238431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 56339a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 5646666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 56539a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 56639a53e0cSJaegeuk Kim 56739a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 56839a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 569d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 570204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 57139a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 57239a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 57388c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 574b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 57539a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 57626de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 57788b88a66SJaegeuk Kim 5780abd675eSChao Yu #ifdef CONFIG_QUOTA 5790abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 5800abd675eSChao Yu 5810abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 5820abd675eSChao Yu qsize_t i_reserved_quota; 5830abd675eSChao Yu #endif 5840f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 5850f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 58688b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 5877a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 58888b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 5893e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 59082e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 5915a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 592f2470371SChao Yu 5937a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 5945c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 59539a53e0cSJaegeuk Kim }; 59639a53e0cSJaegeuk Kim 59739a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 598bd933d4fSChao Yu struct f2fs_extent *i_ext) 59939a53e0cSJaegeuk Kim { 600bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 601bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 602bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 60339a53e0cSJaegeuk Kim } 60439a53e0cSJaegeuk Kim 60539a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 60639a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 60739a53e0cSJaegeuk Kim { 60839a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 6094d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 61039a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 61139a53e0cSJaegeuk Kim } 61239a53e0cSJaegeuk Kim 613429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 614429511cdSChao Yu u32 blk, unsigned int len) 615429511cdSChao Yu { 616429511cdSChao Yu ei->fofs = fofs; 617429511cdSChao Yu ei->blk = blk; 618429511cdSChao Yu ei->len = len; 619429511cdSChao Yu } 620429511cdSChao Yu 621004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 622004b6862SChao Yu struct discard_info *front) 623004b6862SChao Yu { 624004b6862SChao Yu return back->lstart + back->len == front->lstart; 625004b6862SChao Yu } 626004b6862SChao Yu 627004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 628004b6862SChao Yu struct discard_info *back) 629004b6862SChao Yu { 630004b6862SChao Yu return __is_discard_mergeable(back, cur); 631004b6862SChao Yu } 632004b6862SChao Yu 633004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 634004b6862SChao Yu struct discard_info *front) 635004b6862SChao Yu { 636004b6862SChao Yu return __is_discard_mergeable(cur, front); 637004b6862SChao Yu } 638004b6862SChao Yu 639429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 640429511cdSChao Yu struct extent_info *front) 641429511cdSChao Yu { 642429511cdSChao Yu return (back->fofs + back->len == front->fofs && 643429511cdSChao Yu back->blk + back->len == front->blk); 644429511cdSChao Yu } 645429511cdSChao Yu 646429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 647429511cdSChao Yu struct extent_info *back) 648429511cdSChao Yu { 649429511cdSChao Yu return __is_extent_mergeable(back, cur); 650429511cdSChao Yu } 651429511cdSChao Yu 652429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 653429511cdSChao Yu struct extent_info *front) 654429511cdSChao Yu { 655429511cdSChao Yu return __is_extent_mergeable(cur, front); 656429511cdSChao Yu } 657429511cdSChao Yu 658cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 659205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 660205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 6614abd3f5aSChao Yu { 662205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 6634abd3f5aSChao Yu et->largest = en->ei; 6647c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 665205b9822SJaegeuk Kim } 6664abd3f5aSChao Yu } 6674abd3f5aSChao Yu 668b8559dc2SChao Yu enum nid_list { 669b8559dc2SChao Yu FREE_NID_LIST, 670b8559dc2SChao Yu ALLOC_NID_LIST, 671b8559dc2SChao Yu MAX_NID_LIST, 672b8559dc2SChao Yu }; 673b8559dc2SChao Yu 67439a53e0cSJaegeuk Kim struct f2fs_nm_info { 67539a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 67639a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 67704d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 67839a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 679cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 680ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 6812304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 68239a53e0cSJaegeuk Kim 68339a53e0cSJaegeuk Kim /* NAT cache management */ 68439a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 685309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 686b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 68739a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 688309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 689aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 69022ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 69139a53e0cSJaegeuk Kim 69239a53e0cSJaegeuk Kim /* free node ids management */ 6938a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 694b8559dc2SChao Yu struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ 695b8559dc2SChao Yu unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 696b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 69739a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 6984ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 6994ac91242SChao Yu unsigned char *nat_block_bitmap; 700586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 70139a53e0cSJaegeuk Kim 70239a53e0cSJaegeuk Kim /* for checkpoint */ 70339a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 70422ad0b6aSJaegeuk Kim 70522ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 70622ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 70722ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 70822ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 709599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 710599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 711599a09b2SChao Yu #endif 71239a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 71339a53e0cSJaegeuk Kim }; 71439a53e0cSJaegeuk Kim 71539a53e0cSJaegeuk Kim /* 71639a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 71739a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 71839a53e0cSJaegeuk Kim * by the data offset in a file. 71939a53e0cSJaegeuk Kim */ 72039a53e0cSJaegeuk Kim struct dnode_of_data { 72139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 72239a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 72339a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 72439a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 72539a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 72639a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 72793bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 7283cf45747SChao Yu char cur_level; /* level of hole node page */ 7293cf45747SChao Yu char max_level; /* level of current page located */ 73039a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 73139a53e0cSJaegeuk Kim }; 73239a53e0cSJaegeuk Kim 73339a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 73439a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 73539a53e0cSJaegeuk Kim { 736d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 73739a53e0cSJaegeuk Kim dn->inode = inode; 73839a53e0cSJaegeuk Kim dn->inode_page = ipage; 73939a53e0cSJaegeuk Kim dn->node_page = npage; 74039a53e0cSJaegeuk Kim dn->nid = nid; 74139a53e0cSJaegeuk Kim } 74239a53e0cSJaegeuk Kim 74339a53e0cSJaegeuk Kim /* 74439a53e0cSJaegeuk Kim * For SIT manager 74539a53e0cSJaegeuk Kim * 74639a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 74739a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 74839a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 74939a53e0cSJaegeuk Kim * respectively. 75039a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 75139a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 75239a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 75339a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 75439a53e0cSJaegeuk Kim * data and 8 for node logs. 75539a53e0cSJaegeuk Kim */ 75639a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 75739a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 75839a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 75939a53e0cSJaegeuk Kim 76039a53e0cSJaegeuk Kim enum { 76139a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 76239a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 76339a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 76439a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 76539a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 76639a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 76738aa0889SJaegeuk Kim NO_CHECK_TYPE, 76839a53e0cSJaegeuk Kim }; 76939a53e0cSJaegeuk Kim 7706b4afdd7SJaegeuk Kim struct flush_cmd { 7716b4afdd7SJaegeuk Kim struct completion wait; 772721bd4d5SGu Zheng struct llist_node llnode; 7736b4afdd7SJaegeuk Kim int ret; 7746b4afdd7SJaegeuk Kim }; 7756b4afdd7SJaegeuk Kim 776a688b9d9SGu Zheng struct flush_cmd_control { 777a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 778a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 7798b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 7808b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 781721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 782721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 783a688b9d9SGu Zheng }; 784a688b9d9SGu Zheng 78539a53e0cSJaegeuk Kim struct f2fs_sm_info { 78639a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 78739a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 78839a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 78939a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 79039a53e0cSJaegeuk Kim 79139a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 79239a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 79339a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 79439a53e0cSJaegeuk Kim 79539a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 79639a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 79739a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 79839a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 79981eb8d6eSJaegeuk Kim 80081eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 80181eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 8027fd9e544SJaegeuk Kim 803bba681cbSJaegeuk Kim /* for batched trimming */ 804bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 805bba681cbSJaegeuk Kim 806184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 807184a5cd2SChao Yu 808216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 809216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 810c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 811ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 8126b4afdd7SJaegeuk Kim 8136b4afdd7SJaegeuk Kim /* for flush command control */ 814b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 815a688b9d9SGu Zheng 8160b54fb84SJaegeuk Kim /* for discard command control */ 8170b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 81839a53e0cSJaegeuk Kim }; 81939a53e0cSJaegeuk Kim 82039a53e0cSJaegeuk Kim /* 82139a53e0cSJaegeuk Kim * For superblock 82239a53e0cSJaegeuk Kim */ 82339a53e0cSJaegeuk Kim /* 82439a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 82539a53e0cSJaegeuk Kim * 82639a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 82739a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 82839a53e0cSJaegeuk Kim */ 82936951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 83039a53e0cSJaegeuk Kim enum count_type { 83139a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 832c227f912SChao Yu F2FS_DIRTY_DATA, 83339a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 83439a53e0cSJaegeuk Kim F2FS_DIRTY_META, 8358dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 8360f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 83736951b38SChao Yu F2FS_WB_CP_DATA, 83836951b38SChao Yu F2FS_WB_DATA, 83939a53e0cSJaegeuk Kim NR_COUNT_TYPE, 84039a53e0cSJaegeuk Kim }; 84139a53e0cSJaegeuk Kim 84239a53e0cSJaegeuk Kim /* 843e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 84439a53e0cSJaegeuk Kim * The available types are: 84539a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 84639a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 84739a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 84839a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 84939a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 85039a53e0cSJaegeuk Kim * with waiting the bio's completion 85139a53e0cSJaegeuk Kim * ... Only can be used with META. 85239a53e0cSJaegeuk Kim */ 8537d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 85439a53e0cSJaegeuk Kim enum page_type { 85539a53e0cSJaegeuk Kim DATA, 85639a53e0cSJaegeuk Kim NODE, 85739a53e0cSJaegeuk Kim META, 85839a53e0cSJaegeuk Kim NR_PAGE_TYPE, 85939a53e0cSJaegeuk Kim META_FLUSH, 8608ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 8618ce67cb0SJaegeuk Kim INMEM_DROP, 8628c242db9SJaegeuk Kim INMEM_INVALIDATE, 86328bc106bSChao Yu INMEM_REVOKE, 8648ce67cb0SJaegeuk Kim IPU, 8658ce67cb0SJaegeuk Kim OPU, 86639a53e0cSJaegeuk Kim }; 86739a53e0cSJaegeuk Kim 868a912b54dSJaegeuk Kim enum temp_type { 869a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 870a912b54dSJaegeuk Kim WARM, 871a912b54dSJaegeuk Kim COLD, 872a912b54dSJaegeuk Kim NR_TEMP_TYPE, 873a912b54dSJaegeuk Kim }; 874a912b54dSJaegeuk Kim 875cc15620bSJaegeuk Kim enum need_lock_type { 876cc15620bSJaegeuk Kim LOCK_REQ = 0, 877cc15620bSJaegeuk Kim LOCK_DONE, 878cc15620bSJaegeuk Kim LOCK_RETRY, 879cc15620bSJaegeuk Kim }; 880cc15620bSJaegeuk Kim 881b0af6d49SChao Yu enum iostat_type { 882b0af6d49SChao Yu APP_DIRECT_IO, /* app direct IOs */ 883b0af6d49SChao Yu APP_BUFFERED_IO, /* app buffered IOs */ 884b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 885b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 886b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 887b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 888b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 889b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 890b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 891b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 892b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 893b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 894b0af6d49SChao Yu FS_DISCARD, /* discard */ 895b0af6d49SChao Yu NR_IO_TYPE, 896b0af6d49SChao Yu }; 897b0af6d49SChao Yu 898458e6197SJaegeuk Kim struct f2fs_io_info { 89905ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 900458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 901a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 90204d328deSMike Christie int op; /* contains REQ_OP_ */ 903ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 9047a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 90528bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 90605ca3632SJaegeuk Kim struct page *page; /* page to be written */ 9074375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 908fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 909d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 910cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 911fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 912b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 913458e6197SJaegeuk Kim }; 914458e6197SJaegeuk Kim 91568afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 9161ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 917458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 9181ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 9191ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 920458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 921df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 922fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 923fb830fc5SChao Yu struct list_head io_list; /* track fios */ 9241ff7bd3bSJaegeuk Kim }; 9251ff7bd3bSJaegeuk Kim 9263c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 9273c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 9283c62be17SJaegeuk Kim struct f2fs_dev_info { 9293c62be17SJaegeuk Kim struct block_device *bdev; 9303c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 9313c62be17SJaegeuk Kim unsigned int total_segments; 9323c62be17SJaegeuk Kim block_t start_blk; 9333c62be17SJaegeuk Kim block_t end_blk; 9343c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 9353c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 9363c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 9373c62be17SJaegeuk Kim #endif 9383c62be17SJaegeuk Kim }; 9393c62be17SJaegeuk Kim 940c227f912SChao Yu enum inode_type { 941c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 942c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 9430f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 944c227f912SChao Yu NR_INODE_TYPE, 945c227f912SChao Yu }; 946c227f912SChao Yu 94767298804SChao Yu /* for inner inode cache management */ 94867298804SChao Yu struct inode_management { 94967298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 95067298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 95167298804SChao Yu struct list_head ino_list; /* inode list head */ 95267298804SChao Yu unsigned long ino_num; /* number of entries */ 95367298804SChao Yu }; 95467298804SChao Yu 955caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 956caf0047eSChao Yu enum { 957caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 958caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 959caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 960caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 961df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 962bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 963caf0047eSChao Yu }; 964caf0047eSChao Yu 9656beceb54SJaegeuk Kim enum { 9666beceb54SJaegeuk Kim CP_TIME, 967d0239e1bSJaegeuk Kim REQ_TIME, 9686beceb54SJaegeuk Kim MAX_TIME, 9696beceb54SJaegeuk Kim }; 9706beceb54SJaegeuk Kim 97139a53e0cSJaegeuk Kim struct f2fs_sb_info { 97239a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 9735e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 97439a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 975e8240f65SChao Yu int valid_super_block; /* valid super block no */ 976fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 97739a53e0cSJaegeuk Kim 978178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 979178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 980178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 981178053e2SDamien Le Moal #endif 982178053e2SDamien Le Moal 98339a53e0cSJaegeuk Kim /* for node-related operations */ 98439a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 98539a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 98639a53e0cSJaegeuk Kim 98739a53e0cSJaegeuk Kim /* for segment-related operations */ 98839a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 9891ff7bd3bSJaegeuk Kim 9901ff7bd3bSJaegeuk Kim /* for bio operations */ 991a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 992e41e6d75SChao Yu struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 993e41e6d75SChao Yu /* bio ordering for NODE/DATA */ 9940a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 9950a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 99639a53e0cSJaegeuk Kim 99739a53e0cSJaegeuk Kim /* for checkpoint */ 99839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 9998508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1000aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 100139a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 100239936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 1003b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1004b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 100559c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1006fb51b5efSChangman Lee wait_queue_head_t cp_wait; 10076beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 10086beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 100939a53e0cSJaegeuk Kim 101067298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 10116451e041SJaegeuk Kim 10126451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 10130d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 101439a53e0cSJaegeuk Kim 1015c227f912SChao Yu /* for inode management */ 1016c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1017c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 101839a53e0cSJaegeuk Kim 101913054c54SChao Yu /* for extent tree cache */ 102013054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 10215e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 102213054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 102313054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 10247441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1025137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 102674fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 102713054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 102813054c54SChao Yu 102939a53e0cSJaegeuk Kim /* basic filesystem units */ 103039a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 103139a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 103239a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 103339a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 103439a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 103539a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 103639a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 103739a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 103839a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 103939a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 104039a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 104139a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 104239a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1043e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 104439a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 1045ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 104639a53e0cSJaegeuk Kim 104739a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 104839a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1049a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 105039a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1051daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 1052daeb433eSChao Yu 105339a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 1054523be8a6SJaegeuk Kim 1055523be8a6SJaegeuk Kim /* # of pages, see count_type */ 105635782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 105741382ec4SJaegeuk Kim /* # of allocated blocks */ 105841382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 105939a53e0cSJaegeuk Kim 1060687de7f1SJaegeuk Kim /* writeback control */ 1061687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 1062687de7f1SJaegeuk Kim 1063513c5f37SJaegeuk Kim /* valid inode count */ 1064513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1065513c5f37SJaegeuk Kim 106639a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 106739a53e0cSJaegeuk Kim 106839a53e0cSJaegeuk Kim /* for cleaning operations */ 106939a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 107039a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 10715ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 107239a53e0cSJaegeuk Kim 1073e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 1074e93b9865SHou Pengyang u64 fggc_threshold; 1075e93b9865SHou Pengyang 1076b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1077b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1078b1c57c1cSJaegeuk Kim 107939a53e0cSJaegeuk Kim /* 108039a53e0cSJaegeuk Kim * for stat information. 108139a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 108239a53e0cSJaegeuk Kim */ 108335b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 108439a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 108539a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 108639a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1087b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 10885b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 10895b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 10905b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 10915b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1092d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 109303e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 109403e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 109526a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 1096648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 109726a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1098648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 109939a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 110033fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 110135b09d82SNamjae Jeon #endif 110239a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1103b59d0baeSNamjae Jeon 1104b0af6d49SChao Yu /* For app/fs IO statistics */ 1105b0af6d49SChao Yu spinlock_t iostat_lock; 1106b0af6d49SChao Yu unsigned long long write_iostat[NR_IO_TYPE]; 1107b0af6d49SChao Yu bool iostat_enable; 1108b0af6d49SChao Yu 1109b59d0baeSNamjae Jeon /* For sysfs suppport */ 1110b59d0baeSNamjae Jeon struct kobject s_kobj; 1111b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 11122658e50dSJaegeuk Kim 11132658e50dSJaegeuk Kim /* For shrinker support */ 11142658e50dSJaegeuk Kim struct list_head s_list; 11153c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 11163c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 11172658e50dSJaegeuk Kim struct mutex umount_mutex; 11182658e50dSJaegeuk Kim unsigned int shrinker_run_no; 11198f1dbbbbSShuoran Liu 11208f1dbbbbSShuoran Liu /* For write statistics */ 11218f1dbbbbSShuoran Liu u64 sectors_written_start; 11228f1dbbbbSShuoran Liu u64 kbytes_written; 112343b6573bSKeith Mok 112443b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 112543b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 11261ecc0c5cSChao Yu 1127704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1128704956ecSChao Yu __u32 s_chksum_seed; 1129704956ecSChao Yu 11301ecc0c5cSChao Yu /* For fault injection */ 11311ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 11321ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 11331ecc0c5cSChao Yu #endif 11344b2414d0SChao Yu 11354b2414d0SChao Yu #ifdef CONFIG_QUOTA 11364b2414d0SChao Yu /* Names of quota files with journalled quota */ 11374b2414d0SChao Yu char *s_qf_names[MAXQUOTAS]; 11384b2414d0SChao Yu int s_jquota_fmt; /* Format of quota to use */ 11394b2414d0SChao Yu #endif 114039a53e0cSJaegeuk Kim }; 114139a53e0cSJaegeuk Kim 11421ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 114355523519SChao Yu #define f2fs_show_injection_info(type) \ 114455523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 114555523519SChao Yu KERN_INFO, fault_name[type], \ 114655523519SChao Yu __func__, __builtin_return_address(0)) 11471ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 11481ecc0c5cSChao Yu { 11491ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 11501ecc0c5cSChao Yu 11511ecc0c5cSChao Yu if (!ffi->inject_rate) 11521ecc0c5cSChao Yu return false; 11531ecc0c5cSChao Yu 11541ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 11551ecc0c5cSChao Yu return false; 11561ecc0c5cSChao Yu 11571ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 11581ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 11591ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 11601ecc0c5cSChao Yu return true; 11611ecc0c5cSChao Yu } 11621ecc0c5cSChao Yu return false; 11631ecc0c5cSChao Yu } 11641ecc0c5cSChao Yu #endif 11651ecc0c5cSChao Yu 11668f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 11678f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 11688f1dbbbbSShuoran Liu */ 11698f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 117068afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 117168afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 11728f1dbbbbSShuoran Liu 11736beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 11746beceb54SJaegeuk Kim { 11756beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 11766beceb54SJaegeuk Kim } 11776beceb54SJaegeuk Kim 11786beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 11796beceb54SJaegeuk Kim { 11806beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 11816beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 11826beceb54SJaegeuk Kim 11836beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 11846beceb54SJaegeuk Kim } 11856beceb54SJaegeuk Kim 1186d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1187d0239e1bSJaegeuk Kim { 1188d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1189d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1190d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1191d0239e1bSJaegeuk Kim 1192d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1193d0239e1bSJaegeuk Kim return 0; 1194d0239e1bSJaegeuk Kim 1195d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1196d0239e1bSJaegeuk Kim } 1197d0239e1bSJaegeuk Kim 119839a53e0cSJaegeuk Kim /* 119939a53e0cSJaegeuk Kim * Inline functions 120039a53e0cSJaegeuk Kim */ 120143b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 120243b6573bSKeith Mok unsigned int length) 120343b6573bSKeith Mok { 120443b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 120543b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 1206d41519a6SDavid Miller u32 retval; 120743b6573bSKeith Mok int err; 120843b6573bSKeith Mok 120943b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 121043b6573bSKeith Mok shash->flags = 0; 121143b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 121243b6573bSKeith Mok 121343b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 121443b6573bSKeith Mok BUG_ON(err); 121543b6573bSKeith Mok 1216d41519a6SDavid Miller retval = *ctx; 1217d41519a6SDavid Miller barrier_data(ctx); 1218d41519a6SDavid Miller return retval; 121943b6573bSKeith Mok } 122043b6573bSKeith Mok 122143b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 122243b6573bSKeith Mok void *buf, size_t buf_size) 122343b6573bSKeith Mok { 122443b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 122543b6573bSKeith Mok } 122643b6573bSKeith Mok 1227704956ecSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1228704956ecSChao Yu const void *address, unsigned int length) 1229704956ecSChao Yu { 1230704956ecSChao Yu struct { 1231704956ecSChao Yu struct shash_desc shash; 1232704956ecSChao Yu char ctx[4]; 1233704956ecSChao Yu } desc; 1234704956ecSChao Yu int err; 1235704956ecSChao Yu 1236704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1237704956ecSChao Yu 1238704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1239704956ecSChao Yu desc.shash.flags = 0; 1240704956ecSChao Yu *(u32 *)desc.ctx = crc; 1241704956ecSChao Yu 1242704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1243704956ecSChao Yu BUG_ON(err); 1244704956ecSChao Yu 1245704956ecSChao Yu return *(u32 *)desc.ctx; 1246704956ecSChao Yu } 1247704956ecSChao Yu 124839a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 124939a53e0cSJaegeuk Kim { 125039a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 125139a53e0cSJaegeuk Kim } 125239a53e0cSJaegeuk Kim 125339a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 125439a53e0cSJaegeuk Kim { 125539a53e0cSJaegeuk Kim return sb->s_fs_info; 125639a53e0cSJaegeuk Kim } 125739a53e0cSJaegeuk Kim 12584081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 12594081363fSJaegeuk Kim { 12604081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 12614081363fSJaegeuk Kim } 12624081363fSJaegeuk Kim 12634081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 12644081363fSJaegeuk Kim { 12654081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 12664081363fSJaegeuk Kim } 12674081363fSJaegeuk Kim 12684081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 12694081363fSJaegeuk Kim { 12704081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 12714081363fSJaegeuk Kim } 12724081363fSJaegeuk Kim 127339a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 127439a53e0cSJaegeuk Kim { 127539a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 127639a53e0cSJaegeuk Kim } 127739a53e0cSJaegeuk Kim 127839a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 127939a53e0cSJaegeuk Kim { 128039a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 128139a53e0cSJaegeuk Kim } 128239a53e0cSJaegeuk Kim 128345590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 128445590710SGu Zheng { 128545590710SGu Zheng return (struct f2fs_node *)page_address(page); 128645590710SGu Zheng } 128745590710SGu Zheng 128858bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 128958bfaf44SJaegeuk Kim { 129058bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 129158bfaf44SJaegeuk Kim } 129258bfaf44SJaegeuk Kim 129339a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 129439a53e0cSJaegeuk Kim { 129539a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 129639a53e0cSJaegeuk Kim } 129739a53e0cSJaegeuk Kim 129839a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 129939a53e0cSJaegeuk Kim { 130039a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 130139a53e0cSJaegeuk Kim } 130239a53e0cSJaegeuk Kim 130339a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 130439a53e0cSJaegeuk Kim { 130539a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 130639a53e0cSJaegeuk Kim } 130739a53e0cSJaegeuk Kim 130839a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 130939a53e0cSJaegeuk Kim { 131039a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 131139a53e0cSJaegeuk Kim } 131239a53e0cSJaegeuk Kim 131339a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 131439a53e0cSJaegeuk Kim { 131539a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 131639a53e0cSJaegeuk Kim } 131739a53e0cSJaegeuk Kim 13189df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 13199df27d98SGu Zheng { 13209df27d98SGu Zheng return sbi->meta_inode->i_mapping; 13219df27d98SGu Zheng } 13229df27d98SGu Zheng 13234ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 13244ef51a8fSJaegeuk Kim { 13254ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 13264ef51a8fSJaegeuk Kim } 13274ef51a8fSJaegeuk Kim 1328caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 132939a53e0cSJaegeuk Kim { 1330fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 133139a53e0cSJaegeuk Kim } 133239a53e0cSJaegeuk Kim 1333caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 133439a53e0cSJaegeuk Kim { 1335fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1336caf0047eSChao Yu } 1337caf0047eSChao Yu 1338caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1339caf0047eSChao Yu { 1340fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 134139a53e0cSJaegeuk Kim } 134239a53e0cSJaegeuk Kim 1343d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1344d71b5564SJaegeuk Kim { 1345d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1346d71b5564SJaegeuk Kim } 1347d71b5564SJaegeuk Kim 1348ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1349ced2c7eaSKinglong Mee { 1350ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1351ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1352ced2c7eaSKinglong Mee } 1353ced2c7eaSKinglong Mee 1354aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 135525ca923bSJaegeuk Kim { 135625ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1357aaec2b1dSChao Yu 135825ca923bSJaegeuk Kim return ckpt_flags & f; 135925ca923bSJaegeuk Kim } 136025ca923bSJaegeuk Kim 1361aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 136225ca923bSJaegeuk Kim { 1363aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1364aaec2b1dSChao Yu } 1365aaec2b1dSChao Yu 1366aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1367aaec2b1dSChao Yu { 1368aaec2b1dSChao Yu unsigned int ckpt_flags; 1369aaec2b1dSChao Yu 1370aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 137125ca923bSJaegeuk Kim ckpt_flags |= f; 137225ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 137325ca923bSJaegeuk Kim } 137425ca923bSJaegeuk Kim 1375aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 137625ca923bSJaegeuk Kim { 1377d1aa2453SChao Yu unsigned long flags; 1378d1aa2453SChao Yu 1379d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1380aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1381d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1382aaec2b1dSChao Yu } 1383aaec2b1dSChao Yu 1384aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1385aaec2b1dSChao Yu { 1386aaec2b1dSChao Yu unsigned int ckpt_flags; 1387aaec2b1dSChao Yu 1388aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 138925ca923bSJaegeuk Kim ckpt_flags &= (~f); 139025ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 139125ca923bSJaegeuk Kim } 139225ca923bSJaegeuk Kim 1393aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1394aaec2b1dSChao Yu { 1395d1aa2453SChao Yu unsigned long flags; 1396d1aa2453SChao Yu 1397d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1398aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1399d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1400aaec2b1dSChao Yu } 1401aaec2b1dSChao Yu 140222ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 140322ad0b6aSJaegeuk Kim { 1404d1aa2453SChao Yu unsigned long flags; 1405d1aa2453SChao Yu 140622ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 140722ad0b6aSJaegeuk Kim 140822ad0b6aSJaegeuk Kim if (lock) 1409d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 141022ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 141122ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 141222ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 141322ad0b6aSJaegeuk Kim if (lock) 1414d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 141522ad0b6aSJaegeuk Kim } 141622ad0b6aSJaegeuk Kim 141722ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 141822ad0b6aSJaegeuk Kim struct cp_control *cpc) 141922ad0b6aSJaegeuk Kim { 142022ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 142122ad0b6aSJaegeuk Kim 1422c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 142322ad0b6aSJaegeuk Kim } 142422ad0b6aSJaegeuk Kim 1425e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 142639a53e0cSJaegeuk Kim { 1427b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 142839a53e0cSJaegeuk Kim } 142939a53e0cSJaegeuk Kim 1430cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1431cc15620bSJaegeuk Kim { 1432cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1433cc15620bSJaegeuk Kim } 1434cc15620bSJaegeuk Kim 1435e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 143639a53e0cSJaegeuk Kim { 1437b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 143839936837SJaegeuk Kim } 143939936837SJaegeuk Kim 1440e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 144139936837SJaegeuk Kim { 1442b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 144339936837SJaegeuk Kim } 144439936837SJaegeuk Kim 1445e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 144639936837SJaegeuk Kim { 1447b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 144839a53e0cSJaegeuk Kim } 144939a53e0cSJaegeuk Kim 1450119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1451119ee914SJaegeuk Kim { 1452119ee914SJaegeuk Kim int reason = CP_SYNC; 1453119ee914SJaegeuk Kim 1454119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1455119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1456119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1457119ee914SJaegeuk Kim reason = CP_UMOUNT; 1458119ee914SJaegeuk Kim return reason; 1459119ee914SJaegeuk Kim } 1460119ee914SJaegeuk Kim 1461119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1462119ee914SJaegeuk Kim { 1463c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1464119ee914SJaegeuk Kim } 1465119ee914SJaegeuk Kim 1466119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1467119ee914SJaegeuk Kim { 1468aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1469aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1470119ee914SJaegeuk Kim } 1471119ee914SJaegeuk Kim 147239a53e0cSJaegeuk Kim /* 147339a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 147439a53e0cSJaegeuk Kim */ 1475064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 147639a53e0cSJaegeuk Kim { 1477d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1478d6b7d4b3SChao Yu return -EINVAL; 1479cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1480064e0823SNamjae Jeon return -EINVAL; 1481064e0823SNamjae Jeon return 0; 148239a53e0cSJaegeuk Kim } 148339a53e0cSJaegeuk Kim 148439a53e0cSJaegeuk Kim /* 148539a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 148639a53e0cSJaegeuk Kim */ 148739a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 148839a53e0cSJaegeuk Kim { 14890eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 14900eb0adadSChao Yu 1491000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 149239a53e0cSJaegeuk Kim } 149339a53e0cSJaegeuk Kim 14944bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 14954bc8e9bcSChao Yu { 14964bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 14974bc8e9bcSChao Yu } 14984bc8e9bcSChao Yu 14990abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 15000abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 150146008c6dSChao Yu struct inode *inode, blkcnt_t *count) 150239a53e0cSJaegeuk Kim { 15030abd675eSChao Yu blkcnt_t diff = 0, release = 0; 1504daeb433eSChao Yu block_t avail_user_block_count; 15050abd675eSChao Yu int ret; 15060abd675eSChao Yu 15070abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 15080abd675eSChao Yu if (ret) 15090abd675eSChao Yu return ret; 1510dd11a5dfSJaegeuk Kim 1511cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 151255523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 151355523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 15140abd675eSChao Yu release = *count; 15150abd675eSChao Yu goto enospc; 151655523519SChao Yu } 1517cb78942bSJaegeuk Kim #endif 1518dd11a5dfSJaegeuk Kim /* 1519dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1520dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1521dd11a5dfSJaegeuk Kim */ 1522dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1523cfb271d4SChao Yu 152439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 15252555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 1526daeb433eSChao Yu avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks; 1527daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1528daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 1529dd11a5dfSJaegeuk Kim *count -= diff; 15300abd675eSChao Yu release = diff; 1531daeb433eSChao Yu sbi->total_valid_block_count = avail_user_block_count; 153246008c6dSChao Yu if (!*count) { 153339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1534dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 15350abd675eSChao Yu goto enospc; 153639a53e0cSJaegeuk Kim } 153746008c6dSChao Yu } 153839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 153941382ec4SJaegeuk Kim 15400abd675eSChao Yu if (release) 15410abd675eSChao Yu dquot_release_reservation_block(inode, release); 15420abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 15430abd675eSChao Yu return 0; 15440abd675eSChao Yu 15450abd675eSChao Yu enospc: 15460abd675eSChao Yu dquot_release_reservation_block(inode, release); 15470abd675eSChao Yu return -ENOSPC; 154839a53e0cSJaegeuk Kim } 154939a53e0cSJaegeuk Kim 1550da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 155139a53e0cSJaegeuk Kim struct inode *inode, 15520eb0adadSChao Yu block_t count) 155339a53e0cSJaegeuk Kim { 15540eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 15550eb0adadSChao Yu 155639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 15579850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 15580eb0adadSChao Yu f2fs_bug_on(sbi, inode->i_blocks < sectors); 155939a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 156039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 15610abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 156239a53e0cSJaegeuk Kim } 156339a53e0cSJaegeuk Kim 156439a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 156539a53e0cSJaegeuk Kim { 156635782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 15677c4abcbeSChao Yu 156836951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 156936951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 15707c4abcbeSChao Yu return; 15717c4abcbeSChao Yu 1572caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 157339a53e0cSJaegeuk Kim } 157439a53e0cSJaegeuk Kim 1575a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 157639a53e0cSJaegeuk Kim { 1577204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1578c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1579c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 158039a53e0cSJaegeuk Kim } 158139a53e0cSJaegeuk Kim 158239a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 158339a53e0cSJaegeuk Kim { 158435782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 158539a53e0cSJaegeuk Kim } 158639a53e0cSJaegeuk Kim 1587a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 158839a53e0cSJaegeuk Kim { 15895ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 15905ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 15911fe54f9dSJaegeuk Kim return; 15921fe54f9dSJaegeuk Kim 1593204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1594c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1595c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 159639a53e0cSJaegeuk Kim } 159739a53e0cSJaegeuk Kim 1598523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 159939a53e0cSJaegeuk Kim { 160035782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 160139a53e0cSJaegeuk Kim } 160239a53e0cSJaegeuk Kim 1603204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1604f8b2c1f9SJaegeuk Kim { 1605204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1606f8b2c1f9SJaegeuk Kim } 1607f8b2c1f9SJaegeuk Kim 16085ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 16095ac206cfSNamjae Jeon { 16103519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1611523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1612523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1613523be8a6SJaegeuk Kim 1614523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 16155ac206cfSNamjae Jeon } 16165ac206cfSNamjae Jeon 161739a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 161839a53e0cSJaegeuk Kim { 16198b8343faSJaegeuk Kim return sbi->total_valid_block_count; 162039a53e0cSJaegeuk Kim } 162139a53e0cSJaegeuk Kim 1622f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1623f83a2584SYunlei He { 1624f83a2584SYunlei He return sbi->discard_blks; 1625f83a2584SYunlei He } 1626f83a2584SYunlei He 162739a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 162839a53e0cSJaegeuk Kim { 162939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 163039a53e0cSJaegeuk Kim 163139a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 163239a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 163339a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 163439a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 163539a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 163639a53e0cSJaegeuk Kim 163739a53e0cSJaegeuk Kim return 0; 163839a53e0cSJaegeuk Kim } 163939a53e0cSJaegeuk Kim 164055141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 164155141486SWanpeng Li { 164255141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 164355141486SWanpeng Li } 164455141486SWanpeng Li 164539a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 164639a53e0cSJaegeuk Kim { 164739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 16481dbe4152SChangman Lee int offset; 16491dbe4152SChangman Lee 165055141486SWanpeng Li if (__cp_payload(sbi) > 0) { 16511dbe4152SChangman Lee if (flag == NAT_BITMAP) 16521dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 16531dbe4152SChangman Lee else 165465b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 16551dbe4152SChangman Lee } else { 16561dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 165725ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 165839a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 165939a53e0cSJaegeuk Kim } 16601dbe4152SChangman Lee } 166139a53e0cSJaegeuk Kim 166239a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 166339a53e0cSJaegeuk Kim { 16648508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 166539a53e0cSJaegeuk Kim 16668508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 166739a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 166839a53e0cSJaegeuk Kim return start_addr; 166939a53e0cSJaegeuk Kim } 167039a53e0cSJaegeuk Kim 16718508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 16728508e44aSJaegeuk Kim { 16738508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 16748508e44aSJaegeuk Kim 16758508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 16768508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 16778508e44aSJaegeuk Kim return start_addr; 16788508e44aSJaegeuk Kim } 16798508e44aSJaegeuk Kim 16808508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 16818508e44aSJaegeuk Kim { 16828508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 16838508e44aSJaegeuk Kim } 16848508e44aSJaegeuk Kim 168539a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 168639a53e0cSJaegeuk Kim { 168739a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 168839a53e0cSJaegeuk Kim } 168939a53e0cSJaegeuk Kim 16900abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 1691000519f2SChao Yu struct inode *inode, bool is_inode) 169239a53e0cSJaegeuk Kim { 169339a53e0cSJaegeuk Kim block_t valid_block_count; 169439a53e0cSJaegeuk Kim unsigned int valid_node_count; 16950abd675eSChao Yu bool quota = inode && !is_inode; 16960abd675eSChao Yu 16970abd675eSChao Yu if (quota) { 16980abd675eSChao Yu int ret = dquot_reserve_block(inode, 1); 16990abd675eSChao Yu if (ret) 17000abd675eSChao Yu return ret; 17010abd675eSChao Yu } 170239a53e0cSJaegeuk Kim 170339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 170439a53e0cSJaegeuk Kim 1705ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1706daeb433eSChao Yu if (unlikely(valid_block_count + sbi->reserved_blocks > 1707daeb433eSChao Yu sbi->user_block_count)) { 170839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17090abd675eSChao Yu goto enospc; 171039a53e0cSJaegeuk Kim } 171139a53e0cSJaegeuk Kim 1712ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1713cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 171439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17150abd675eSChao Yu goto enospc; 171639a53e0cSJaegeuk Kim } 171739a53e0cSJaegeuk Kim 1718ef86d709SGu Zheng sbi->total_valid_node_count++; 1719ef86d709SGu Zheng sbi->total_valid_block_count++; 172039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 172139a53e0cSJaegeuk Kim 17220abd675eSChao Yu if (inode) { 17230abd675eSChao Yu if (is_inode) 17240abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 17250abd675eSChao Yu else 17260abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 17270abd675eSChao Yu } 17280abd675eSChao Yu 172941382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 17300abd675eSChao Yu return 0; 17310abd675eSChao Yu 17320abd675eSChao Yu enospc: 17330abd675eSChao Yu if (quota) 17340abd675eSChao Yu dquot_release_reservation_block(inode, 1); 17350abd675eSChao Yu return -ENOSPC; 173639a53e0cSJaegeuk Kim } 173739a53e0cSJaegeuk Kim 173839a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1739000519f2SChao Yu struct inode *inode, bool is_inode) 174039a53e0cSJaegeuk Kim { 174139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 174239a53e0cSJaegeuk Kim 17439850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 17449850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 1745000519f2SChao Yu f2fs_bug_on(sbi, !is_inode && !inode->i_blocks); 174639a53e0cSJaegeuk Kim 1747ef86d709SGu Zheng sbi->total_valid_node_count--; 1748ef86d709SGu Zheng sbi->total_valid_block_count--; 174939a53e0cSJaegeuk Kim 175039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17510abd675eSChao Yu 17520abd675eSChao Yu if (!is_inode) 17530abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 175439a53e0cSJaegeuk Kim } 175539a53e0cSJaegeuk Kim 175639a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 175739a53e0cSJaegeuk Kim { 17588b8343faSJaegeuk Kim return sbi->total_valid_node_count; 175939a53e0cSJaegeuk Kim } 176039a53e0cSJaegeuk Kim 176139a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 176239a53e0cSJaegeuk Kim { 1763513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 176439a53e0cSJaegeuk Kim } 176539a53e0cSJaegeuk Kim 17660e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 176739a53e0cSJaegeuk Kim { 1768513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 176939a53e0cSJaegeuk Kim } 177039a53e0cSJaegeuk Kim 1771513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 177239a53e0cSJaegeuk Kim { 1773513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 177439a53e0cSJaegeuk Kim } 177539a53e0cSJaegeuk Kim 1776a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1777a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1778a56c7c6fSJaegeuk Kim { 1779c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1780c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1781cac5a3d8SDongOh Shin 1782c41f3cc3SJaegeuk Kim if (page) 1783c41f3cc3SJaegeuk Kim return page; 1784c41f3cc3SJaegeuk Kim 178555523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 178655523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1787c41f3cc3SJaegeuk Kim return NULL; 178855523519SChao Yu } 1789c41f3cc3SJaegeuk Kim #endif 1790a56c7c6fSJaegeuk Kim if (!for_write) 1791a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1792a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1793a56c7c6fSJaegeuk Kim } 1794a56c7c6fSJaegeuk Kim 17956e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 17966e2c64adSJaegeuk Kim { 17976e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 17986e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 17996e2c64adSJaegeuk Kim 18006e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 18016e2c64adSJaegeuk Kim kunmap(dst); 18026e2c64adSJaegeuk Kim kunmap(src); 18036e2c64adSJaegeuk Kim } 18046e2c64adSJaegeuk Kim 180539a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 180639a53e0cSJaegeuk Kim { 1807031fa8ccSJaegeuk Kim if (!page) 180839a53e0cSJaegeuk Kim return; 180939a53e0cSJaegeuk Kim 181039a53e0cSJaegeuk Kim if (unlock) { 18119850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 181239a53e0cSJaegeuk Kim unlock_page(page); 181339a53e0cSJaegeuk Kim } 181409cbfeafSKirill A. Shutemov put_page(page); 181539a53e0cSJaegeuk Kim } 181639a53e0cSJaegeuk Kim 181739a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 181839a53e0cSJaegeuk Kim { 181939a53e0cSJaegeuk Kim if (dn->node_page) 182039a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 182139a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 182239a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 182339a53e0cSJaegeuk Kim dn->node_page = NULL; 182439a53e0cSJaegeuk Kim dn->inode_page = NULL; 182539a53e0cSJaegeuk Kim } 182639a53e0cSJaegeuk Kim 182739a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1828e8512d2eSGu Zheng size_t size) 182939a53e0cSJaegeuk Kim { 1830e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 183139a53e0cSJaegeuk Kim } 183239a53e0cSJaegeuk Kim 18337bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 18347bd59381SGu Zheng gfp_t flags) 18357bd59381SGu Zheng { 18367bd59381SGu Zheng void *entry; 18377bd59381SGu Zheng 183880c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 183980c54505SJaegeuk Kim if (!entry) 184080c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 18417bd59381SGu Zheng return entry; 18427bd59381SGu Zheng } 18437bd59381SGu Zheng 1844740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1845740432f8SJaegeuk Kim { 1846740432f8SJaegeuk Kim struct bio *bio; 1847740432f8SJaegeuk Kim 1848740432f8SJaegeuk Kim /* No failure on bio allocation */ 1849740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 185080c54505SJaegeuk Kim if (!bio) 185180c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1852740432f8SJaegeuk Kim return bio; 1853740432f8SJaegeuk Kim } 1854740432f8SJaegeuk Kim 18559be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 18569be32d72SJaegeuk Kim unsigned long index, void *item) 18579be32d72SJaegeuk Kim { 18589be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 18599be32d72SJaegeuk Kim cond_resched(); 18609be32d72SJaegeuk Kim } 18619be32d72SJaegeuk Kim 186239a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 186339a53e0cSJaegeuk Kim 186439a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 186539a53e0cSJaegeuk Kim { 186645590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1867cac5a3d8SDongOh Shin 186839a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 186939a53e0cSJaegeuk Kim } 187039a53e0cSJaegeuk Kim 18717a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 18727a2af766SChao Yu { 18737a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 18747a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 18757a2af766SChao Yu } 18767a2af766SChao Yu 187739a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 187839a53e0cSJaegeuk Kim { 187939a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 188039a53e0cSJaegeuk Kim } 188139a53e0cSJaegeuk Kim 18827a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 18837a2af766SChao Yu static inline block_t datablock_addr(struct inode *inode, 18847a2af766SChao Yu struct page *node_page, unsigned int offset) 188539a53e0cSJaegeuk Kim { 188639a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 188739a53e0cSJaegeuk Kim __le32 *addr_array; 18887a2af766SChao Yu int base = 0; 18897a2af766SChao Yu bool is_inode = IS_INODE(node_page); 1890cac5a3d8SDongOh Shin 189145590710SGu Zheng raw_node = F2FS_NODE(node_page); 18927a2af766SChao Yu 18937a2af766SChao Yu /* from GC path only */ 18947a2af766SChao Yu if (!inode) { 18957a2af766SChao Yu if (is_inode) 18967a2af766SChao Yu base = offset_in_addr(&raw_node->i); 18977a2af766SChao Yu } else if (f2fs_has_extra_attr(inode) && is_inode) { 18987a2af766SChao Yu base = get_extra_isize(inode); 18997a2af766SChao Yu } 19007a2af766SChao Yu 190139a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 19027a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 190339a53e0cSJaegeuk Kim } 190439a53e0cSJaegeuk Kim 190539a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 190639a53e0cSJaegeuk Kim { 190739a53e0cSJaegeuk Kim int mask; 190839a53e0cSJaegeuk Kim 190939a53e0cSJaegeuk Kim addr += (nr >> 3); 191039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 191139a53e0cSJaegeuk Kim return mask & *addr; 191239a53e0cSJaegeuk Kim } 191339a53e0cSJaegeuk Kim 1914a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1915a66cdd98SJaegeuk Kim { 1916a66cdd98SJaegeuk Kim int mask; 1917a66cdd98SJaegeuk Kim 1918a66cdd98SJaegeuk Kim addr += (nr >> 3); 1919a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1920a66cdd98SJaegeuk Kim *addr |= mask; 1921a66cdd98SJaegeuk Kim } 1922a66cdd98SJaegeuk Kim 1923a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1924a66cdd98SJaegeuk Kim { 1925a66cdd98SJaegeuk Kim int mask; 1926a66cdd98SJaegeuk Kim 1927a66cdd98SJaegeuk Kim addr += (nr >> 3); 1928a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1929a66cdd98SJaegeuk Kim *addr &= ~mask; 1930a66cdd98SJaegeuk Kim } 1931a66cdd98SJaegeuk Kim 193252aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 193339a53e0cSJaegeuk Kim { 193439a53e0cSJaegeuk Kim int mask; 193539a53e0cSJaegeuk Kim int ret; 193639a53e0cSJaegeuk Kim 193739a53e0cSJaegeuk Kim addr += (nr >> 3); 193839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 193939a53e0cSJaegeuk Kim ret = mask & *addr; 194039a53e0cSJaegeuk Kim *addr |= mask; 194139a53e0cSJaegeuk Kim return ret; 194239a53e0cSJaegeuk Kim } 194339a53e0cSJaegeuk Kim 194452aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 194539a53e0cSJaegeuk Kim { 194639a53e0cSJaegeuk Kim int mask; 194739a53e0cSJaegeuk Kim int ret; 194839a53e0cSJaegeuk Kim 194939a53e0cSJaegeuk Kim addr += (nr >> 3); 195039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 195139a53e0cSJaegeuk Kim ret = mask & *addr; 195239a53e0cSJaegeuk Kim *addr &= ~mask; 195339a53e0cSJaegeuk Kim return ret; 195439a53e0cSJaegeuk Kim } 195539a53e0cSJaegeuk Kim 1956c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1957c6ac4c0eSGu Zheng { 1958c6ac4c0eSGu Zheng int mask; 1959c6ac4c0eSGu Zheng 1960c6ac4c0eSGu Zheng addr += (nr >> 3); 1961c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1962c6ac4c0eSGu Zheng *addr ^= mask; 1963c6ac4c0eSGu Zheng } 1964c6ac4c0eSGu Zheng 19655c57132eSChao Yu #define F2FS_REG_FLMASK (~(FS_DIRSYNC_FL | FS_TOPDIR_FL)) 19665c57132eSChao Yu #define F2FS_OTHER_FLMASK (FS_NODUMP_FL | FS_NOATIME_FL) 19675c57132eSChao Yu #define F2FS_FL_INHERITED (FS_PROJINHERIT_FL) 19685c57132eSChao Yu 19695c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 19705c57132eSChao Yu { 19715c57132eSChao Yu if (S_ISDIR(mode)) 19725c57132eSChao Yu return flags; 19735c57132eSChao Yu else if (S_ISREG(mode)) 19745c57132eSChao Yu return flags & F2FS_REG_FLMASK; 19755c57132eSChao Yu else 19765c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 19775c57132eSChao Yu } 19785c57132eSChao Yu 197939a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 198039a53e0cSJaegeuk Kim enum { 198139a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1982b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 198326de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1984ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 198539a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 198639a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 198739a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1988c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1989c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1990444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 19911001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 199234d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1993fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1994fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 199588b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 199688b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 19975fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 199802a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 19993c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 20001e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 2001b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 2002510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 2003d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 2004c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 2005dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 2006ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 20077a2af766SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 20085c57132eSChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 200939a53e0cSJaegeuk Kim }; 201039a53e0cSJaegeuk Kim 2011205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2012205b9822SJaegeuk Kim int flag, bool set) 201339a53e0cSJaegeuk Kim { 2014205b9822SJaegeuk Kim switch (flag) { 2015205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2016205b9822SJaegeuk Kim case FI_INLINE_DATA: 2017205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 2018205b9822SJaegeuk Kim if (set) 2019205b9822SJaegeuk Kim return; 2020205b9822SJaegeuk Kim case FI_DATA_EXIST: 2021205b9822SJaegeuk Kim case FI_INLINE_DOTS: 20227c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2023205b9822SJaegeuk Kim } 202439a53e0cSJaegeuk Kim } 202539a53e0cSJaegeuk Kim 202691942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 202739a53e0cSJaegeuk Kim { 202891942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 202991942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 2030205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 203139a53e0cSJaegeuk Kim } 203239a53e0cSJaegeuk Kim 203391942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 203439a53e0cSJaegeuk Kim { 203591942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 203639a53e0cSJaegeuk Kim } 203739a53e0cSJaegeuk Kim 203891942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 203939a53e0cSJaegeuk Kim { 204091942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 204191942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 2042205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 204339a53e0cSJaegeuk Kim } 204439a53e0cSJaegeuk Kim 204591942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2046444c580fSJaegeuk Kim { 204791942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 204891942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 20497c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 205039a53e0cSJaegeuk Kim } 205139a53e0cSJaegeuk Kim 2052a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2053a1961246SJaegeuk Kim { 2054a1961246SJaegeuk Kim if (inc) 2055a1961246SJaegeuk Kim inc_nlink(inode); 2056a1961246SJaegeuk Kim else 2057a1961246SJaegeuk Kim drop_nlink(inode); 20587c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2059a1961246SJaegeuk Kim } 2060a1961246SJaegeuk Kim 20618edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 20620abd675eSChao Yu block_t diff, bool add, bool claim) 20638edd03c8SJaegeuk Kim { 206426de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 206526de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 206626de9b11SJaegeuk Kim 20670abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 20680abd675eSChao Yu if (add) { 20690abd675eSChao Yu if (claim) 20700abd675eSChao Yu dquot_claim_block(inode, diff); 20710abd675eSChao Yu else 20720abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 20730abd675eSChao Yu } else { 20740abd675eSChao Yu dquot_free_block(inode, diff); 20750abd675eSChao Yu } 20760abd675eSChao Yu 20777c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 207826de9b11SJaegeuk Kim if (clean || recover) 207926de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 20808edd03c8SJaegeuk Kim } 20818edd03c8SJaegeuk Kim 2082fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2083fc9581c8SJaegeuk Kim { 208426de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 208526de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 208626de9b11SJaegeuk Kim 2087fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2088fc9581c8SJaegeuk Kim return; 2089fc9581c8SJaegeuk Kim 2090fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 20917c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 209226de9b11SJaegeuk Kim if (clean || recover) 209326de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 209426de9b11SJaegeuk Kim } 209526de9b11SJaegeuk Kim 2096205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2097205b9822SJaegeuk Kim { 2098205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 20997c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2100205b9822SJaegeuk Kim } 2101205b9822SJaegeuk Kim 2102205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2103205b9822SJaegeuk Kim { 2104205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 21057c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2106205b9822SJaegeuk Kim } 2107205b9822SJaegeuk Kim 2108205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2109205b9822SJaegeuk Kim { 2110205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 21117c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2112205b9822SJaegeuk Kim } 2113205b9822SJaegeuk Kim 211491942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2115444c580fSJaegeuk Kim { 2116205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2117205b9822SJaegeuk Kim 2118444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 2119205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 21201001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 2121205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 212234d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 2123205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 2124b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 2125205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 2126510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 2127205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 21287a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 21297a2af766SChao Yu set_bit(FI_EXTRA_ATTR, &fi->flags); 2130444c580fSJaegeuk Kim } 2131444c580fSJaegeuk Kim 213291942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2133444c580fSJaegeuk Kim { 2134444c580fSJaegeuk Kim ri->i_inline = 0; 2135444c580fSJaegeuk Kim 213691942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2137444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 213891942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 21391001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 214091942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 214134d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 214291942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2143b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 214491942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2145510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 21467a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 21477a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 21487a2af766SChao Yu } 21497a2af766SChao Yu 21507a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 21517a2af766SChao Yu { 21527a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2153444c580fSJaegeuk Kim } 2154444c580fSJaegeuk Kim 2155987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2156987c7c31SChao Yu { 215791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2158987c7c31SChao Yu } 2159987c7c31SChao Yu 216081ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2161de93653fSJaegeuk Kim { 216281ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 21637a2af766SChao Yu return CUR_ADDRS_PER_INODE(inode) - F2FS_INLINE_XATTR_ADDRS; 21647a2af766SChao Yu return CUR_ADDRS_PER_INODE(inode); 2165de93653fSJaegeuk Kim } 2166de93653fSJaegeuk Kim 216765985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 216865985d93SJaegeuk Kim { 2169695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2170cac5a3d8SDongOh Shin 217165985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 217265985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 217365985d93SJaegeuk Kim } 217465985d93SJaegeuk Kim 217565985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 217665985d93SJaegeuk Kim { 2177987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 217865985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 217965985d93SJaegeuk Kim else 218065985d93SJaegeuk Kim return 0; 218165985d93SJaegeuk Kim } 218265985d93SJaegeuk Kim 21830dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 21840dbdc2aeSJaegeuk Kim { 218591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 21860dbdc2aeSJaegeuk Kim } 21870dbdc2aeSJaegeuk Kim 2188b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2189b3d208f9SJaegeuk Kim { 219091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2191b3d208f9SJaegeuk Kim } 2192b3d208f9SJaegeuk Kim 2193510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2194510022a8SJaegeuk Kim { 219591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2196510022a8SJaegeuk Kim } 2197510022a8SJaegeuk Kim 219888b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 219988b88a66SJaegeuk Kim { 220091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 220188b88a66SJaegeuk Kim } 220288b88a66SJaegeuk Kim 22035fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 22045fe45743SChao Yu { 22055fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 22065fe45743SChao Yu } 22075fe45743SChao Yu 220802a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 220902a1335fSJaegeuk Kim { 221091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 221102a1335fSJaegeuk Kim } 221202a1335fSJaegeuk Kim 22133c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 22143c6c2bebSJaegeuk Kim { 221591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 22163c6c2bebSJaegeuk Kim } 22173c6c2bebSJaegeuk Kim 22181e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 22191e84371fSJaegeuk Kim { 222091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 22211e84371fSJaegeuk Kim } 22221e84371fSJaegeuk Kim 2223f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 22241001b347SHuajun Li { 2225695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 22267a2af766SChao Yu int extra_size = get_extra_isize(inode); 2227cac5a3d8SDongOh Shin 22287a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 22291001b347SHuajun Li } 22301001b347SHuajun Li 223134d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 223234d67debSChao Yu { 223391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 223434d67debSChao Yu } 223534d67debSChao Yu 22369486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 22379486ba44SJaegeuk Kim { 22389486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 22399486ba44SJaegeuk Kim kunmap(page); 22409486ba44SJaegeuk Kim } 22419486ba44SJaegeuk Kim 2242b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2243b5492af7SJaegeuk Kim { 2244b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2245b5492af7SJaegeuk Kim } 2246b5492af7SJaegeuk Kim 2247b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2248b5492af7SJaegeuk Kim { 2249b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 22507c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2251b5492af7SJaegeuk Kim } 2252b5492af7SJaegeuk Kim 2253b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2254b5492af7SJaegeuk Kim { 2255b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 22567c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2257b5492af7SJaegeuk Kim } 2258b5492af7SJaegeuk Kim 225926787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 226026787236SJaegeuk Kim { 226126787236SJaegeuk Kim if (dsync) { 226226787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 226326787236SJaegeuk Kim bool ret; 226426787236SJaegeuk Kim 226526787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 226626787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 226726787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 226826787236SJaegeuk Kim return ret; 226926787236SJaegeuk Kim } 227026787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 227126787236SJaegeuk Kim file_keep_isize(inode) || 227226787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 227326787236SJaegeuk Kim return false; 227426787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 2275267378d4SChao Yu } 2276267378d4SChao Yu 2277267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 2278267378d4SChao Yu { 2279267378d4SChao Yu return sb->s_flags & MS_RDONLY; 2280267378d4SChao Yu } 228139a53e0cSJaegeuk Kim 228239a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 228339a53e0cSJaegeuk Kim { 2284aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 228539a53e0cSJaegeuk Kim } 228639a53e0cSJaegeuk Kim 2287eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2288eaa693f4SJaegeuk Kim { 2289eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2290eaa693f4SJaegeuk Kim return true; 2291eaa693f4SJaegeuk Kim 2292eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2293eaa693f4SJaegeuk Kim return true; 2294eaa693f4SJaegeuk Kim 2295eaa693f4SJaegeuk Kim return false; 2296eaa693f4SJaegeuk Kim } 2297eaa693f4SJaegeuk Kim 22983e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 22993e72f721SJaegeuk Kim { 23003e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 230191942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 23023e72f721SJaegeuk Kim return false; 23033e72f721SJaegeuk Kim 2304886f56f9SAl Viro return S_ISREG(inode->i_mode); 23053e72f721SJaegeuk Kim } 23063e72f721SJaegeuk Kim 23071ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 23081ecc0c5cSChao Yu size_t size, gfp_t flags) 23090414b004SJaegeuk Kim { 23102c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 231155523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 231255523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 23132c63feadSJaegeuk Kim return NULL; 231455523519SChao Yu } 23152c63feadSJaegeuk Kim #endif 23160414b004SJaegeuk Kim return kmalloc(size, flags); 23170414b004SJaegeuk Kim } 23180414b004SJaegeuk Kim 23197a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 2320f2470371SChao Yu { 23217a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 2322f2470371SChao Yu } 2323f2470371SChao Yu 232439a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 232591942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 232639a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 232739a53e0cSJaegeuk Kim 23287a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 23297a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 23307a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 23317a2af766SChao Yu 23325c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 23335c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 23345c57132eSChao Yu ((offsetof(typeof(*f2fs_inode), field) + \ 23355c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 23365c57132eSChao Yu <= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize)) \ 23375c57132eSChao Yu 2338b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 2339b0af6d49SChao Yu { 2340b0af6d49SChao Yu int i; 2341b0af6d49SChao Yu 2342b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2343b0af6d49SChao Yu for (i = 0; i < NR_IO_TYPE; i++) 2344b0af6d49SChao Yu sbi->write_iostat[i] = 0; 2345b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2346b0af6d49SChao Yu } 2347b0af6d49SChao Yu 2348b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 2349b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 2350b0af6d49SChao Yu { 2351b0af6d49SChao Yu if (!sbi->iostat_enable) 2352b0af6d49SChao Yu return; 2353b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2354b0af6d49SChao Yu sbi->write_iostat[type] += io_bytes; 2355b0af6d49SChao Yu 2356b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 2357b0af6d49SChao Yu sbi->write_iostat[APP_BUFFERED_IO] = 2358b0af6d49SChao Yu sbi->write_iostat[APP_WRITE_IO] - 2359b0af6d49SChao Yu sbi->write_iostat[APP_DIRECT_IO]; 2360b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2361b0af6d49SChao Yu } 2362b0af6d49SChao Yu 236339a53e0cSJaegeuk Kim /* 236439a53e0cSJaegeuk Kim * file.c 236539a53e0cSJaegeuk Kim */ 2366cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2367cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2368cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2369cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2370a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2371a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2372cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2373cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2374cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2375cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2376cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 237739a53e0cSJaegeuk Kim 237839a53e0cSJaegeuk Kim /* 237939a53e0cSJaegeuk Kim * inode.c 238039a53e0cSJaegeuk Kim */ 2381cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2382704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 2383704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 2384cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2385cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2386cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2387cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2388cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2389cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2390cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2391cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 239239a53e0cSJaegeuk Kim 239339a53e0cSJaegeuk Kim /* 239439a53e0cSJaegeuk Kim * namei.c 239539a53e0cSJaegeuk Kim */ 239639a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 239739a53e0cSJaegeuk Kim 239839a53e0cSJaegeuk Kim /* 239939a53e0cSJaegeuk Kim * dir.c 240039a53e0cSJaegeuk Kim */ 2401cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2402cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2403cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2404cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2405cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2406cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2407cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2408cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2409cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2410cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2411cac5a3d8SDongOh Shin const struct qstr *new_name, 2412cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2413cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2414cac5a3d8SDongOh Shin unsigned int current_depth); 2415cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2416cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2417cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2418cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2419cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2420cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2421cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2422cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2423cac5a3d8SDongOh Shin struct page **page); 2424cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2425cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2426cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2427cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2428cac5a3d8SDongOh Shin unsigned int bit_pos); 2429cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2430cac5a3d8SDongOh Shin const struct qstr *orig_name, 2431cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2432cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2433cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2434cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2435cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2436cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2437cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2438cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2439cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 244039a53e0cSJaegeuk Kim 2441b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2442b7f7a5e0SAl Viro { 24432b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2444510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2445b7f7a5e0SAl Viro } 2446b7f7a5e0SAl Viro 244739a53e0cSJaegeuk Kim /* 244839a53e0cSJaegeuk Kim * super.c 244939a53e0cSJaegeuk Kim */ 2450cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2451cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 24524b2414d0SChao Yu void f2fs_enable_quota_files(struct f2fs_sb_info *sbi); 24534b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 2454cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2455cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2456a07ef784SNamjae Jeon extern __printf(3, 4) 2457cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2458984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 245939a53e0cSJaegeuk Kim 246039a53e0cSJaegeuk Kim /* 246139a53e0cSJaegeuk Kim * hash.c 246239a53e0cSJaegeuk Kim */ 24636332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, 24646332cd32SJaegeuk Kim struct fscrypt_name *fname); 246539a53e0cSJaegeuk Kim 246639a53e0cSJaegeuk Kim /* 246739a53e0cSJaegeuk Kim * node.c 246839a53e0cSJaegeuk Kim */ 246939a53e0cSJaegeuk Kim struct dnode_of_data; 247039a53e0cSJaegeuk Kim struct node_info; 247139a53e0cSJaegeuk Kim 2472cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2473cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2474cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2475cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2476cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2477cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2478cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2479cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2480cac5a3d8SDongOh Shin int truncate_xattr_node(struct inode *inode, struct page *page); 2481cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2482cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2483cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 24845f4ce6abSYunlei He struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs); 2485cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2486cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2487cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2488cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2489cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2490cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2491401db79fSYunlong Song int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc, 2492b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 249322ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2494cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2495cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2496cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2497cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2498cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2499d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2500cac5a3d8SDongOh Shin block_t blkaddr); 2501cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2502cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2503cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 250422ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2505cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2506cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 25076e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 250839a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 250939a53e0cSJaegeuk Kim 251039a53e0cSJaegeuk Kim /* 251139a53e0cSJaegeuk Kim * segment.c 251239a53e0cSJaegeuk Kim */ 2513cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 2514cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 25158c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2516cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2517cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2518cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2519cac5a3d8SDongOh Shin int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2520cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2521cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2522cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2523cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2524cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2525cce13252SChao Yu void stop_discard_thread(struct f2fs_sb_info *sbi); 2526d431413fSChao Yu void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2527cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2528cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2529cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2530cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2531cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2532cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2533cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2534cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2535b0af6d49SChao Yu void write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 2536b0af6d49SChao Yu enum iostat_type io_type); 2537cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2538cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2539d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2540cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2541cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2542cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2543cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2544cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2545cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2546cac5a3d8SDongOh Shin bool recover_newaddr); 2547cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2548cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2549fb830fc5SChao Yu struct f2fs_summary *sum, int type, 2550fb830fc5SChao Yu struct f2fs_io_info *fio, bool add_list); 2551cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2552cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2553cac5a3d8SDongOh Shin void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2554cac5a3d8SDongOh Shin block_t blkaddr); 2555cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2556cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2557cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2558cac5a3d8SDongOh Shin unsigned int val, int alloc); 2559cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2560cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2561cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 25627fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 25637fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 256439a53e0cSJaegeuk Kim 256539a53e0cSJaegeuk Kim /* 256639a53e0cSJaegeuk Kim * checkpoint.c 256739a53e0cSJaegeuk Kim */ 2568cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2569cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2570cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2571cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2572cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2573cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2574cac5a3d8SDongOh Shin int type, bool sync); 2575cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2576cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2577b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 2578cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2579cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2580cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2581cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2582cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2583cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2584cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2585cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2586cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2587cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2588cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2589cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2590cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2591cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2592cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2593cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 25946e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 259539a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 259639a53e0cSJaegeuk Kim 259739a53e0cSJaegeuk Kim /* 259839a53e0cSJaegeuk Kim * data.c 259939a53e0cSJaegeuk Kim */ 2600b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 2601b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 2602942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2603b9109b0eSJaegeuk Kim enum page_type type); 2604b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 2605cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2606b9109b0eSJaegeuk Kim int f2fs_submit_page_write(struct f2fs_io_info *fio); 2607cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2608cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2609cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2610cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2611cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2612cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2613cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2614cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2615cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2616cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2617cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2618cac5a3d8SDongOh Shin int op_flags, bool for_write); 2619cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2620cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2621cac5a3d8SDongOh Shin bool for_write); 2622cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2623cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2624cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2625cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2626cac5a3d8SDongOh Shin int create, int flag); 2627cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2628cac5a3d8SDongOh Shin u64 start, u64 len); 2629cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2630b0af6d49SChao Yu int __f2fs_write_data_pages(struct address_space *mapping, 2631b0af6d49SChao Yu struct writeback_control *wbc, 2632b0af6d49SChao Yu enum iostat_type io_type); 2633cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2634cac5a3d8SDongOh Shin unsigned int length); 2635cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 26365b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2637cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2638cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 26395b7a487cSWeichao Guo #endif 264039a53e0cSJaegeuk Kim 264139a53e0cSJaegeuk Kim /* 264239a53e0cSJaegeuk Kim * gc.c 264339a53e0cSJaegeuk Kim */ 2644cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2645cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2646cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2647e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 2648e066b83cSJaegeuk Kim unsigned int segno); 2649cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 265039a53e0cSJaegeuk Kim 265139a53e0cSJaegeuk Kim /* 265239a53e0cSJaegeuk Kim * recovery.c 265339a53e0cSJaegeuk Kim */ 2654cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2655cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 265639a53e0cSJaegeuk Kim 265739a53e0cSJaegeuk Kim /* 265839a53e0cSJaegeuk Kim * debug.c 265939a53e0cSJaegeuk Kim */ 266039a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 266139a53e0cSJaegeuk Kim struct f2fs_stat_info { 266239a53e0cSJaegeuk Kim struct list_head stat_list; 266339a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 266439a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 266539a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 26665b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 26675b7ee374SChao Yu unsigned long long hit_total, total_ext; 2668c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 266935782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 267035782b23SJaegeuk Kim int inmem_pages; 26710f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 26725b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 26735b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 267439a53e0cSJaegeuk Kim int total_count, utilization; 26758b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 26768b8dd65fSChao Yu int nr_flushing, nr_flushed, nr_discarding, nr_discarded; 26775f32366aSChao Yu int nr_discard_cmd; 2678d84d1cbdSChao Yu unsigned int undiscard_blks; 2679a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2680648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2681f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 268239a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 268339a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 268439a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 268539a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 268642190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 268739a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2688e1235983SChangman Lee int bg_node_segs, bg_data_segs; 268939a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2690e1235983SChangman Lee int bg_data_blks, bg_node_blks; 269139a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 269239a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 269339a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 269439a53e0cSJaegeuk Kim 269539a53e0cSJaegeuk Kim unsigned int segment_count[2]; 269639a53e0cSJaegeuk Kim unsigned int block_count[2]; 2697b9a2c252SChangman Lee unsigned int inplace_count; 26989edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 269939a53e0cSJaegeuk Kim }; 270039a53e0cSJaegeuk Kim 2701963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2702963d4f7dSGu Zheng { 2703963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2704963d4f7dSGu Zheng } 2705963d4f7dSGu Zheng 2706942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 270742190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 270839a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2709dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 271033fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 271133fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 27125b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 27135b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 27145b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 27155b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2716d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2717d5e8f6c9SChao Yu do { \ 2718d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2719d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2720d5e8f6c9SChao Yu } while (0) 2721d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2722d5e8f6c9SChao Yu do { \ 2723d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2724d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2725d5e8f6c9SChao Yu } while (0) 27260dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 27270dbdc2aeSJaegeuk Kim do { \ 27280dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 272903e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 27300dbdc2aeSJaegeuk Kim } while (0) 27310dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 27320dbdc2aeSJaegeuk Kim do { \ 27330dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 273403e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 27350dbdc2aeSJaegeuk Kim } while (0) 27363289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 27373289c061SJaegeuk Kim do { \ 27383289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 273903e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 27403289c061SJaegeuk Kim } while (0) 27413289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 27423289c061SJaegeuk Kim do { \ 27433289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 274403e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 27453289c061SJaegeuk Kim } while (0) 2746dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2747dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2748dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2749dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2750b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2751b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 275226a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2753cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 275426a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2755cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 275626a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 275726a28a0cSJaegeuk Kim do { \ 275826a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 275926a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 276026a28a0cSJaegeuk Kim if (cur > max) \ 276126a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 276226a28a0cSJaegeuk Kim } while (0) 2763648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2764648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2765648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2766648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2767648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2768648d50baSChao Yu do { \ 2769648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2770648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2771648d50baSChao Yu if (cur > max) \ 2772648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2773648d50baSChao Yu } while (0) 2774e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 277539a53e0cSJaegeuk Kim do { \ 2776963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 277768afcf2dSTomohiro Kusumi si->tot_segs++; \ 277868afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 277939a53e0cSJaegeuk Kim si->data_segs++; \ 2780e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2781e1235983SChangman Lee } else { \ 278239a53e0cSJaegeuk Kim si->node_segs++; \ 2783e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2784e1235983SChangman Lee } \ 278539a53e0cSJaegeuk Kim } while (0) 278639a53e0cSJaegeuk Kim 278739a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 278868afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 278939a53e0cSJaegeuk Kim 2790e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 279139a53e0cSJaegeuk Kim do { \ 2792963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 279339a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 279439a53e0cSJaegeuk Kim si->data_blks += (blks); \ 279568afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 279639a53e0cSJaegeuk Kim } while (0) 279739a53e0cSJaegeuk Kim 2798e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 279939a53e0cSJaegeuk Kim do { \ 2800963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 280139a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 280239a53e0cSJaegeuk Kim si->node_blks += (blks); \ 280368afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 280439a53e0cSJaegeuk Kim } while (0) 280539a53e0cSJaegeuk Kim 2806cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2807cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2808787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 28094589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 281039a53e0cSJaegeuk Kim #else 2811d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 2812d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 2813d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 2814d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 2815d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 2816d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 2817d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 2818d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 2819d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 2820d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 2821d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 2822d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 2823d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 2824d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 2825d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 2826d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 2827d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 2828d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 2829d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 2830d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 2831d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 2832d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 2833d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 2834d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 2835d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 2836d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 2837d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 2838d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 2839d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 284039a53e0cSJaegeuk Kim 284139a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 284239a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2843787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 28444589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 284539a53e0cSJaegeuk Kim #endif 284639a53e0cSJaegeuk Kim 284739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 284839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 284939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 285039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 285139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 285239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 285339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 285439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2855cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 285639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 285729e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 28581001b347SHuajun Li 2859e18c65b2SHuajun Li /* 2860e18c65b2SHuajun Li * inline.c 2861e18c65b2SHuajun Li */ 2862cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2863cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2864cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2865bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2866cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2867cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2868cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2869cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2870cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2871cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2872cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2873cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2874cac5a3d8SDongOh Shin struct page *ipage); 2875cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2876cac5a3d8SDongOh Shin const struct qstr *orig_name, 2877cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2878cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2879cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2880cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2881cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2882cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2883cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2884cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2885cac5a3d8SDongOh Shin __u64 start, __u64 len); 2886cde4de12SJaegeuk Kim 2887cde4de12SJaegeuk Kim /* 28882658e50dSJaegeuk Kim * shrinker.c 28892658e50dSJaegeuk Kim */ 2890cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2891cac5a3d8SDongOh Shin struct shrink_control *sc); 2892cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2893cac5a3d8SDongOh Shin struct shrink_control *sc); 2894cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2895cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 28962658e50dSJaegeuk Kim 28972658e50dSJaegeuk Kim /* 2898a28ef1f5SChao Yu * extent_cache.c 2899a28ef1f5SChao Yu */ 2900004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 2901004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 2902004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 2903004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 2904004b6862SChao Yu unsigned int ofs); 2905004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 2906004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 2907004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 2908004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 2909004b6862SChao Yu bool force); 2910df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi, 2911df0f6b44SChao Yu struct rb_root *root); 2912cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2913cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2914cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2915cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2916cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2917cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2918cac5a3d8SDongOh Shin struct extent_info *ei); 2919cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 292019b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2921cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2922cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2923a28ef1f5SChao Yu int __init create_extent_cache(void); 2924a28ef1f5SChao Yu void destroy_extent_cache(void); 2925a28ef1f5SChao Yu 2926a28ef1f5SChao Yu /* 29278ceffcb2SChao Yu * sysfs.c 29288ceffcb2SChao Yu */ 2929dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 2930dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 2931dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 2932dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 29338ceffcb2SChao Yu 29348ceffcb2SChao Yu /* 2935cde4de12SJaegeuk Kim * crypto support 2936cde4de12SJaegeuk Kim */ 29370b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2938cde4de12SJaegeuk Kim { 2939cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2940cde4de12SJaegeuk Kim } 2941cde4de12SJaegeuk Kim 2942*1958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 2943*1958593eSJaegeuk Kim { 2944*1958593eSJaegeuk Kim return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode); 2945*1958593eSJaegeuk Kim } 2946*1958593eSJaegeuk Kim 2947cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2948cde4de12SJaegeuk Kim { 2949cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2950cde4de12SJaegeuk Kim file_set_encrypt(inode); 2951cde4de12SJaegeuk Kim #endif 2952cde4de12SJaegeuk Kim } 2953cde4de12SJaegeuk Kim 2954cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2955cde4de12SJaegeuk Kim { 29560b81d077SJaegeuk Kim return bio->bi_private != NULL; 2957cde4de12SJaegeuk Kim } 2958cde4de12SJaegeuk Kim 2959cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2960cde4de12SJaegeuk Kim { 2961cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2962cde4de12SJaegeuk Kim } 2963f424f664SJaegeuk Kim 29640bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 296552763a4bSJaegeuk Kim { 29660bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 296752763a4bSJaegeuk Kim } 296852763a4bSJaegeuk Kim 29697a2af766SChao Yu static inline int f2fs_sb_has_extra_attr(struct super_block *sb) 29707a2af766SChao Yu { 29717a2af766SChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_EXTRA_ATTR); 29727a2af766SChao Yu } 29737a2af766SChao Yu 29745c57132eSChao Yu static inline int f2fs_sb_has_project_quota(struct super_block *sb) 29755c57132eSChao Yu { 29765c57132eSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_PRJQUOTA); 29775c57132eSChao Yu } 29785c57132eSChao Yu 2979704956ecSChao Yu static inline int f2fs_sb_has_inode_chksum(struct super_block *sb) 2980704956ecSChao Yu { 2981704956ecSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CHKSUM); 2982704956ecSChao Yu } 2983704956ecSChao Yu 2984178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2985178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 29863c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2987178053e2SDamien Le Moal { 2988178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 29893c62be17SJaegeuk Kim int i; 2990178053e2SDamien Le Moal 29913c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 29923c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 29933c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 29943c62be17SJaegeuk Kim return -EINVAL; 2995178053e2SDamien Le Moal } 2996178053e2SDamien Le Moal #endif 2997178053e2SDamien Le Moal 299896ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 299996ba2decSDamien Le Moal { 300096ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 300196ba2decSDamien Le Moal 300296ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 300352763a4bSJaegeuk Kim } 300452763a4bSJaegeuk Kim 300552763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 300652763a4bSJaegeuk Kim { 300752763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 300852763a4bSJaegeuk Kim clear_opt(sbi, LFS); 300952763a4bSJaegeuk Kim 301052763a4bSJaegeuk Kim switch (mt) { 301152763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 301252763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 301352763a4bSJaegeuk Kim break; 301452763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 301552763a4bSJaegeuk Kim set_opt(sbi, LFS); 301652763a4bSJaegeuk Kim break; 301752763a4bSJaegeuk Kim } 301852763a4bSJaegeuk Kim } 301952763a4bSJaegeuk Kim 3020fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 3021fcc85a4dSJaegeuk Kim { 3022fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 3023886f56f9SAl Viro umode_t mode = inode->i_mode; 3024fcc85a4dSJaegeuk Kim 3025fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 3026fcc85a4dSJaegeuk Kim #else 3027fcc85a4dSJaegeuk Kim return 0; 3028fcc85a4dSJaegeuk Kim #endif 3029fcc85a4dSJaegeuk Kim } 3030fcc85a4dSJaegeuk Kim 303139a53e0cSJaegeuk Kim #endif 3032