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 96*6afc662eSChao Yu #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 9739a53e0cSJaegeuk Kim 9868afcf2dSTomohiro Kusumi #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) 9968afcf2dSTomohiro Kusumi #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) 10068afcf2dSTomohiro Kusumi #define test_opt(sbi, option) ((sbi)->mount_opt.opt & F2FS_MOUNT_##option) 10139a53e0cSJaegeuk Kim 10239a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 10339a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 10439a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 10539a53e0cSJaegeuk Kim 106a9841c4dSJaegeuk Kim typedef u32 block_t; /* 107a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 108a9841c4dSJaegeuk Kim * address format, __le32. 109a9841c4dSJaegeuk Kim */ 11039a53e0cSJaegeuk Kim typedef u32 nid_t; 11139a53e0cSJaegeuk Kim 11239a53e0cSJaegeuk Kim struct f2fs_mount_info { 11339a53e0cSJaegeuk Kim unsigned int opt; 11439a53e0cSJaegeuk Kim }; 11539a53e0cSJaegeuk Kim 116cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1170bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 118e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1197a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1205c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 121704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 122*6afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 123cde4de12SJaegeuk Kim 12476f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 12576f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 12676f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 127c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 12876f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 129c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 13076f105a2SJaegeuk Kim 13139a53e0cSJaegeuk Kim /* 13239a53e0cSJaegeuk Kim * For checkpoint manager 13339a53e0cSJaegeuk Kim */ 13439a53e0cSJaegeuk Kim enum { 13539a53e0cSJaegeuk Kim NAT_BITMAP, 13639a53e0cSJaegeuk Kim SIT_BITMAP 13739a53e0cSJaegeuk Kim }; 13839a53e0cSJaegeuk Kim 139c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 140c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 141c473f1a9SChao Yu #define CP_SYNC 0x00000004 142c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 143c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1441f43e2adSChao Yu #define CP_TRIMMED 0x00000020 14575ab4cb8SJaegeuk Kim 14647b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 147bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 1484ddb1a4dSJaegeuk Kim (GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections)) 149a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 150a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 1514ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 152ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 153969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 154969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 15560b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 156dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 157bba681cbSJaegeuk Kim 15875ab4cb8SJaegeuk Kim struct cp_control { 15975ab4cb8SJaegeuk Kim int reason; 1604b2fecc8SJaegeuk Kim __u64 trim_start; 1614b2fecc8SJaegeuk Kim __u64 trim_end; 1624b2fecc8SJaegeuk Kim __u64 trim_minlen; 1634b2fecc8SJaegeuk Kim __u64 trimmed; 16475ab4cb8SJaegeuk Kim }; 16575ab4cb8SJaegeuk Kim 166662befdaSChao Yu /* 16781c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 168662befdaSChao Yu */ 169662befdaSChao Yu enum { 170662befdaSChao Yu META_CP, 171662befdaSChao Yu META_NAT, 17281c1a0f1SChao Yu META_SIT, 1734c521f49SJaegeuk Kim META_SSA, 1744c521f49SJaegeuk Kim META_POR, 175662befdaSChao Yu }; 176662befdaSChao Yu 1776451e041SJaegeuk Kim /* for the list of ino */ 1786451e041SJaegeuk Kim enum { 1796451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 180fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 181fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 18239d787beSChao Yu FLUSH_INO, /* for multiple device flushing */ 1836451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1846451e041SJaegeuk Kim }; 1856451e041SJaegeuk Kim 1866451e041SJaegeuk Kim struct ino_entry { 18739a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18839a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 18939d787beSChao Yu unsigned int dirty_device; /* dirty device bitmap */ 19039a53e0cSJaegeuk Kim }; 19139a53e0cSJaegeuk Kim 1922710fd7eSChao Yu /* for the list of inodes to be GCed */ 19306292073SChao Yu struct inode_entry { 19439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 19539a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 19639a53e0cSJaegeuk Kim }; 19739a53e0cSJaegeuk Kim 198a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 1997fd9e544SJaegeuk Kim struct discard_entry { 2007fd9e544SJaegeuk Kim struct list_head list; /* list head */ 201a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 202a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 2037fd9e544SJaegeuk Kim }; 2047fd9e544SJaegeuk Kim 205969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 206969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 207969d1b18SChao Yu 208ba48a33eSChao Yu /* max discard pend list number */ 209ba48a33eSChao Yu #define MAX_PLIST_NUM 512 210ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 211ba48a33eSChao Yu (MAX_PLIST_NUM - 1) : (blk_num - 1)) 212ba48a33eSChao 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 24478997b56SChao Yu enum { 24578997b56SChao Yu DPOLICY_BG, 24678997b56SChao Yu DPOLICY_FORCE, 24778997b56SChao Yu DPOLICY_FSTRIM, 24878997b56SChao Yu DPOLICY_UMOUNT, 24978997b56SChao Yu MAX_DPOLICY, 25078997b56SChao Yu }; 25178997b56SChao Yu 252ecc9aa00SChao Yu struct discard_policy { 25378997b56SChao Yu int type; /* type of discard */ 254ecc9aa00SChao Yu unsigned int min_interval; /* used for candidates exist */ 255ecc9aa00SChao Yu unsigned int max_interval; /* used for candidates not exist */ 256ecc9aa00SChao Yu unsigned int max_requests; /* # of discards issued per round */ 257ecc9aa00SChao Yu unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ 258ecc9aa00SChao Yu bool io_aware; /* issue discard in idle time */ 259ecc9aa00SChao Yu bool sync; /* submit discard with REQ_SYNC flag */ 26078997b56SChao Yu unsigned int granularity; /* discard granularity */ 261ecc9aa00SChao Yu }; 262ecc9aa00SChao Yu 2630b54fb84SJaegeuk Kim struct discard_cmd_control { 26415469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 26546f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 266ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 267969d1b18SChao Yu unsigned char pend_list_tag[MAX_PLIST_NUM];/* tag for pending entries */ 26846f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 2698412663dSChao Yu struct list_head fstrim_list; /* in-flight discard from fstrim */ 27015469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 271969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 27215469963SJaegeuk Kim struct mutex cmd_lock; 273d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 274d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 275969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 276d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 2778b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 2788b8dd65fSChao Yu atomic_t issing_discard; /* # of issing discard */ 2795f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 280004b6862SChao Yu struct rb_root root; /* root of discard rb-tree */ 28139a53e0cSJaegeuk Kim }; 28239a53e0cSJaegeuk Kim 28339a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 28439a53e0cSJaegeuk Kim struct fsync_inode_entry { 28539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 28639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 287c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 288c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 28939a53e0cSJaegeuk Kim }; 29039a53e0cSJaegeuk Kim 29168afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 29268afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 29339a53e0cSJaegeuk Kim 29468afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 29568afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 29668afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 29768afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 29839a53e0cSJaegeuk Kim 299dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 300dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 301309cc2b6SJaegeuk Kim 302dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 30339a53e0cSJaegeuk Kim { 304dfc08a12SChao Yu int before = nats_in_cursum(journal); 305cac5a3d8SDongOh Shin 306dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 30739a53e0cSJaegeuk Kim return before; 30839a53e0cSJaegeuk Kim } 30939a53e0cSJaegeuk Kim 310dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 31139a53e0cSJaegeuk Kim { 312dfc08a12SChao Yu int before = sits_in_cursum(journal); 313cac5a3d8SDongOh Shin 314dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 31539a53e0cSJaegeuk Kim return before; 31639a53e0cSJaegeuk Kim } 31739a53e0cSJaegeuk Kim 318dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 319dfc08a12SChao Yu int size, int type) 320184a5cd2SChao Yu { 321184a5cd2SChao Yu if (type == NAT_JOURNAL) 322dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 323dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 324184a5cd2SChao Yu } 325184a5cd2SChao Yu 32639a53e0cSJaegeuk Kim /* 327e9750824SNamjae Jeon * ioctl commands 328e9750824SNamjae Jeon */ 329e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 330e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 331d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 332e9750824SNamjae Jeon 33388b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 33488b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 33588b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 33602a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 3371e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 3381e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 339d07efb50SJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32) 340456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 341d07efb50SJaegeuk Kim #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \ 342d07efb50SJaegeuk Kim struct f2fs_defragment) 3434dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 3444dd6f977SJaegeuk Kim struct f2fs_move_range) 345e066b83cSJaegeuk Kim #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ 346e066b83cSJaegeuk Kim struct f2fs_flush_device) 34734dc77adSJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ 34834dc77adSJaegeuk Kim struct f2fs_gc_range) 349e65ef207SJaegeuk Kim #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) 35088b88a66SJaegeuk Kim 3510b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 3520b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 3530b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 354f424f664SJaegeuk Kim 3551abff93dSJaegeuk Kim /* 3561abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 3571abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 3581abff93dSJaegeuk Kim */ 3591abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 3601abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 3611abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 3621abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 363c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 3641abff93dSJaegeuk Kim 365e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 366e9750824SNamjae Jeon /* 367e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 368e9750824SNamjae Jeon */ 369e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 370e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 37104ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 372e9750824SNamjae Jeon #endif 373e9750824SNamjae Jeon 3742c1d0305SChao Yu #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR 3752c1d0305SChao Yu #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR 3762c1d0305SChao Yu 37734dc77adSJaegeuk Kim struct f2fs_gc_range { 37834dc77adSJaegeuk Kim u32 sync; 37934dc77adSJaegeuk Kim u64 start; 38034dc77adSJaegeuk Kim u64 len; 38134dc77adSJaegeuk Kim }; 38234dc77adSJaegeuk Kim 383d323d005SChao Yu struct f2fs_defragment { 384d323d005SChao Yu u64 start; 385d323d005SChao Yu u64 len; 386d323d005SChao Yu }; 387d323d005SChao Yu 3884dd6f977SJaegeuk Kim struct f2fs_move_range { 3894dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3904dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3914dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3924dd6f977SJaegeuk Kim u64 len; /* size to move */ 3934dd6f977SJaegeuk Kim }; 3944dd6f977SJaegeuk Kim 395e066b83cSJaegeuk Kim struct f2fs_flush_device { 396e066b83cSJaegeuk Kim u32 dev_num; /* device number to flush */ 397e066b83cSJaegeuk Kim u32 segments; /* # of segments to flush */ 398e066b83cSJaegeuk Kim }; 399e066b83cSJaegeuk Kim 400f2470371SChao Yu /* for inline stuff */ 401f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 402*6afc662eSChao Yu #define DEF_MIN_INLINE_SIZE 1 4037a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 404*6afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode); 405*6afc662eSChao Yu #define F2FS_INLINE_XATTR_ADDRS(inode) get_inline_xattr_addrs(inode) 4067a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 4077a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 408*6afc662eSChao Yu F2FS_INLINE_XATTR_ADDRS(inode) - \ 409*6afc662eSChao Yu DEF_INLINE_RESERVED_SIZE)) 410f2470371SChao Yu 411f2470371SChao Yu /* for inline dir */ 412f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 413f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 414f2470371SChao Yu BITS_PER_BYTE + 1)) 415f2470371SChao Yu #define INLINE_DENTRY_BITMAP_SIZE(inode) ((NR_INLINE_DENTRY(inode) + \ 416f2470371SChao Yu BITS_PER_BYTE - 1) / BITS_PER_BYTE) 417f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 418f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 419f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 420f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 421f2470371SChao Yu 422e9750824SNamjae Jeon /* 42339a53e0cSJaegeuk Kim * For INODE and NODE manager 42439a53e0cSJaegeuk Kim */ 4257b3cd7d6SJaegeuk Kim /* for directory operations */ 4267b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 427d8c6822aSJaegeuk Kim struct inode *inode; 42876a9dd85SChao Yu void *bitmap; 4297b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 4307b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 4317b3cd7d6SJaegeuk Kim int max; 43276a9dd85SChao Yu int nr_bitmap; 4337b3cd7d6SJaegeuk Kim }; 4347b3cd7d6SJaegeuk Kim 43564c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 43664c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 4377b3cd7d6SJaegeuk Kim { 438d8c6822aSJaegeuk Kim d->inode = inode; 4397b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 44076a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 4417b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 4427b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 4437b3cd7d6SJaegeuk Kim d->filename = t->filename; 44464c24ecbSTomohiro Kusumi } 445cac5a3d8SDongOh Shin 44664c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 447f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 44864c24ecbSTomohiro Kusumi { 449f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 450f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 451f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 452f2470371SChao Yu 45364c24ecbSTomohiro Kusumi d->inode = inode; 454f2470371SChao Yu d->max = entry_cnt; 455f2470371SChao Yu d->nr_bitmap = bitmap_size; 456f2470371SChao Yu d->bitmap = t; 457f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 458f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 459f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 4607b3cd7d6SJaegeuk Kim } 4617b3cd7d6SJaegeuk Kim 462dbe6a5ffSJaegeuk Kim /* 463dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 464dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 465dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 46639a53e0cSJaegeuk Kim */ 467dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 468dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 469266e97a8SJaegeuk Kim enum { 470266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 471266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 472266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 473266e97a8SJaegeuk Kim * look up a node with readahead called 4744f4124d0SChao Yu * by get_data_block. 47539a53e0cSJaegeuk Kim */ 476266e97a8SJaegeuk Kim }; 477266e97a8SJaegeuk Kim 478a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 47939a53e0cSJaegeuk Kim 480817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 481817202d9SChao Yu 48213054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 48313054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 48413054c54SChao Yu 48539a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 48613054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 48713054c54SChao Yu 48813054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 48913054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 490c11abd1aSJaegeuk Kim 49154c2258cSChao Yu struct rb_entry { 49254c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 49354c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 49454c2258cSChao Yu unsigned int len; /* length of the entry */ 49554c2258cSChao Yu }; 49654c2258cSChao Yu 49739a53e0cSJaegeuk Kim struct extent_info { 49839a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 499111d2495SMasanari Iida unsigned int len; /* length of the extent */ 50054c2258cSChao Yu u32 blk; /* start block address of the extent */ 50139a53e0cSJaegeuk Kim }; 50239a53e0cSJaegeuk Kim 50313054c54SChao Yu struct extent_node { 50454c2258cSChao Yu struct rb_node rb_node; 50554c2258cSChao Yu union { 50654c2258cSChao Yu struct { 50754c2258cSChao Yu unsigned int fofs; 50854c2258cSChao Yu unsigned int len; 50954c2258cSChao Yu u32 blk; 51054c2258cSChao Yu }; 51113054c54SChao Yu struct extent_info ei; /* extent info */ 51254c2258cSChao Yu 51354c2258cSChao Yu }; 51454c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 515201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 51613054c54SChao Yu }; 51713054c54SChao Yu 51813054c54SChao Yu struct extent_tree { 51913054c54SChao Yu nid_t ino; /* inode number */ 52013054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 52162c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 5223e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 523137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 52413054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 52568e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 52613054c54SChao Yu }; 52713054c54SChao Yu 52839a53e0cSJaegeuk Kim /* 529003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 530003a3e1dSJaegeuk Kim * 531003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 532003a3e1dSJaegeuk Kim */ 533003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 534003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 5357f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 5367f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 5377f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 538003a3e1dSJaegeuk Kim 539003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 540003a3e1dSJaegeuk Kim block_t m_pblk; 541003a3e1dSJaegeuk Kim block_t m_lblk; 542003a3e1dSJaegeuk Kim unsigned int m_len; 543003a3e1dSJaegeuk Kim unsigned int m_flags; 544da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 545003a3e1dSJaegeuk Kim }; 546003a3e1dSJaegeuk Kim 547e2b4e2bcSChao Yu /* for flag in get_data_block */ 548f2220c7fSQiuyang Sun enum { 549f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 550f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 551f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 552f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 553f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 554f2220c7fSQiuyang Sun }; 555e2b4e2bcSChao Yu 556003a3e1dSJaegeuk Kim /* 55739a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 55839a53e0cSJaegeuk Kim */ 55939a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 560354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 561cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 562e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 56326787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 56439a53e0cSJaegeuk Kim 565b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 566b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 567b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 568b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 569b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 570b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 571cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 572cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 573cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 574e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 575e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 57626787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 57726787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 578cde4de12SJaegeuk Kim 579ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 580ab9fa662SJaegeuk Kim 58139a53e0cSJaegeuk Kim struct f2fs_inode_info { 58239a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 58339a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 58439a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 58538431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 58639a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 5876666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 58839a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 58939a53e0cSJaegeuk Kim 59039a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 59139a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 592d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 593204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 59439a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 59539a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 59688c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 597b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 59839a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 59926de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 60088b88a66SJaegeuk Kim 6010abd675eSChao Yu #ifdef CONFIG_QUOTA 6020abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 6030abd675eSChao Yu 6040abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 6050abd675eSChao Yu qsize_t i_reserved_quota; 6060abd675eSChao Yu #endif 6070f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 6080f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 60957864ae5SJaegeuk Kim struct list_head inmem_ilist; /* list for inmem inodes */ 61088b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 6117a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 61288b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 6133e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 61482e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 6155a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 61627161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 617f2470371SChao Yu 6187a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 6195c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 620*6afc662eSChao Yu int i_inline_xattr_size; /* inline xattr size */ 62139a53e0cSJaegeuk Kim }; 62239a53e0cSJaegeuk Kim 62339a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 624bd933d4fSChao Yu struct f2fs_extent *i_ext) 62539a53e0cSJaegeuk Kim { 626bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 627bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 628bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 62939a53e0cSJaegeuk Kim } 63039a53e0cSJaegeuk Kim 63139a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 63239a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 63339a53e0cSJaegeuk Kim { 63439a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 6354d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 63639a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 63739a53e0cSJaegeuk Kim } 63839a53e0cSJaegeuk Kim 639429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 640429511cdSChao Yu u32 blk, unsigned int len) 641429511cdSChao Yu { 642429511cdSChao Yu ei->fofs = fofs; 643429511cdSChao Yu ei->blk = blk; 644429511cdSChao Yu ei->len = len; 645429511cdSChao Yu } 646429511cdSChao Yu 647004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 648004b6862SChao Yu struct discard_info *front) 649004b6862SChao Yu { 650004b6862SChao Yu return back->lstart + back->len == front->lstart; 651004b6862SChao Yu } 652004b6862SChao Yu 653004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 654004b6862SChao Yu struct discard_info *back) 655004b6862SChao Yu { 656004b6862SChao Yu return __is_discard_mergeable(back, cur); 657004b6862SChao Yu } 658004b6862SChao Yu 659004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 660004b6862SChao Yu struct discard_info *front) 661004b6862SChao Yu { 662004b6862SChao Yu return __is_discard_mergeable(cur, front); 663004b6862SChao Yu } 664004b6862SChao Yu 665429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 666429511cdSChao Yu struct extent_info *front) 667429511cdSChao Yu { 668429511cdSChao Yu return (back->fofs + back->len == front->fofs && 669429511cdSChao Yu back->blk + back->len == front->blk); 670429511cdSChao Yu } 671429511cdSChao Yu 672429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 673429511cdSChao Yu struct extent_info *back) 674429511cdSChao Yu { 675429511cdSChao Yu return __is_extent_mergeable(back, cur); 676429511cdSChao Yu } 677429511cdSChao Yu 678429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 679429511cdSChao Yu struct extent_info *front) 680429511cdSChao Yu { 681429511cdSChao Yu return __is_extent_mergeable(cur, front); 682429511cdSChao Yu } 683429511cdSChao Yu 684cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 685205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 686205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 6874abd3f5aSChao Yu { 688205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 6894abd3f5aSChao Yu et->largest = en->ei; 6907c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 691205b9822SJaegeuk Kim } 6924abd3f5aSChao Yu } 6934abd3f5aSChao Yu 6949a4ffdf5SChao Yu /* 6959a4ffdf5SChao Yu * For free nid management 6969a4ffdf5SChao Yu */ 6979a4ffdf5SChao Yu enum nid_state { 6989a4ffdf5SChao Yu FREE_NID, /* newly added to free nid list */ 6999a4ffdf5SChao Yu PREALLOC_NID, /* it is preallocated */ 7009a4ffdf5SChao Yu MAX_NID_STATE, 701b8559dc2SChao Yu }; 702b8559dc2SChao Yu 70339a53e0cSJaegeuk Kim struct f2fs_nm_info { 70439a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 70539a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 70604d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 70739a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 708cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 709ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 7102304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 71139a53e0cSJaegeuk Kim 71239a53e0cSJaegeuk Kim /* NAT cache management */ 71339a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 714309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 715b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 71639a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 717309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 718aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 71922ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 72039a53e0cSJaegeuk Kim 72139a53e0cSJaegeuk Kim /* free node ids management */ 7228a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 7239a4ffdf5SChao Yu struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ 7249a4ffdf5SChao Yu unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 725b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 72639a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 7274ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 7284ac91242SChao Yu unsigned char *nat_block_bitmap; 729586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 73039a53e0cSJaegeuk Kim 73139a53e0cSJaegeuk Kim /* for checkpoint */ 73239a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 73322ad0b6aSJaegeuk Kim 73422ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 73522ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 73622ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 73722ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 738599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 739599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 740599a09b2SChao Yu #endif 74139a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 74239a53e0cSJaegeuk Kim }; 74339a53e0cSJaegeuk Kim 74439a53e0cSJaegeuk Kim /* 74539a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 74639a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 74739a53e0cSJaegeuk Kim * by the data offset in a file. 74839a53e0cSJaegeuk Kim */ 74939a53e0cSJaegeuk Kim struct dnode_of_data { 75039a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 75139a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 75239a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 75339a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 75439a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 75539a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 75693bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 7573cf45747SChao Yu char cur_level; /* level of hole node page */ 7583cf45747SChao Yu char max_level; /* level of current page located */ 75939a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 76039a53e0cSJaegeuk Kim }; 76139a53e0cSJaegeuk Kim 76239a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 76339a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 76439a53e0cSJaegeuk Kim { 765d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 76639a53e0cSJaegeuk Kim dn->inode = inode; 76739a53e0cSJaegeuk Kim dn->inode_page = ipage; 76839a53e0cSJaegeuk Kim dn->node_page = npage; 76939a53e0cSJaegeuk Kim dn->nid = nid; 77039a53e0cSJaegeuk Kim } 77139a53e0cSJaegeuk Kim 77239a53e0cSJaegeuk Kim /* 77339a53e0cSJaegeuk Kim * For SIT manager 77439a53e0cSJaegeuk Kim * 77539a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 77639a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 77739a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 77839a53e0cSJaegeuk Kim * respectively. 77939a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 78039a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 78139a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 78239a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 78339a53e0cSJaegeuk Kim * data and 8 for node logs. 78439a53e0cSJaegeuk Kim */ 78539a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 78639a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 78739a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 78839a53e0cSJaegeuk Kim 78939a53e0cSJaegeuk Kim enum { 79039a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 79139a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 79239a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 79339a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 79439a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 79539a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 79638aa0889SJaegeuk Kim NO_CHECK_TYPE, 79739a53e0cSJaegeuk Kim }; 79839a53e0cSJaegeuk Kim 7996b4afdd7SJaegeuk Kim struct flush_cmd { 8006b4afdd7SJaegeuk Kim struct completion wait; 801721bd4d5SGu Zheng struct llist_node llnode; 80239d787beSChao Yu nid_t ino; 8036b4afdd7SJaegeuk Kim int ret; 8046b4afdd7SJaegeuk Kim }; 8056b4afdd7SJaegeuk Kim 806a688b9d9SGu Zheng struct flush_cmd_control { 807a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 808a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 8098b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 8108b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 811721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 812721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 813a688b9d9SGu Zheng }; 814a688b9d9SGu Zheng 81539a53e0cSJaegeuk Kim struct f2fs_sm_info { 81639a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 81739a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 81839a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 81939a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 82039a53e0cSJaegeuk Kim 82139a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 82239a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 82339a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 82439a53e0cSJaegeuk Kim 82539a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 82639a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 82739a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 82839a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 82981eb8d6eSJaegeuk Kim 83081eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 83181eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 8327fd9e544SJaegeuk Kim 833bba681cbSJaegeuk Kim /* for batched trimming */ 834bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 835bba681cbSJaegeuk Kim 836184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 837184a5cd2SChao Yu 838216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 839216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 840c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 841ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 8426b4afdd7SJaegeuk Kim 8436b4afdd7SJaegeuk Kim /* for flush command control */ 844b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 845a688b9d9SGu Zheng 8460b54fb84SJaegeuk Kim /* for discard command control */ 8470b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 84839a53e0cSJaegeuk Kim }; 84939a53e0cSJaegeuk Kim 85039a53e0cSJaegeuk Kim /* 85139a53e0cSJaegeuk Kim * For superblock 85239a53e0cSJaegeuk Kim */ 85339a53e0cSJaegeuk Kim /* 85439a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 85539a53e0cSJaegeuk Kim * 85639a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 85739a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 85839a53e0cSJaegeuk Kim */ 85936951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 86039a53e0cSJaegeuk Kim enum count_type { 86139a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 862c227f912SChao Yu F2FS_DIRTY_DATA, 86339a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 86439a53e0cSJaegeuk Kim F2FS_DIRTY_META, 8658dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 8660f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 86736951b38SChao Yu F2FS_WB_CP_DATA, 86836951b38SChao Yu F2FS_WB_DATA, 86939a53e0cSJaegeuk Kim NR_COUNT_TYPE, 87039a53e0cSJaegeuk Kim }; 87139a53e0cSJaegeuk Kim 87239a53e0cSJaegeuk Kim /* 873e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 87439a53e0cSJaegeuk Kim * The available types are: 87539a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 87639a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 87739a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 87839a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 87939a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 88039a53e0cSJaegeuk Kim * with waiting the bio's completion 88139a53e0cSJaegeuk Kim * ... Only can be used with META. 88239a53e0cSJaegeuk Kim */ 8837d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 88439a53e0cSJaegeuk Kim enum page_type { 88539a53e0cSJaegeuk Kim DATA, 88639a53e0cSJaegeuk Kim NODE, 88739a53e0cSJaegeuk Kim META, 88839a53e0cSJaegeuk Kim NR_PAGE_TYPE, 88939a53e0cSJaegeuk Kim META_FLUSH, 8908ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 8918ce67cb0SJaegeuk Kim INMEM_DROP, 8928c242db9SJaegeuk Kim INMEM_INVALIDATE, 89328bc106bSChao Yu INMEM_REVOKE, 8948ce67cb0SJaegeuk Kim IPU, 8958ce67cb0SJaegeuk Kim OPU, 89639a53e0cSJaegeuk Kim }; 89739a53e0cSJaegeuk Kim 898a912b54dSJaegeuk Kim enum temp_type { 899a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 900a912b54dSJaegeuk Kim WARM, 901a912b54dSJaegeuk Kim COLD, 902a912b54dSJaegeuk Kim NR_TEMP_TYPE, 903a912b54dSJaegeuk Kim }; 904a912b54dSJaegeuk Kim 905cc15620bSJaegeuk Kim enum need_lock_type { 906cc15620bSJaegeuk Kim LOCK_REQ = 0, 907cc15620bSJaegeuk Kim LOCK_DONE, 908cc15620bSJaegeuk Kim LOCK_RETRY, 909cc15620bSJaegeuk Kim }; 910cc15620bSJaegeuk Kim 911b0af6d49SChao Yu enum iostat_type { 912b0af6d49SChao Yu APP_DIRECT_IO, /* app direct IOs */ 913b0af6d49SChao Yu APP_BUFFERED_IO, /* app buffered IOs */ 914b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 915b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 916b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 917b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 918b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 919b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 920b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 921b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 922b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 923b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 924b0af6d49SChao Yu FS_DISCARD, /* discard */ 925b0af6d49SChao Yu NR_IO_TYPE, 926b0af6d49SChao Yu }; 927b0af6d49SChao Yu 928458e6197SJaegeuk Kim struct f2fs_io_info { 92905ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 93039d787beSChao Yu nid_t ino; /* inode number */ 931458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 932a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 93304d328deSMike Christie int op; /* contains REQ_OP_ */ 934ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 9357a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 93628bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 93705ca3632SJaegeuk Kim struct page *page; /* page to be written */ 9384375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 939fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 940d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 941cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 942fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 943b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 944458e6197SJaegeuk Kim }; 945458e6197SJaegeuk Kim 94668afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 9471ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 948458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 9491ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 9501ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 951458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 952df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 953fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 954fb830fc5SChao Yu struct list_head io_list; /* track fios */ 9551ff7bd3bSJaegeuk Kim }; 9561ff7bd3bSJaegeuk Kim 9573c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 9583c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 9593c62be17SJaegeuk Kim struct f2fs_dev_info { 9603c62be17SJaegeuk Kim struct block_device *bdev; 9613c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 9623c62be17SJaegeuk Kim unsigned int total_segments; 9633c62be17SJaegeuk Kim block_t start_blk; 9643c62be17SJaegeuk Kim block_t end_blk; 9653c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 9663c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 9673c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 9683c62be17SJaegeuk Kim #endif 9693c62be17SJaegeuk Kim }; 9703c62be17SJaegeuk Kim 971c227f912SChao Yu enum inode_type { 972c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 973c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 9740f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 97557864ae5SJaegeuk Kim ATOMIC_FILE, /* for all atomic files */ 976c227f912SChao Yu NR_INODE_TYPE, 977c227f912SChao Yu }; 978c227f912SChao Yu 97967298804SChao Yu /* for inner inode cache management */ 98067298804SChao Yu struct inode_management { 98167298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 98267298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 98367298804SChao Yu struct list_head ino_list; /* inode list head */ 98467298804SChao Yu unsigned long ino_num; /* number of entries */ 98567298804SChao Yu }; 98667298804SChao Yu 987caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 988caf0047eSChao Yu enum { 989caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 990caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 991caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 992caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 993df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 994bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 995caf0047eSChao Yu }; 996caf0047eSChao Yu 9976beceb54SJaegeuk Kim enum { 9986beceb54SJaegeuk Kim CP_TIME, 999d0239e1bSJaegeuk Kim REQ_TIME, 10006beceb54SJaegeuk Kim MAX_TIME, 10016beceb54SJaegeuk Kim }; 10026beceb54SJaegeuk Kim 100339a53e0cSJaegeuk Kim struct f2fs_sb_info { 100439a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 10055e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 100639a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 1007e8240f65SChao Yu int valid_super_block; /* valid super block no */ 1008fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 100939a53e0cSJaegeuk Kim 1010178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 1011178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1012178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 1013178053e2SDamien Le Moal #endif 1014178053e2SDamien Le Moal 101539a53e0cSJaegeuk Kim /* for node-related operations */ 101639a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 101739a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 101839a53e0cSJaegeuk Kim 101939a53e0cSJaegeuk Kim /* for segment-related operations */ 102039a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 10211ff7bd3bSJaegeuk Kim 10221ff7bd3bSJaegeuk Kim /* for bio operations */ 1023a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1024e41e6d75SChao Yu struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 1025e41e6d75SChao Yu /* bio ordering for NODE/DATA */ 10260a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 10270a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 102839a53e0cSJaegeuk Kim 102939a53e0cSJaegeuk Kim /* for checkpoint */ 103039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 10318508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1032aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 103339a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 103439936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 1035b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1036b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 103759c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1038fb51b5efSChangman Lee wait_queue_head_t cp_wait; 10396beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 10406beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 104139a53e0cSJaegeuk Kim 104267298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 10436451e041SJaegeuk Kim 10446451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 10450d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 104639a53e0cSJaegeuk Kim 1047c227f912SChao Yu /* for inode management */ 1048c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1049c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 105039a53e0cSJaegeuk Kim 105113054c54SChao Yu /* for extent tree cache */ 105213054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 10535e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 105413054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 105513054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 10567441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1057137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 105874fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 105913054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 106013054c54SChao Yu 106139a53e0cSJaegeuk Kim /* basic filesystem units */ 106239a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 106339a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 106439a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 106539a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 106639a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 106739a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 106839a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 106939a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 107039a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 107139a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 107239a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 107339a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 107439a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1075e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 107639a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 1077ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 1078*6afc662eSChao Yu int inline_xattr_size; /* inline xattr size */ 107939a53e0cSJaegeuk Kim 108039a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 108139a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1082a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 108339a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1084daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 1085daeb433eSChao Yu 108639a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 1087523be8a6SJaegeuk Kim 1088523be8a6SJaegeuk Kim /* # of pages, see count_type */ 108935782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 109041382ec4SJaegeuk Kim /* # of allocated blocks */ 109141382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 109239a53e0cSJaegeuk Kim 1093687de7f1SJaegeuk Kim /* writeback control */ 1094687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 1095687de7f1SJaegeuk Kim 1096513c5f37SJaegeuk Kim /* valid inode count */ 1097513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1098513c5f37SJaegeuk Kim 109939a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 110039a53e0cSJaegeuk Kim 110139a53e0cSJaegeuk Kim /* for cleaning operations */ 110239a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 110339a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 11045ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 110539a53e0cSJaegeuk Kim 1106e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 1107e93b9865SHou Pengyang u64 fggc_threshold; 1108e93b9865SHou Pengyang 1109b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1110b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1111b1c57c1cSJaegeuk Kim 111239a53e0cSJaegeuk Kim /* 111339a53e0cSJaegeuk Kim * for stat information. 111439a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 111539a53e0cSJaegeuk Kim */ 111635b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 111739a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 111839a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 111939a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1120b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 11215b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 11225b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 11235b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 11245b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1125d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 112603e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 112703e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 112826a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 1129648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 113026a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1131648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 113239a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 113333fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 113435b09d82SNamjae Jeon #endif 113539a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1136b59d0baeSNamjae Jeon 1137b0af6d49SChao Yu /* For app/fs IO statistics */ 1138b0af6d49SChao Yu spinlock_t iostat_lock; 1139b0af6d49SChao Yu unsigned long long write_iostat[NR_IO_TYPE]; 1140b0af6d49SChao Yu bool iostat_enable; 1141b0af6d49SChao Yu 1142b59d0baeSNamjae Jeon /* For sysfs suppport */ 1143b59d0baeSNamjae Jeon struct kobject s_kobj; 1144b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 11452658e50dSJaegeuk Kim 11462658e50dSJaegeuk Kim /* For shrinker support */ 11472658e50dSJaegeuk Kim struct list_head s_list; 11483c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 11493c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 11501228b482SChao Yu unsigned int dirty_device; /* for checkpoint data flush */ 11511228b482SChao Yu spinlock_t dev_lock; /* protect dirty_device */ 11522658e50dSJaegeuk Kim struct mutex umount_mutex; 11532658e50dSJaegeuk Kim unsigned int shrinker_run_no; 11548f1dbbbbSShuoran Liu 11558f1dbbbbSShuoran Liu /* For write statistics */ 11568f1dbbbbSShuoran Liu u64 sectors_written_start; 11578f1dbbbbSShuoran Liu u64 kbytes_written; 115843b6573bSKeith Mok 115943b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 116043b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 11611ecc0c5cSChao Yu 1162704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1163704956ecSChao Yu __u32 s_chksum_seed; 1164704956ecSChao Yu 11651ecc0c5cSChao Yu /* For fault injection */ 11661ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 11671ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 11681ecc0c5cSChao Yu #endif 11694b2414d0SChao Yu 11704b2414d0SChao Yu #ifdef CONFIG_QUOTA 11714b2414d0SChao Yu /* Names of quota files with journalled quota */ 11724b2414d0SChao Yu char *s_qf_names[MAXQUOTAS]; 11734b2414d0SChao Yu int s_jquota_fmt; /* Format of quota to use */ 11744b2414d0SChao Yu #endif 117539a53e0cSJaegeuk Kim }; 117639a53e0cSJaegeuk Kim 11771ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 117855523519SChao Yu #define f2fs_show_injection_info(type) \ 117955523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 118055523519SChao Yu KERN_INFO, fault_name[type], \ 118155523519SChao Yu __func__, __builtin_return_address(0)) 11821ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 11831ecc0c5cSChao Yu { 11841ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 11851ecc0c5cSChao Yu 11861ecc0c5cSChao Yu if (!ffi->inject_rate) 11871ecc0c5cSChao Yu return false; 11881ecc0c5cSChao Yu 11891ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 11901ecc0c5cSChao Yu return false; 11911ecc0c5cSChao Yu 11921ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 11931ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 11941ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 11951ecc0c5cSChao Yu return true; 11961ecc0c5cSChao Yu } 11971ecc0c5cSChao Yu return false; 11981ecc0c5cSChao Yu } 11991ecc0c5cSChao Yu #endif 12001ecc0c5cSChao Yu 12018f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 12028f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 12038f1dbbbbSShuoran Liu */ 12048f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 120568afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 120668afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 12078f1dbbbbSShuoran Liu 12086beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 12096beceb54SJaegeuk Kim { 12106beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 12116beceb54SJaegeuk Kim } 12126beceb54SJaegeuk Kim 12136beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 12146beceb54SJaegeuk Kim { 12156bccfa19SArnd Bergmann unsigned long interval = sbi->interval_time[type] * HZ; 12166beceb54SJaegeuk Kim 12176beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 12186beceb54SJaegeuk Kim } 12196beceb54SJaegeuk Kim 1220d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1221d0239e1bSJaegeuk Kim { 1222d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1223d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1224d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1225d0239e1bSJaegeuk Kim 1226d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1227d0239e1bSJaegeuk Kim return 0; 1228d0239e1bSJaegeuk Kim 1229d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1230d0239e1bSJaegeuk Kim } 1231d0239e1bSJaegeuk Kim 123239a53e0cSJaegeuk Kim /* 123339a53e0cSJaegeuk Kim * Inline functions 123439a53e0cSJaegeuk Kim */ 123543b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 123643b6573bSKeith Mok unsigned int length) 123743b6573bSKeith Mok { 123843b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 123943b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 1240d41519a6SDavid Miller u32 retval; 124143b6573bSKeith Mok int err; 124243b6573bSKeith Mok 124343b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 124443b6573bSKeith Mok shash->flags = 0; 124543b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 124643b6573bSKeith Mok 124743b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 124843b6573bSKeith Mok BUG_ON(err); 124943b6573bSKeith Mok 1250d41519a6SDavid Miller retval = *ctx; 1251d41519a6SDavid Miller barrier_data(ctx); 1252d41519a6SDavid Miller return retval; 125343b6573bSKeith Mok } 125443b6573bSKeith Mok 125543b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 125643b6573bSKeith Mok void *buf, size_t buf_size) 125743b6573bSKeith Mok { 125843b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 125943b6573bSKeith Mok } 126043b6573bSKeith Mok 1261704956ecSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1262704956ecSChao Yu const void *address, unsigned int length) 1263704956ecSChao Yu { 1264704956ecSChao Yu struct { 1265704956ecSChao Yu struct shash_desc shash; 1266704956ecSChao Yu char ctx[4]; 1267704956ecSChao Yu } desc; 1268704956ecSChao Yu int err; 1269704956ecSChao Yu 1270704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1271704956ecSChao Yu 1272704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1273704956ecSChao Yu desc.shash.flags = 0; 1274704956ecSChao Yu *(u32 *)desc.ctx = crc; 1275704956ecSChao Yu 1276704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1277704956ecSChao Yu BUG_ON(err); 1278704956ecSChao Yu 1279704956ecSChao Yu return *(u32 *)desc.ctx; 1280704956ecSChao Yu } 1281704956ecSChao Yu 128239a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 128339a53e0cSJaegeuk Kim { 128439a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 128539a53e0cSJaegeuk Kim } 128639a53e0cSJaegeuk Kim 128739a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 128839a53e0cSJaegeuk Kim { 128939a53e0cSJaegeuk Kim return sb->s_fs_info; 129039a53e0cSJaegeuk Kim } 129139a53e0cSJaegeuk Kim 12924081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 12934081363fSJaegeuk Kim { 12944081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 12954081363fSJaegeuk Kim } 12964081363fSJaegeuk Kim 12974081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 12984081363fSJaegeuk Kim { 12994081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 13004081363fSJaegeuk Kim } 13014081363fSJaegeuk Kim 13024081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 13034081363fSJaegeuk Kim { 13044081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 13054081363fSJaegeuk Kim } 13064081363fSJaegeuk Kim 130739a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 130839a53e0cSJaegeuk Kim { 130939a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 131039a53e0cSJaegeuk Kim } 131139a53e0cSJaegeuk Kim 131239a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 131339a53e0cSJaegeuk Kim { 131439a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 131539a53e0cSJaegeuk Kim } 131639a53e0cSJaegeuk Kim 131745590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 131845590710SGu Zheng { 131945590710SGu Zheng return (struct f2fs_node *)page_address(page); 132045590710SGu Zheng } 132145590710SGu Zheng 132258bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 132358bfaf44SJaegeuk Kim { 132458bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 132558bfaf44SJaegeuk Kim } 132658bfaf44SJaegeuk Kim 132739a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 132839a53e0cSJaegeuk Kim { 132939a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 133039a53e0cSJaegeuk Kim } 133139a53e0cSJaegeuk Kim 133239a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 133339a53e0cSJaegeuk Kim { 133439a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 133539a53e0cSJaegeuk Kim } 133639a53e0cSJaegeuk Kim 133739a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 133839a53e0cSJaegeuk Kim { 133939a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 134039a53e0cSJaegeuk Kim } 134139a53e0cSJaegeuk Kim 134239a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 134339a53e0cSJaegeuk Kim { 134439a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 134539a53e0cSJaegeuk Kim } 134639a53e0cSJaegeuk Kim 134739a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 134839a53e0cSJaegeuk Kim { 134939a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 135039a53e0cSJaegeuk Kim } 135139a53e0cSJaegeuk Kim 13529df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 13539df27d98SGu Zheng { 13549df27d98SGu Zheng return sbi->meta_inode->i_mapping; 13559df27d98SGu Zheng } 13569df27d98SGu Zheng 13574ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 13584ef51a8fSJaegeuk Kim { 13594ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 13604ef51a8fSJaegeuk Kim } 13614ef51a8fSJaegeuk Kim 1362caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 136339a53e0cSJaegeuk Kim { 1364fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 136539a53e0cSJaegeuk Kim } 136639a53e0cSJaegeuk Kim 1367caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 136839a53e0cSJaegeuk Kim { 1369fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1370caf0047eSChao Yu } 1371caf0047eSChao Yu 1372caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1373caf0047eSChao Yu { 1374fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 137539a53e0cSJaegeuk Kim } 137639a53e0cSJaegeuk Kim 1377d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1378d71b5564SJaegeuk Kim { 1379d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1380d71b5564SJaegeuk Kim } 1381d71b5564SJaegeuk Kim 1382ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1383ced2c7eaSKinglong Mee { 1384ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1385ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1386ced2c7eaSKinglong Mee } 1387ced2c7eaSKinglong Mee 1388aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 138925ca923bSJaegeuk Kim { 139025ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1391aaec2b1dSChao Yu 139225ca923bSJaegeuk Kim return ckpt_flags & f; 139325ca923bSJaegeuk Kim } 139425ca923bSJaegeuk Kim 1395aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 139625ca923bSJaegeuk Kim { 1397aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1398aaec2b1dSChao Yu } 1399aaec2b1dSChao Yu 1400aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1401aaec2b1dSChao Yu { 1402aaec2b1dSChao Yu unsigned int ckpt_flags; 1403aaec2b1dSChao Yu 1404aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 140525ca923bSJaegeuk Kim ckpt_flags |= f; 140625ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 140725ca923bSJaegeuk Kim } 140825ca923bSJaegeuk Kim 1409aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 141025ca923bSJaegeuk Kim { 1411d1aa2453SChao Yu unsigned long flags; 1412d1aa2453SChao Yu 1413d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1414aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1415d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1416aaec2b1dSChao Yu } 1417aaec2b1dSChao Yu 1418aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1419aaec2b1dSChao Yu { 1420aaec2b1dSChao Yu unsigned int ckpt_flags; 1421aaec2b1dSChao Yu 1422aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 142325ca923bSJaegeuk Kim ckpt_flags &= (~f); 142425ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 142525ca923bSJaegeuk Kim } 142625ca923bSJaegeuk Kim 1427aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1428aaec2b1dSChao Yu { 1429d1aa2453SChao Yu unsigned long flags; 1430d1aa2453SChao Yu 1431d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1432aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1433d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1434aaec2b1dSChao Yu } 1435aaec2b1dSChao Yu 143622ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 143722ad0b6aSJaegeuk Kim { 1438d1aa2453SChao Yu unsigned long flags; 1439d1aa2453SChao Yu 144022ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 144122ad0b6aSJaegeuk Kim 144222ad0b6aSJaegeuk Kim if (lock) 1443d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 144422ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 144522ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 144622ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 144722ad0b6aSJaegeuk Kim if (lock) 1448d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 144922ad0b6aSJaegeuk Kim } 145022ad0b6aSJaegeuk Kim 145122ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 145222ad0b6aSJaegeuk Kim struct cp_control *cpc) 145322ad0b6aSJaegeuk Kim { 145422ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 145522ad0b6aSJaegeuk Kim 1456c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 145722ad0b6aSJaegeuk Kim } 145822ad0b6aSJaegeuk Kim 1459e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 146039a53e0cSJaegeuk Kim { 1461b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 146239a53e0cSJaegeuk Kim } 146339a53e0cSJaegeuk Kim 1464cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1465cc15620bSJaegeuk Kim { 1466cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1467cc15620bSJaegeuk Kim } 1468cc15620bSJaegeuk Kim 1469e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 147039a53e0cSJaegeuk Kim { 1471b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 147239936837SJaegeuk Kim } 147339936837SJaegeuk Kim 1474e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 147539936837SJaegeuk Kim { 1476b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 147739936837SJaegeuk Kim } 147839936837SJaegeuk Kim 1479e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 148039936837SJaegeuk Kim { 1481b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 148239a53e0cSJaegeuk Kim } 148339a53e0cSJaegeuk Kim 1484119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1485119ee914SJaegeuk Kim { 1486119ee914SJaegeuk Kim int reason = CP_SYNC; 1487119ee914SJaegeuk Kim 1488119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1489119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1490119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1491119ee914SJaegeuk Kim reason = CP_UMOUNT; 1492119ee914SJaegeuk Kim return reason; 1493119ee914SJaegeuk Kim } 1494119ee914SJaegeuk Kim 1495119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1496119ee914SJaegeuk Kim { 1497c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1498119ee914SJaegeuk Kim } 1499119ee914SJaegeuk Kim 1500119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1501119ee914SJaegeuk Kim { 1502aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1503aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1504119ee914SJaegeuk Kim } 1505119ee914SJaegeuk Kim 150639a53e0cSJaegeuk Kim /* 150739a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 150839a53e0cSJaegeuk Kim */ 1509064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 151039a53e0cSJaegeuk Kim { 1511d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1512d6b7d4b3SChao Yu return -EINVAL; 1513cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1514064e0823SNamjae Jeon return -EINVAL; 1515064e0823SNamjae Jeon return 0; 151639a53e0cSJaegeuk Kim } 151739a53e0cSJaegeuk Kim 151839a53e0cSJaegeuk Kim /* 151939a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 152039a53e0cSJaegeuk Kim */ 152139a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 152239a53e0cSJaegeuk Kim { 15230eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 15240eb0adadSChao Yu 1525000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 152639a53e0cSJaegeuk Kim } 152739a53e0cSJaegeuk Kim 15284bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 15294bc8e9bcSChao Yu { 15304bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 15314bc8e9bcSChao Yu } 15324bc8e9bcSChao Yu 15330abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 15340abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 153546008c6dSChao Yu struct inode *inode, blkcnt_t *count) 153639a53e0cSJaegeuk Kim { 15370abd675eSChao Yu blkcnt_t diff = 0, release = 0; 1538daeb433eSChao Yu block_t avail_user_block_count; 15390abd675eSChao Yu int ret; 15400abd675eSChao Yu 15410abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 15420abd675eSChao Yu if (ret) 15430abd675eSChao Yu return ret; 1544dd11a5dfSJaegeuk Kim 1545cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 154655523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 154755523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 15480abd675eSChao Yu release = *count; 15490abd675eSChao Yu goto enospc; 155055523519SChao Yu } 1551cb78942bSJaegeuk Kim #endif 1552dd11a5dfSJaegeuk Kim /* 1553dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1554dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1555dd11a5dfSJaegeuk Kim */ 1556dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1557cfb271d4SChao Yu 155839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 15592555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 1560daeb433eSChao Yu avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks; 1561daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1562daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 1563dd11a5dfSJaegeuk Kim *count -= diff; 15640abd675eSChao Yu release = diff; 1565daeb433eSChao Yu sbi->total_valid_block_count = avail_user_block_count; 156646008c6dSChao Yu if (!*count) { 156739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1568dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 15690abd675eSChao Yu goto enospc; 157039a53e0cSJaegeuk Kim } 157146008c6dSChao Yu } 157239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 157341382ec4SJaegeuk Kim 15740abd675eSChao Yu if (release) 15750abd675eSChao Yu dquot_release_reservation_block(inode, release); 15760abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 15770abd675eSChao Yu return 0; 15780abd675eSChao Yu 15790abd675eSChao Yu enospc: 15800abd675eSChao Yu dquot_release_reservation_block(inode, release); 15810abd675eSChao Yu return -ENOSPC; 158239a53e0cSJaegeuk Kim } 158339a53e0cSJaegeuk Kim 1584da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 158539a53e0cSJaegeuk Kim struct inode *inode, 15860eb0adadSChao Yu block_t count) 158739a53e0cSJaegeuk Kim { 15880eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 15890eb0adadSChao Yu 159039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 15919850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 15920eb0adadSChao Yu f2fs_bug_on(sbi, inode->i_blocks < sectors); 159339a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 159439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 15950abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 159639a53e0cSJaegeuk Kim } 159739a53e0cSJaegeuk Kim 159839a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 159939a53e0cSJaegeuk Kim { 160035782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 16017c4abcbeSChao Yu 160236951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 160336951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 16047c4abcbeSChao Yu return; 16057c4abcbeSChao Yu 1606caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 160739a53e0cSJaegeuk Kim } 160839a53e0cSJaegeuk Kim 1609a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 161039a53e0cSJaegeuk Kim { 1611204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1612c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1613c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 161439a53e0cSJaegeuk Kim } 161539a53e0cSJaegeuk Kim 161639a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 161739a53e0cSJaegeuk Kim { 161835782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 161939a53e0cSJaegeuk Kim } 162039a53e0cSJaegeuk Kim 1621a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 162239a53e0cSJaegeuk Kim { 16235ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 16245ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 16251fe54f9dSJaegeuk Kim return; 16261fe54f9dSJaegeuk Kim 1627204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1628c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1629c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 163039a53e0cSJaegeuk Kim } 163139a53e0cSJaegeuk Kim 1632523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 163339a53e0cSJaegeuk Kim { 163435782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 163539a53e0cSJaegeuk Kim } 163639a53e0cSJaegeuk Kim 1637204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1638f8b2c1f9SJaegeuk Kim { 1639204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1640f8b2c1f9SJaegeuk Kim } 1641f8b2c1f9SJaegeuk Kim 16425ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 16435ac206cfSNamjae Jeon { 16443519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1645523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1646523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1647523be8a6SJaegeuk Kim 1648523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 16495ac206cfSNamjae Jeon } 16505ac206cfSNamjae Jeon 165139a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 165239a53e0cSJaegeuk Kim { 16538b8343faSJaegeuk Kim return sbi->total_valid_block_count; 165439a53e0cSJaegeuk Kim } 165539a53e0cSJaegeuk Kim 1656f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1657f83a2584SYunlei He { 1658f83a2584SYunlei He return sbi->discard_blks; 1659f83a2584SYunlei He } 1660f83a2584SYunlei He 166139a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 166239a53e0cSJaegeuk Kim { 166339a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 166439a53e0cSJaegeuk Kim 166539a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 166639a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 166739a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 166839a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 166939a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 167039a53e0cSJaegeuk Kim 167139a53e0cSJaegeuk Kim return 0; 167239a53e0cSJaegeuk Kim } 167339a53e0cSJaegeuk Kim 167455141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 167555141486SWanpeng Li { 167655141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 167755141486SWanpeng Li } 167855141486SWanpeng Li 167939a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 168039a53e0cSJaegeuk Kim { 168139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 16821dbe4152SChangman Lee int offset; 16831dbe4152SChangman Lee 168455141486SWanpeng Li if (__cp_payload(sbi) > 0) { 16851dbe4152SChangman Lee if (flag == NAT_BITMAP) 16861dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 16871dbe4152SChangman Lee else 168865b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 16891dbe4152SChangman Lee } else { 16901dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 169125ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 169239a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 169339a53e0cSJaegeuk Kim } 16941dbe4152SChangman Lee } 169539a53e0cSJaegeuk Kim 169639a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 169739a53e0cSJaegeuk Kim { 16988508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 169939a53e0cSJaegeuk Kim 17008508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 170139a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 170239a53e0cSJaegeuk Kim return start_addr; 170339a53e0cSJaegeuk Kim } 170439a53e0cSJaegeuk Kim 17058508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 17068508e44aSJaegeuk Kim { 17078508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 17088508e44aSJaegeuk Kim 17098508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 17108508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 17118508e44aSJaegeuk Kim return start_addr; 17128508e44aSJaegeuk Kim } 17138508e44aSJaegeuk Kim 17148508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 17158508e44aSJaegeuk Kim { 17168508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 17178508e44aSJaegeuk Kim } 17188508e44aSJaegeuk Kim 171939a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 172039a53e0cSJaegeuk Kim { 172139a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 172239a53e0cSJaegeuk Kim } 172339a53e0cSJaegeuk Kim 17240abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 1725000519f2SChao Yu struct inode *inode, bool is_inode) 172639a53e0cSJaegeuk Kim { 172739a53e0cSJaegeuk Kim block_t valid_block_count; 172839a53e0cSJaegeuk Kim unsigned int valid_node_count; 17290abd675eSChao Yu bool quota = inode && !is_inode; 17300abd675eSChao Yu 17310abd675eSChao Yu if (quota) { 17320abd675eSChao Yu int ret = dquot_reserve_block(inode, 1); 17330abd675eSChao Yu if (ret) 17340abd675eSChao Yu return ret; 17350abd675eSChao Yu } 173639a53e0cSJaegeuk Kim 173739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 173839a53e0cSJaegeuk Kim 1739ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1740daeb433eSChao Yu if (unlikely(valid_block_count + sbi->reserved_blocks > 1741daeb433eSChao Yu sbi->user_block_count)) { 174239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17430abd675eSChao Yu goto enospc; 174439a53e0cSJaegeuk Kim } 174539a53e0cSJaegeuk Kim 1746ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1747cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 174839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17490abd675eSChao Yu goto enospc; 175039a53e0cSJaegeuk Kim } 175139a53e0cSJaegeuk Kim 1752ef86d709SGu Zheng sbi->total_valid_node_count++; 1753ef86d709SGu Zheng sbi->total_valid_block_count++; 175439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 175539a53e0cSJaegeuk Kim 17560abd675eSChao Yu if (inode) { 17570abd675eSChao Yu if (is_inode) 17580abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 17590abd675eSChao Yu else 17600abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 17610abd675eSChao Yu } 17620abd675eSChao Yu 176341382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 17640abd675eSChao Yu return 0; 17650abd675eSChao Yu 17660abd675eSChao Yu enospc: 17670abd675eSChao Yu if (quota) 17680abd675eSChao Yu dquot_release_reservation_block(inode, 1); 17690abd675eSChao Yu return -ENOSPC; 177039a53e0cSJaegeuk Kim } 177139a53e0cSJaegeuk Kim 177239a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1773000519f2SChao Yu struct inode *inode, bool is_inode) 177439a53e0cSJaegeuk Kim { 177539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 177639a53e0cSJaegeuk Kim 17779850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 17789850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 1779000519f2SChao Yu f2fs_bug_on(sbi, !is_inode && !inode->i_blocks); 178039a53e0cSJaegeuk Kim 1781ef86d709SGu Zheng sbi->total_valid_node_count--; 1782ef86d709SGu Zheng sbi->total_valid_block_count--; 178339a53e0cSJaegeuk Kim 178439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17850abd675eSChao Yu 17860abd675eSChao Yu if (!is_inode) 17870abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 178839a53e0cSJaegeuk Kim } 178939a53e0cSJaegeuk Kim 179039a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 179139a53e0cSJaegeuk Kim { 17928b8343faSJaegeuk Kim return sbi->total_valid_node_count; 179339a53e0cSJaegeuk Kim } 179439a53e0cSJaegeuk Kim 179539a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 179639a53e0cSJaegeuk Kim { 1797513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 179839a53e0cSJaegeuk Kim } 179939a53e0cSJaegeuk Kim 18000e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 180139a53e0cSJaegeuk Kim { 1802513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 180339a53e0cSJaegeuk Kim } 180439a53e0cSJaegeuk Kim 1805513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 180639a53e0cSJaegeuk Kim { 1807513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 180839a53e0cSJaegeuk Kim } 180939a53e0cSJaegeuk Kim 1810a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1811a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1812a56c7c6fSJaegeuk Kim { 1813c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1814c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1815cac5a3d8SDongOh Shin 1816c41f3cc3SJaegeuk Kim if (page) 1817c41f3cc3SJaegeuk Kim return page; 1818c41f3cc3SJaegeuk Kim 181955523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 182055523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1821c41f3cc3SJaegeuk Kim return NULL; 182255523519SChao Yu } 1823c41f3cc3SJaegeuk Kim #endif 1824a56c7c6fSJaegeuk Kim if (!for_write) 1825a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1826a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1827a56c7c6fSJaegeuk Kim } 1828a56c7c6fSJaegeuk Kim 18296e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 18306e2c64adSJaegeuk Kim { 18316e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 18326e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 18336e2c64adSJaegeuk Kim 18346e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 18356e2c64adSJaegeuk Kim kunmap(dst); 18366e2c64adSJaegeuk Kim kunmap(src); 18376e2c64adSJaegeuk Kim } 18386e2c64adSJaegeuk Kim 183939a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 184039a53e0cSJaegeuk Kim { 1841031fa8ccSJaegeuk Kim if (!page) 184239a53e0cSJaegeuk Kim return; 184339a53e0cSJaegeuk Kim 184439a53e0cSJaegeuk Kim if (unlock) { 18459850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 184639a53e0cSJaegeuk Kim unlock_page(page); 184739a53e0cSJaegeuk Kim } 184809cbfeafSKirill A. Shutemov put_page(page); 184939a53e0cSJaegeuk Kim } 185039a53e0cSJaegeuk Kim 185139a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 185239a53e0cSJaegeuk Kim { 185339a53e0cSJaegeuk Kim if (dn->node_page) 185439a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 185539a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 185639a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 185739a53e0cSJaegeuk Kim dn->node_page = NULL; 185839a53e0cSJaegeuk Kim dn->inode_page = NULL; 185939a53e0cSJaegeuk Kim } 186039a53e0cSJaegeuk Kim 186139a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1862e8512d2eSGu Zheng size_t size) 186339a53e0cSJaegeuk Kim { 1864e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 186539a53e0cSJaegeuk Kim } 186639a53e0cSJaegeuk Kim 18677bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 18687bd59381SGu Zheng gfp_t flags) 18697bd59381SGu Zheng { 18707bd59381SGu Zheng void *entry; 18717bd59381SGu Zheng 187280c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 187380c54505SJaegeuk Kim if (!entry) 187480c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 18757bd59381SGu Zheng return entry; 18767bd59381SGu Zheng } 18777bd59381SGu Zheng 1878740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1879740432f8SJaegeuk Kim { 1880740432f8SJaegeuk Kim struct bio *bio; 1881740432f8SJaegeuk Kim 1882740432f8SJaegeuk Kim /* No failure on bio allocation */ 1883740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 188480c54505SJaegeuk Kim if (!bio) 188580c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1886740432f8SJaegeuk Kim return bio; 1887740432f8SJaegeuk Kim } 1888740432f8SJaegeuk Kim 18899be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 18909be32d72SJaegeuk Kim unsigned long index, void *item) 18919be32d72SJaegeuk Kim { 18929be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 18939be32d72SJaegeuk Kim cond_resched(); 18949be32d72SJaegeuk Kim } 18959be32d72SJaegeuk Kim 189639a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 189739a53e0cSJaegeuk Kim 189839a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 189939a53e0cSJaegeuk Kim { 190045590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1901cac5a3d8SDongOh Shin 190239a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 190339a53e0cSJaegeuk Kim } 190439a53e0cSJaegeuk Kim 19057a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 19067a2af766SChao Yu { 19077a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 19087a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 19097a2af766SChao Yu } 19107a2af766SChao Yu 191139a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 191239a53e0cSJaegeuk Kim { 191339a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 191439a53e0cSJaegeuk Kim } 191539a53e0cSJaegeuk Kim 19167a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 19177a2af766SChao Yu static inline block_t datablock_addr(struct inode *inode, 19187a2af766SChao Yu struct page *node_page, unsigned int offset) 191939a53e0cSJaegeuk Kim { 192039a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 192139a53e0cSJaegeuk Kim __le32 *addr_array; 19227a2af766SChao Yu int base = 0; 19237a2af766SChao Yu bool is_inode = IS_INODE(node_page); 1924cac5a3d8SDongOh Shin 192545590710SGu Zheng raw_node = F2FS_NODE(node_page); 19267a2af766SChao Yu 19277a2af766SChao Yu /* from GC path only */ 19287a2af766SChao Yu if (!inode) { 19297a2af766SChao Yu if (is_inode) 19307a2af766SChao Yu base = offset_in_addr(&raw_node->i); 19317a2af766SChao Yu } else if (f2fs_has_extra_attr(inode) && is_inode) { 19327a2af766SChao Yu base = get_extra_isize(inode); 19337a2af766SChao Yu } 19347a2af766SChao Yu 193539a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 19367a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 193739a53e0cSJaegeuk Kim } 193839a53e0cSJaegeuk Kim 193939a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 194039a53e0cSJaegeuk Kim { 194139a53e0cSJaegeuk Kim int mask; 194239a53e0cSJaegeuk Kim 194339a53e0cSJaegeuk Kim addr += (nr >> 3); 194439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 194539a53e0cSJaegeuk Kim return mask & *addr; 194639a53e0cSJaegeuk Kim } 194739a53e0cSJaegeuk Kim 1948a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1949a66cdd98SJaegeuk Kim { 1950a66cdd98SJaegeuk Kim int mask; 1951a66cdd98SJaegeuk Kim 1952a66cdd98SJaegeuk Kim addr += (nr >> 3); 1953a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1954a66cdd98SJaegeuk Kim *addr |= mask; 1955a66cdd98SJaegeuk Kim } 1956a66cdd98SJaegeuk Kim 1957a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1958a66cdd98SJaegeuk Kim { 1959a66cdd98SJaegeuk Kim int mask; 1960a66cdd98SJaegeuk Kim 1961a66cdd98SJaegeuk Kim addr += (nr >> 3); 1962a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1963a66cdd98SJaegeuk Kim *addr &= ~mask; 1964a66cdd98SJaegeuk Kim } 1965a66cdd98SJaegeuk Kim 196652aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 196739a53e0cSJaegeuk Kim { 196839a53e0cSJaegeuk Kim int mask; 196939a53e0cSJaegeuk Kim int ret; 197039a53e0cSJaegeuk Kim 197139a53e0cSJaegeuk Kim addr += (nr >> 3); 197239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 197339a53e0cSJaegeuk Kim ret = mask & *addr; 197439a53e0cSJaegeuk Kim *addr |= mask; 197539a53e0cSJaegeuk Kim return ret; 197639a53e0cSJaegeuk Kim } 197739a53e0cSJaegeuk Kim 197852aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 197939a53e0cSJaegeuk Kim { 198039a53e0cSJaegeuk Kim int mask; 198139a53e0cSJaegeuk Kim int ret; 198239a53e0cSJaegeuk Kim 198339a53e0cSJaegeuk Kim addr += (nr >> 3); 198439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 198539a53e0cSJaegeuk Kim ret = mask & *addr; 198639a53e0cSJaegeuk Kim *addr &= ~mask; 198739a53e0cSJaegeuk Kim return ret; 198839a53e0cSJaegeuk Kim } 198939a53e0cSJaegeuk Kim 1990c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1991c6ac4c0eSGu Zheng { 1992c6ac4c0eSGu Zheng int mask; 1993c6ac4c0eSGu Zheng 1994c6ac4c0eSGu Zheng addr += (nr >> 3); 1995c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1996c6ac4c0eSGu Zheng *addr ^= mask; 1997c6ac4c0eSGu Zheng } 1998c6ac4c0eSGu Zheng 19995c57132eSChao Yu #define F2FS_REG_FLMASK (~(FS_DIRSYNC_FL | FS_TOPDIR_FL)) 20005c57132eSChao Yu #define F2FS_OTHER_FLMASK (FS_NODUMP_FL | FS_NOATIME_FL) 20015c57132eSChao Yu #define F2FS_FL_INHERITED (FS_PROJINHERIT_FL) 20025c57132eSChao Yu 20035c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 20045c57132eSChao Yu { 20055c57132eSChao Yu if (S_ISDIR(mode)) 20065c57132eSChao Yu return flags; 20075c57132eSChao Yu else if (S_ISREG(mode)) 20085c57132eSChao Yu return flags & F2FS_REG_FLMASK; 20095c57132eSChao Yu else 20105c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 20115c57132eSChao Yu } 20125c57132eSChao Yu 201339a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 201439a53e0cSJaegeuk Kim enum { 201539a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 2016b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 201726de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 2018ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 201939a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 202039a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 202139a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 2022c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 2023c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 2024444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 20251001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 202634d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 2027fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 2028fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 202988b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 203088b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 20315fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 203202a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 20333c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 20341e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 2035b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 2036510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 2037d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 2038c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 2039dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 2040ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 20417a2af766SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 20425c57132eSChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 204339a53e0cSJaegeuk Kim }; 204439a53e0cSJaegeuk Kim 2045205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2046205b9822SJaegeuk Kim int flag, bool set) 204739a53e0cSJaegeuk Kim { 2048205b9822SJaegeuk Kim switch (flag) { 2049205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2050205b9822SJaegeuk Kim case FI_INLINE_DATA: 2051205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 2052205b9822SJaegeuk Kim if (set) 2053205b9822SJaegeuk Kim return; 2054205b9822SJaegeuk Kim case FI_DATA_EXIST: 2055205b9822SJaegeuk Kim case FI_INLINE_DOTS: 20567c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2057205b9822SJaegeuk Kim } 205839a53e0cSJaegeuk Kim } 205939a53e0cSJaegeuk Kim 206091942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 206139a53e0cSJaegeuk Kim { 206291942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 206391942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 2064205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 206539a53e0cSJaegeuk Kim } 206639a53e0cSJaegeuk Kim 206791942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 206839a53e0cSJaegeuk Kim { 206991942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 207039a53e0cSJaegeuk Kim } 207139a53e0cSJaegeuk Kim 207291942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 207339a53e0cSJaegeuk Kim { 207491942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 207591942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 2076205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 207739a53e0cSJaegeuk Kim } 207839a53e0cSJaegeuk Kim 207991942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2080444c580fSJaegeuk Kim { 208191942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 208291942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 20837c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 208439a53e0cSJaegeuk Kim } 208539a53e0cSJaegeuk Kim 2086a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2087a1961246SJaegeuk Kim { 2088a1961246SJaegeuk Kim if (inc) 2089a1961246SJaegeuk Kim inc_nlink(inode); 2090a1961246SJaegeuk Kim else 2091a1961246SJaegeuk Kim drop_nlink(inode); 20927c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2093a1961246SJaegeuk Kim } 2094a1961246SJaegeuk Kim 20958edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 20960abd675eSChao Yu block_t diff, bool add, bool claim) 20978edd03c8SJaegeuk Kim { 209826de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 209926de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 210026de9b11SJaegeuk Kim 21010abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 21020abd675eSChao Yu if (add) { 21030abd675eSChao Yu if (claim) 21040abd675eSChao Yu dquot_claim_block(inode, diff); 21050abd675eSChao Yu else 21060abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 21070abd675eSChao Yu } else { 21080abd675eSChao Yu dquot_free_block(inode, diff); 21090abd675eSChao Yu } 21100abd675eSChao Yu 21117c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 211226de9b11SJaegeuk Kim if (clean || recover) 211326de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 21148edd03c8SJaegeuk Kim } 21158edd03c8SJaegeuk Kim 2116fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2117fc9581c8SJaegeuk Kim { 211826de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 211926de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 212026de9b11SJaegeuk Kim 2121fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2122fc9581c8SJaegeuk Kim return; 2123fc9581c8SJaegeuk Kim 2124fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 21257c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 212626de9b11SJaegeuk Kim if (clean || recover) 212726de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 212826de9b11SJaegeuk Kim } 212926de9b11SJaegeuk Kim 2130205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2131205b9822SJaegeuk Kim { 2132205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 21337c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2134205b9822SJaegeuk Kim } 2135205b9822SJaegeuk Kim 2136205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2137205b9822SJaegeuk Kim { 2138205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 21397c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2140205b9822SJaegeuk Kim } 2141205b9822SJaegeuk Kim 2142205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2143205b9822SJaegeuk Kim { 2144205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 21457c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2146205b9822SJaegeuk Kim } 2147205b9822SJaegeuk Kim 214891942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2149444c580fSJaegeuk Kim { 2150205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2151205b9822SJaegeuk Kim 2152444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 2153205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 21541001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 2155205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 215634d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 2157205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 2158b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 2159205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 2160510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 2161205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 21627a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 21637a2af766SChao Yu set_bit(FI_EXTRA_ATTR, &fi->flags); 2164444c580fSJaegeuk Kim } 2165444c580fSJaegeuk Kim 216691942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2167444c580fSJaegeuk Kim { 2168444c580fSJaegeuk Kim ri->i_inline = 0; 2169444c580fSJaegeuk Kim 217091942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2171444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 217291942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 21731001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 217491942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 217534d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 217691942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2177b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 217891942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2179510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 21807a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 21817a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 21827a2af766SChao Yu } 21837a2af766SChao Yu 21847a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 21857a2af766SChao Yu { 21867a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2187444c580fSJaegeuk Kim } 2188444c580fSJaegeuk Kim 2189987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2190987c7c31SChao Yu { 219191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2192987c7c31SChao Yu } 2193987c7c31SChao Yu 219481ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2195de93653fSJaegeuk Kim { 2196*6afc662eSChao Yu return CUR_ADDRS_PER_INODE(inode) - F2FS_INLINE_XATTR_ADDRS(inode); 2197de93653fSJaegeuk Kim } 2198de93653fSJaegeuk Kim 2199*6afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page) 220065985d93SJaegeuk Kim { 2201695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2202cac5a3d8SDongOh Shin 220365985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 2204*6afc662eSChao Yu F2FS_INLINE_XATTR_ADDRS(inode)]); 220565985d93SJaegeuk Kim } 220665985d93SJaegeuk Kim 220765985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 220865985d93SJaegeuk Kim { 2209*6afc662eSChao Yu return get_inline_xattr_addrs(inode) * sizeof(__le32); 221065985d93SJaegeuk Kim } 221165985d93SJaegeuk Kim 22120dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 22130dbdc2aeSJaegeuk Kim { 221491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 22150dbdc2aeSJaegeuk Kim } 22160dbdc2aeSJaegeuk Kim 2217b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2218b3d208f9SJaegeuk Kim { 221991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2220b3d208f9SJaegeuk Kim } 2221b3d208f9SJaegeuk Kim 2222510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2223510022a8SJaegeuk Kim { 222491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2225510022a8SJaegeuk Kim } 2226510022a8SJaegeuk Kim 222788b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 222888b88a66SJaegeuk Kim { 222991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 223088b88a66SJaegeuk Kim } 223188b88a66SJaegeuk Kim 22325fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 22335fe45743SChao Yu { 22345fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 22355fe45743SChao Yu } 22365fe45743SChao Yu 223702a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 223802a1335fSJaegeuk Kim { 223991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 224002a1335fSJaegeuk Kim } 224102a1335fSJaegeuk Kim 22423c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 22433c6c2bebSJaegeuk Kim { 224491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 22453c6c2bebSJaegeuk Kim } 22463c6c2bebSJaegeuk Kim 22471e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 22481e84371fSJaegeuk Kim { 224991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 22501e84371fSJaegeuk Kim } 22511e84371fSJaegeuk Kim 2252f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 22531001b347SHuajun Li { 2254695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 22557a2af766SChao Yu int extra_size = get_extra_isize(inode); 2256cac5a3d8SDongOh Shin 22577a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 22581001b347SHuajun Li } 22591001b347SHuajun Li 226034d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 226134d67debSChao Yu { 226291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 226334d67debSChao Yu } 226434d67debSChao Yu 22659486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 22669486ba44SJaegeuk Kim { 22679486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 22689486ba44SJaegeuk Kim kunmap(page); 22699486ba44SJaegeuk Kim } 22709486ba44SJaegeuk Kim 2271b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2272b5492af7SJaegeuk Kim { 2273b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2274b5492af7SJaegeuk Kim } 2275b5492af7SJaegeuk Kim 2276b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2277b5492af7SJaegeuk Kim { 2278b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 22797c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2280b5492af7SJaegeuk Kim } 2281b5492af7SJaegeuk Kim 2282b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2283b5492af7SJaegeuk Kim { 2284b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 22857c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2286b5492af7SJaegeuk Kim } 2287b5492af7SJaegeuk Kim 228826787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 228926787236SJaegeuk Kim { 2290a0d00fadSChao Yu bool ret; 2291a0d00fadSChao Yu 229226787236SJaegeuk Kim if (dsync) { 229326787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 229426787236SJaegeuk Kim 229526787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 229626787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 229726787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 229826787236SJaegeuk Kim return ret; 229926787236SJaegeuk Kim } 230026787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 230126787236SJaegeuk Kim file_keep_isize(inode) || 230226787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 230326787236SJaegeuk Kim return false; 2304a0d00fadSChao Yu 2305a0d00fadSChao Yu down_read(&F2FS_I(inode)->i_sem); 2306a0d00fadSChao Yu ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 2307a0d00fadSChao Yu up_read(&F2FS_I(inode)->i_sem); 2308a0d00fadSChao Yu 2309a0d00fadSChao Yu return ret; 2310267378d4SChao Yu } 2311267378d4SChao Yu 2312267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 2313267378d4SChao Yu { 2314267378d4SChao Yu return sb->s_flags & MS_RDONLY; 2315267378d4SChao Yu } 231639a53e0cSJaegeuk Kim 231739a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 231839a53e0cSJaegeuk Kim { 2319aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 232039a53e0cSJaegeuk Kim } 232139a53e0cSJaegeuk Kim 2322eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2323eaa693f4SJaegeuk Kim { 2324eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2325eaa693f4SJaegeuk Kim return true; 2326eaa693f4SJaegeuk Kim 2327eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2328eaa693f4SJaegeuk Kim return true; 2329eaa693f4SJaegeuk Kim 2330eaa693f4SJaegeuk Kim return false; 2331eaa693f4SJaegeuk Kim } 2332eaa693f4SJaegeuk Kim 23333e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 23343e72f721SJaegeuk Kim { 23353e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 233691942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 23373e72f721SJaegeuk Kim return false; 23383e72f721SJaegeuk Kim 2339886f56f9SAl Viro return S_ISREG(inode->i_mode); 23403e72f721SJaegeuk Kim } 23413e72f721SJaegeuk Kim 23421ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 23431ecc0c5cSChao Yu size_t size, gfp_t flags) 23440414b004SJaegeuk Kim { 23452c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 234655523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 234755523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 23482c63feadSJaegeuk Kim return NULL; 234955523519SChao Yu } 23502c63feadSJaegeuk Kim #endif 23510414b004SJaegeuk Kim return kmalloc(size, flags); 23520414b004SJaegeuk Kim } 23530414b004SJaegeuk Kim 23547a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 2355f2470371SChao Yu { 23567a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 2357f2470371SChao Yu } 2358f2470371SChao Yu 2359*6afc662eSChao Yu static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb); 2360*6afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode) 2361*6afc662eSChao Yu { 2362*6afc662eSChao Yu return F2FS_I(inode)->i_inline_xattr_size; 2363*6afc662eSChao Yu } 2364*6afc662eSChao Yu 236539a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 236691942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 236739a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 236839a53e0cSJaegeuk Kim 23697a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 23707a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 23717a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 23727a2af766SChao Yu 23735c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 23745c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 23755c57132eSChao Yu ((offsetof(typeof(*f2fs_inode), field) + \ 23765c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 23775c57132eSChao Yu <= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize)) \ 23785c57132eSChao Yu 2379b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 2380b0af6d49SChao Yu { 2381b0af6d49SChao Yu int i; 2382b0af6d49SChao Yu 2383b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2384b0af6d49SChao Yu for (i = 0; i < NR_IO_TYPE; i++) 2385b0af6d49SChao Yu sbi->write_iostat[i] = 0; 2386b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2387b0af6d49SChao Yu } 2388b0af6d49SChao Yu 2389b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 2390b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 2391b0af6d49SChao Yu { 2392b0af6d49SChao Yu if (!sbi->iostat_enable) 2393b0af6d49SChao Yu return; 2394b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2395b0af6d49SChao Yu sbi->write_iostat[type] += io_bytes; 2396b0af6d49SChao Yu 2397b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 2398b0af6d49SChao Yu sbi->write_iostat[APP_BUFFERED_IO] = 2399b0af6d49SChao Yu sbi->write_iostat[APP_WRITE_IO] - 2400b0af6d49SChao Yu sbi->write_iostat[APP_DIRECT_IO]; 2401b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2402b0af6d49SChao Yu } 2403b0af6d49SChao Yu 240439a53e0cSJaegeuk Kim /* 240539a53e0cSJaegeuk Kim * file.c 240639a53e0cSJaegeuk Kim */ 2407cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2408cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2409cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2410cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2411a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2412a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2413cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2414cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2415cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2416cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2417cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 241839a53e0cSJaegeuk Kim 241939a53e0cSJaegeuk Kim /* 242039a53e0cSJaegeuk Kim * inode.c 242139a53e0cSJaegeuk Kim */ 2422cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2423704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 2424704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 2425cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2426cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2427cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2428cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2429cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2430cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2431cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2432cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 243339a53e0cSJaegeuk Kim 243439a53e0cSJaegeuk Kim /* 243539a53e0cSJaegeuk Kim * namei.c 243639a53e0cSJaegeuk Kim */ 243739a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 243839a53e0cSJaegeuk Kim 243939a53e0cSJaegeuk Kim /* 244039a53e0cSJaegeuk Kim * dir.c 244139a53e0cSJaegeuk Kim */ 2442cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2443cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2444cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2445cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2446cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2447cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2448cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2449cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2450cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2451cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2452cac5a3d8SDongOh Shin const struct qstr *new_name, 2453cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2454cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2455cac5a3d8SDongOh Shin unsigned int current_depth); 2456cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2457cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2458cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2459cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2460cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2461cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2462cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2463cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2464cac5a3d8SDongOh Shin struct page **page); 2465cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2466cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2467cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2468cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2469cac5a3d8SDongOh Shin unsigned int bit_pos); 2470cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2471cac5a3d8SDongOh Shin const struct qstr *orig_name, 2472cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2473cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2474cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2475cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2476cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2477cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2478cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2479cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2480cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 248139a53e0cSJaegeuk Kim 2482b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2483b7f7a5e0SAl Viro { 24842b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2485510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2486b7f7a5e0SAl Viro } 2487b7f7a5e0SAl Viro 248839a53e0cSJaegeuk Kim /* 248939a53e0cSJaegeuk Kim * super.c 249039a53e0cSJaegeuk Kim */ 2491cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2492cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 24934b2414d0SChao Yu void f2fs_enable_quota_files(struct f2fs_sb_info *sbi); 24944b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 2495cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2496cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2497a07ef784SNamjae Jeon extern __printf(3, 4) 2498cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2499984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 250039a53e0cSJaegeuk Kim 250139a53e0cSJaegeuk Kim /* 250239a53e0cSJaegeuk Kim * hash.c 250339a53e0cSJaegeuk Kim */ 25046332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, 25056332cd32SJaegeuk Kim struct fscrypt_name *fname); 250639a53e0cSJaegeuk Kim 250739a53e0cSJaegeuk Kim /* 250839a53e0cSJaegeuk Kim * node.c 250939a53e0cSJaegeuk Kim */ 251039a53e0cSJaegeuk Kim struct dnode_of_data; 251139a53e0cSJaegeuk Kim struct node_info; 251239a53e0cSJaegeuk Kim 2513cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2514cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2515cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2516cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2517cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2518cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2519cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2520cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 25219c77f754SJaegeuk Kim int truncate_xattr_node(struct inode *inode); 2522cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2523cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2524cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 25255f4ce6abSYunlei He struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs); 2526cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2527cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2528cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2529cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2530cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2531cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2532401db79fSYunlong Song int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc, 2533b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 253422ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2535cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2536cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2537cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2538cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2539cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2540d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2541cac5a3d8SDongOh Shin block_t blkaddr); 2542cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2543cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2544cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 254522ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2546cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2547cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 25486e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 254939a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 255039a53e0cSJaegeuk Kim 255139a53e0cSJaegeuk Kim /* 255239a53e0cSJaegeuk Kim * segment.c 255339a53e0cSJaegeuk Kim */ 2554b3a97a2aSJaegeuk Kim bool need_SSR(struct f2fs_sb_info *sbi); 2555cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 255657864ae5SJaegeuk Kim void drop_inmem_pages_all(struct f2fs_sb_info *sbi); 2557cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 25588c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2559cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2560cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2561cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 256239d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 2563cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 25641228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); 2565cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2566cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2567cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 256878997b56SChao Yu void init_discard_policy(struct discard_policy *dpolicy, int discard_type, 256978997b56SChao Yu unsigned int granularity); 2570cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2571cce13252SChao Yu void stop_discard_thread(struct f2fs_sb_info *sbi); 2572cf5c759fSChao Yu bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2573cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2574cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2575cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2576cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2577cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2578cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2579cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2580cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2581b0af6d49SChao Yu void write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 2582b0af6d49SChao Yu enum iostat_type io_type); 2583cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2584cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2585d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2586cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2587cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2588cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2589cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2590cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2591cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2592cac5a3d8SDongOh Shin bool recover_newaddr); 2593cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2594cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2595fb830fc5SChao Yu struct f2fs_summary *sum, int type, 2596fb830fc5SChao Yu struct f2fs_io_info *fio, bool add_list); 2597cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2598cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2599d4c759eeSJaegeuk Kim void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr); 2600cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2601cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2602cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2603cac5a3d8SDongOh Shin unsigned int val, int alloc); 2604cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2605cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2606cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 26077fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 26087fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 260939a53e0cSJaegeuk Kim 261039a53e0cSJaegeuk Kim /* 261139a53e0cSJaegeuk Kim * checkpoint.c 261239a53e0cSJaegeuk Kim */ 2613cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2614cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2615cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2616cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2617cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2618cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2619cac5a3d8SDongOh Shin int type, bool sync); 2620cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2621cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2622b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 2623cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2624cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2625cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2626cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 262739d787beSChao Yu void set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 262839d787beSChao Yu unsigned int devidx, int type); 262939d787beSChao Yu bool is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 263039d787beSChao Yu unsigned int devidx, int type); 2631cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2632cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2633cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2634cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2635cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2636cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2637cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2638cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2639cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2640cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2641cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2642cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 26436e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 264439a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 264539a53e0cSJaegeuk Kim 264639a53e0cSJaegeuk Kim /* 264739a53e0cSJaegeuk Kim * data.c 264839a53e0cSJaegeuk Kim */ 2649b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 2650b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 2651942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2652b9109b0eSJaegeuk Kim enum page_type type); 2653b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 2654cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2655b9109b0eSJaegeuk Kim int f2fs_submit_page_write(struct f2fs_io_info *fio); 2656cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2657cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2658cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2659cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2660cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2661cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2662cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2663cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2664cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2665cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2666cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2667cac5a3d8SDongOh Shin int op_flags, bool for_write); 2668cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2669cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2670cac5a3d8SDongOh Shin bool for_write); 2671cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2672cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2673cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2674cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2675cac5a3d8SDongOh Shin int create, int flag); 2676cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2677cac5a3d8SDongOh Shin u64 start, u64 len); 2678cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2679b0af6d49SChao Yu int __f2fs_write_data_pages(struct address_space *mapping, 2680b0af6d49SChao Yu struct writeback_control *wbc, 2681b0af6d49SChao Yu enum iostat_type io_type); 2682cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2683cac5a3d8SDongOh Shin unsigned int length); 2684cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 26855b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2686cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2687cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 26885b7a487cSWeichao Guo #endif 268939a53e0cSJaegeuk Kim 269039a53e0cSJaegeuk Kim /* 269139a53e0cSJaegeuk Kim * gc.c 269239a53e0cSJaegeuk Kim */ 2693cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2694cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2695cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2696e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 2697e066b83cSJaegeuk Kim unsigned int segno); 2698cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 269939a53e0cSJaegeuk Kim 270039a53e0cSJaegeuk Kim /* 270139a53e0cSJaegeuk Kim * recovery.c 270239a53e0cSJaegeuk Kim */ 2703cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2704cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 270539a53e0cSJaegeuk Kim 270639a53e0cSJaegeuk Kim /* 270739a53e0cSJaegeuk Kim * debug.c 270839a53e0cSJaegeuk Kim */ 270939a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 271039a53e0cSJaegeuk Kim struct f2fs_stat_info { 271139a53e0cSJaegeuk Kim struct list_head stat_list; 271239a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 271339a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 271439a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 27155b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 27165b7ee374SChao Yu unsigned long long hit_total, total_ext; 2717c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 271835782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 271935782b23SJaegeuk Kim int inmem_pages; 27200f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 27215b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 27225b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 272339a53e0cSJaegeuk Kim int total_count, utilization; 27248b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 272514d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 272614d8d5f7SChao Yu int nr_discarding, nr_discarded; 27275f32366aSChao Yu int nr_discard_cmd; 2728d84d1cbdSChao Yu unsigned int undiscard_blks; 2729a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2730648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2731f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 273239a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 273339a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 273439a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 273539a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 273642190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 273739a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2738e1235983SChangman Lee int bg_node_segs, bg_data_segs; 273939a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2740e1235983SChangman Lee int bg_data_blks, bg_node_blks; 274139a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 274239a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 274339a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 274439a53e0cSJaegeuk Kim 274539a53e0cSJaegeuk Kim unsigned int segment_count[2]; 274639a53e0cSJaegeuk Kim unsigned int block_count[2]; 2747b9a2c252SChangman Lee unsigned int inplace_count; 27489edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 274939a53e0cSJaegeuk Kim }; 275039a53e0cSJaegeuk Kim 2751963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2752963d4f7dSGu Zheng { 2753963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2754963d4f7dSGu Zheng } 2755963d4f7dSGu Zheng 2756942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 275742190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 275839a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2759dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 276033fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 276133fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 27625b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 27635b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 27645b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 27655b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2766d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2767d5e8f6c9SChao Yu do { \ 2768d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2769d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2770d5e8f6c9SChao Yu } while (0) 2771d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2772d5e8f6c9SChao Yu do { \ 2773d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2774d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2775d5e8f6c9SChao Yu } while (0) 27760dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 27770dbdc2aeSJaegeuk Kim do { \ 27780dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 277903e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 27800dbdc2aeSJaegeuk Kim } while (0) 27810dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 27820dbdc2aeSJaegeuk Kim do { \ 27830dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 278403e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 27850dbdc2aeSJaegeuk Kim } while (0) 27863289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 27873289c061SJaegeuk Kim do { \ 27883289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 278903e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 27903289c061SJaegeuk Kim } while (0) 27913289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 27923289c061SJaegeuk Kim do { \ 27933289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 279403e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 27953289c061SJaegeuk Kim } while (0) 2796dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2797dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2798dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2799dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2800b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2801b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 280226a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2803cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 280426a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2805cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 280626a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 280726a28a0cSJaegeuk Kim do { \ 280826a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 280926a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 281026a28a0cSJaegeuk Kim if (cur > max) \ 281126a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 281226a28a0cSJaegeuk Kim } while (0) 2813648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2814648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2815648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2816648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2817648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2818648d50baSChao Yu do { \ 2819648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2820648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2821648d50baSChao Yu if (cur > max) \ 2822648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2823648d50baSChao Yu } while (0) 2824e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 282539a53e0cSJaegeuk Kim do { \ 2826963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 282768afcf2dSTomohiro Kusumi si->tot_segs++; \ 282868afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 282939a53e0cSJaegeuk Kim si->data_segs++; \ 2830e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2831e1235983SChangman Lee } else { \ 283239a53e0cSJaegeuk Kim si->node_segs++; \ 2833e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2834e1235983SChangman Lee } \ 283539a53e0cSJaegeuk Kim } while (0) 283639a53e0cSJaegeuk Kim 283739a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 283868afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 283939a53e0cSJaegeuk Kim 2840e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 284139a53e0cSJaegeuk Kim do { \ 2842963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 284339a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 284439a53e0cSJaegeuk Kim si->data_blks += (blks); \ 284568afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 284639a53e0cSJaegeuk Kim } while (0) 284739a53e0cSJaegeuk Kim 2848e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 284939a53e0cSJaegeuk Kim do { \ 2850963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 285139a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 285239a53e0cSJaegeuk Kim si->node_blks += (blks); \ 285368afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 285439a53e0cSJaegeuk Kim } while (0) 285539a53e0cSJaegeuk Kim 2856cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2857cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2858787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 28594589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 286039a53e0cSJaegeuk Kim #else 2861d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 2862d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 2863d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 2864d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 2865d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 2866d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 2867d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 2868d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 2869d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 2870d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 2871d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 2872d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 2873d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 2874d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 2875d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 2876d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 2877d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 2878d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 2879d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 2880d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 2881d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 2882d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 2883d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 2884d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 2885d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 2886d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 2887d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 2888d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 2889d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 289039a53e0cSJaegeuk Kim 289139a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 289239a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2893787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 28944589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 289539a53e0cSJaegeuk Kim #endif 289639a53e0cSJaegeuk Kim 289739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 289839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 289939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 290039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 290139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 290239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 290339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 290439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2905cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 290639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 290729e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 29081001b347SHuajun Li 2909e18c65b2SHuajun Li /* 2910e18c65b2SHuajun Li * inline.c 2911e18c65b2SHuajun Li */ 2912cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2913cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2914cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2915bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2916cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2917cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2918cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2919cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2920cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2921cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2922cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2923cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2924cac5a3d8SDongOh Shin struct page *ipage); 2925cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2926cac5a3d8SDongOh Shin const struct qstr *orig_name, 2927cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2928cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2929cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2930cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2931cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2932cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2933cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2934cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2935cac5a3d8SDongOh Shin __u64 start, __u64 len); 2936cde4de12SJaegeuk Kim 2937cde4de12SJaegeuk Kim /* 29382658e50dSJaegeuk Kim * shrinker.c 29392658e50dSJaegeuk Kim */ 2940cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2941cac5a3d8SDongOh Shin struct shrink_control *sc); 2942cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2943cac5a3d8SDongOh Shin struct shrink_control *sc); 2944cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2945cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 29462658e50dSJaegeuk Kim 29472658e50dSJaegeuk Kim /* 2948a28ef1f5SChao Yu * extent_cache.c 2949a28ef1f5SChao Yu */ 2950004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 2951004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 2952004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 2953004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 2954004b6862SChao Yu unsigned int ofs); 2955004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 2956004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 2957004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 2958004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 2959004b6862SChao Yu bool force); 2960df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi, 2961df0f6b44SChao Yu struct rb_root *root); 2962cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2963cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2964cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2965cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2966cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2967cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2968cac5a3d8SDongOh Shin struct extent_info *ei); 2969cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 297019b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2971cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2972cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2973a28ef1f5SChao Yu int __init create_extent_cache(void); 2974a28ef1f5SChao Yu void destroy_extent_cache(void); 2975a28ef1f5SChao Yu 2976a28ef1f5SChao Yu /* 29778ceffcb2SChao Yu * sysfs.c 29788ceffcb2SChao Yu */ 2979dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 2980dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 2981dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 2982dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 29838ceffcb2SChao Yu 29848ceffcb2SChao Yu /* 2985cde4de12SJaegeuk Kim * crypto support 2986cde4de12SJaegeuk Kim */ 29870b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2988cde4de12SJaegeuk Kim { 2989cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2990cde4de12SJaegeuk Kim } 2991cde4de12SJaegeuk Kim 29921958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 29931958593eSJaegeuk Kim { 29941958593eSJaegeuk Kim return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode); 29951958593eSJaegeuk Kim } 29961958593eSJaegeuk Kim 2997cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2998cde4de12SJaegeuk Kim { 2999cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 3000cde4de12SJaegeuk Kim file_set_encrypt(inode); 3001cde4de12SJaegeuk Kim #endif 3002cde4de12SJaegeuk Kim } 3003cde4de12SJaegeuk Kim 3004cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 3005cde4de12SJaegeuk Kim { 30060b81d077SJaegeuk Kim return bio->bi_private != NULL; 3007cde4de12SJaegeuk Kim } 3008cde4de12SJaegeuk Kim 3009cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 3010cde4de12SJaegeuk Kim { 3011cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 3012cde4de12SJaegeuk Kim } 3013f424f664SJaegeuk Kim 30140bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 301552763a4bSJaegeuk Kim { 30160bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 301752763a4bSJaegeuk Kim } 301852763a4bSJaegeuk Kim 30197a2af766SChao Yu static inline int f2fs_sb_has_extra_attr(struct super_block *sb) 30207a2af766SChao Yu { 30217a2af766SChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_EXTRA_ATTR); 30227a2af766SChao Yu } 30237a2af766SChao Yu 30245c57132eSChao Yu static inline int f2fs_sb_has_project_quota(struct super_block *sb) 30255c57132eSChao Yu { 30265c57132eSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_PRJQUOTA); 30275c57132eSChao Yu } 30285c57132eSChao Yu 3029704956ecSChao Yu static inline int f2fs_sb_has_inode_chksum(struct super_block *sb) 3030704956ecSChao Yu { 3031704956ecSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CHKSUM); 3032704956ecSChao Yu } 3033704956ecSChao Yu 3034*6afc662eSChao Yu static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb) 3035*6afc662eSChao Yu { 3036*6afc662eSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_FLEXIBLE_INLINE_XATTR); 3037*6afc662eSChao Yu } 3038*6afc662eSChao Yu 3039178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 3040178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 30413c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 3042178053e2SDamien Le Moal { 3043178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 30443c62be17SJaegeuk Kim int i; 3045178053e2SDamien Le Moal 30463c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 30473c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 30483c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 30493c62be17SJaegeuk Kim return -EINVAL; 3050178053e2SDamien Le Moal } 3051178053e2SDamien Le Moal #endif 3052178053e2SDamien Le Moal 305396ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 305496ba2decSDamien Le Moal { 305596ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 305696ba2decSDamien Le Moal 305796ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 305852763a4bSJaegeuk Kim } 305952763a4bSJaegeuk Kim 306052763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 306152763a4bSJaegeuk Kim { 306252763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 306352763a4bSJaegeuk Kim clear_opt(sbi, LFS); 306452763a4bSJaegeuk Kim 306552763a4bSJaegeuk Kim switch (mt) { 306652763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 306752763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 306852763a4bSJaegeuk Kim break; 306952763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 307052763a4bSJaegeuk Kim set_opt(sbi, LFS); 307152763a4bSJaegeuk Kim break; 307252763a4bSJaegeuk Kim } 307352763a4bSJaegeuk Kim } 307452763a4bSJaegeuk Kim 3075fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 3076fcc85a4dSJaegeuk Kim { 3077fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 3078886f56f9SAl Viro umode_t mode = inode->i_mode; 3079fcc85a4dSJaegeuk Kim 3080fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 3081fcc85a4dSJaegeuk Kim #else 3082fcc85a4dSJaegeuk Kim return 0; 3083fcc85a4dSJaegeuk Kim #endif 3084fcc85a4dSJaegeuk Kim } 3085fcc85a4dSJaegeuk Kim 308639a53e0cSJaegeuk Kim #endif 3087