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> 2643b6573bSKeith Mok #include <crypto/hash.h> 2739a53e0cSJaegeuk Kim 28734f0d24SDave Chinner #define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_F2FS_FS_ENCRYPTION) 29734f0d24SDave Chinner #include <linux/fscrypt.h> 30734f0d24SDave Chinner 315d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 329850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 335d56b671SJaegeuk Kim #else 349850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 359850cf4aSJaegeuk Kim do { \ 369850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 379850cf4aSJaegeuk Kim WARN_ON(1); \ 38caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 399850cf4aSJaegeuk Kim } \ 409850cf4aSJaegeuk Kim } while (0) 415d56b671SJaegeuk Kim #endif 425d56b671SJaegeuk Kim 432c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 442c63feadSJaegeuk Kim enum { 452c63feadSJaegeuk Kim FAULT_KMALLOC, 46c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 4701eccef7SChao Yu FAULT_PAGE_GET, 48d62fe971SChao Yu FAULT_ALLOC_BIO, 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 966afc662eSChao 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 1226afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 123234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO 0x0080 124cde4de12SJaegeuk Kim 12576f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 12676f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 12776f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 128c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 12976f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 130c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 13176f105a2SJaegeuk Kim 13239a53e0cSJaegeuk Kim /* 13339a53e0cSJaegeuk Kim * For checkpoint manager 13439a53e0cSJaegeuk Kim */ 13539a53e0cSJaegeuk Kim enum { 13639a53e0cSJaegeuk Kim NAT_BITMAP, 13739a53e0cSJaegeuk Kim SIT_BITMAP 13839a53e0cSJaegeuk Kim }; 13939a53e0cSJaegeuk Kim 140c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 141c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 142c473f1a9SChao Yu #define CP_SYNC 0x00000004 143c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 144c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1451f43e2adSChao Yu #define CP_TRIMMED 0x00000020 14675ab4cb8SJaegeuk Kim 14747b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 148bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 1494ddb1a4dSJaegeuk Kim (GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections)) 150a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 151a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 1524ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 153ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 154969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 155969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 15660b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 157dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 158bba681cbSJaegeuk Kim 15975ab4cb8SJaegeuk Kim struct cp_control { 16075ab4cb8SJaegeuk Kim int reason; 1614b2fecc8SJaegeuk Kim __u64 trim_start; 1624b2fecc8SJaegeuk Kim __u64 trim_end; 1634b2fecc8SJaegeuk Kim __u64 trim_minlen; 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 4026afc662eSChao Yu #define DEF_MIN_INLINE_SIZE 1 4037a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 4046afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode); 4056afc662eSChao 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) - \ 4086afc662eSChao Yu F2FS_INLINE_XATTR_ADDRS(inode) - \ 4096afc662eSChao 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 */ 545d5097be5SHyunchul Lee int m_seg_type; 546003a3e1dSJaegeuk Kim }; 547003a3e1dSJaegeuk Kim 548e2b4e2bcSChao Yu /* for flag in get_data_block */ 549f2220c7fSQiuyang Sun enum { 550f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 551f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 552f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 553f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 554f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 555f2220c7fSQiuyang Sun }; 556e2b4e2bcSChao Yu 557003a3e1dSJaegeuk Kim /* 55839a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 55939a53e0cSJaegeuk Kim */ 56039a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 561354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 562cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 563e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 56426787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 56539a53e0cSJaegeuk Kim 566b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 567b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 568b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 569b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 570b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 571b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 572cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 573cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 574cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 575e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 576e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 57726787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 57826787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 579cde4de12SJaegeuk Kim 580ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 581ab9fa662SJaegeuk Kim 58239a53e0cSJaegeuk Kim struct f2fs_inode_info { 58339a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 58439a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 58539a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 58638431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 58739a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 5886666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 58939a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 59039a53e0cSJaegeuk Kim 59139a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 59239a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 593d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 594204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 59539a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 59639a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 59788c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 598b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 59939a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 60026de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 60188b88a66SJaegeuk Kim 6020abd675eSChao Yu #ifdef CONFIG_QUOTA 6030abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 6040abd675eSChao Yu 6050abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 6060abd675eSChao Yu qsize_t i_reserved_quota; 6070abd675eSChao Yu #endif 6080f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 6090f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 61057864ae5SJaegeuk Kim struct list_head inmem_ilist; /* list for inmem inodes */ 61188b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 6127a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 61388b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 6143e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 61582e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 6165a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 61727161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 618f2470371SChao Yu 6197a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 6205c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 6216afc662eSChao Yu int i_inline_xattr_size; /* inline xattr size */ 62239a53e0cSJaegeuk Kim }; 62339a53e0cSJaegeuk Kim 62439a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 625bd933d4fSChao Yu struct f2fs_extent *i_ext) 62639a53e0cSJaegeuk Kim { 627bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 628bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 629bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 63039a53e0cSJaegeuk Kim } 63139a53e0cSJaegeuk Kim 63239a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 63339a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 63439a53e0cSJaegeuk Kim { 63539a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 6364d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 63739a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 63839a53e0cSJaegeuk Kim } 63939a53e0cSJaegeuk Kim 640429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 641429511cdSChao Yu u32 blk, unsigned int len) 642429511cdSChao Yu { 643429511cdSChao Yu ei->fofs = fofs; 644429511cdSChao Yu ei->blk = blk; 645429511cdSChao Yu ei->len = len; 646429511cdSChao Yu } 647429511cdSChao Yu 648004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 649004b6862SChao Yu struct discard_info *front) 650004b6862SChao Yu { 651004b6862SChao Yu return back->lstart + back->len == front->lstart; 652004b6862SChao Yu } 653004b6862SChao Yu 654004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 655004b6862SChao Yu struct discard_info *back) 656004b6862SChao Yu { 657004b6862SChao Yu return __is_discard_mergeable(back, cur); 658004b6862SChao Yu } 659004b6862SChao Yu 660004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 661004b6862SChao Yu struct discard_info *front) 662004b6862SChao Yu { 663004b6862SChao Yu return __is_discard_mergeable(cur, front); 664004b6862SChao Yu } 665004b6862SChao Yu 666429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 667429511cdSChao Yu struct extent_info *front) 668429511cdSChao Yu { 669429511cdSChao Yu return (back->fofs + back->len == front->fofs && 670429511cdSChao Yu back->blk + back->len == front->blk); 671429511cdSChao Yu } 672429511cdSChao Yu 673429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 674429511cdSChao Yu struct extent_info *back) 675429511cdSChao Yu { 676429511cdSChao Yu return __is_extent_mergeable(back, cur); 677429511cdSChao Yu } 678429511cdSChao Yu 679429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 680429511cdSChao Yu struct extent_info *front) 681429511cdSChao Yu { 682429511cdSChao Yu return __is_extent_mergeable(cur, front); 683429511cdSChao Yu } 684429511cdSChao Yu 685cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 686205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 687205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 6884abd3f5aSChao Yu { 689205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 6904abd3f5aSChao Yu et->largest = en->ei; 6917c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 692205b9822SJaegeuk Kim } 6934abd3f5aSChao Yu } 6944abd3f5aSChao Yu 6959a4ffdf5SChao Yu /* 6969a4ffdf5SChao Yu * For free nid management 6979a4ffdf5SChao Yu */ 6989a4ffdf5SChao Yu enum nid_state { 6999a4ffdf5SChao Yu FREE_NID, /* newly added to free nid list */ 7009a4ffdf5SChao Yu PREALLOC_NID, /* it is preallocated */ 7019a4ffdf5SChao Yu MAX_NID_STATE, 702b8559dc2SChao Yu }; 703b8559dc2SChao Yu 70439a53e0cSJaegeuk Kim struct f2fs_nm_info { 70539a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 70639a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 70704d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 70839a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 709cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 710ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 7112304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 71239a53e0cSJaegeuk Kim 71339a53e0cSJaegeuk Kim /* NAT cache management */ 71439a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 715309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 716b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 71739a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 718309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 719aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 72022ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 72139a53e0cSJaegeuk Kim 72239a53e0cSJaegeuk Kim /* free node ids management */ 7238a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 7249a4ffdf5SChao Yu struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ 7259a4ffdf5SChao Yu unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 726b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 72739a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 7284ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 7294ac91242SChao Yu unsigned char *nat_block_bitmap; 730586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 73139a53e0cSJaegeuk Kim 73239a53e0cSJaegeuk Kim /* for checkpoint */ 73339a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 73422ad0b6aSJaegeuk Kim 73522ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 73622ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 73722ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 73822ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 739599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 740599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 741599a09b2SChao Yu #endif 74239a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 74339a53e0cSJaegeuk Kim }; 74439a53e0cSJaegeuk Kim 74539a53e0cSJaegeuk Kim /* 74639a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 74739a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 74839a53e0cSJaegeuk Kim * by the data offset in a file. 74939a53e0cSJaegeuk Kim */ 75039a53e0cSJaegeuk Kim struct dnode_of_data { 75139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 75239a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 75339a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 75439a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 75539a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 75639a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 75793bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 7583cf45747SChao Yu char cur_level; /* level of hole node page */ 7593cf45747SChao Yu char max_level; /* level of current page located */ 76039a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 76139a53e0cSJaegeuk Kim }; 76239a53e0cSJaegeuk Kim 76339a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 76439a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 76539a53e0cSJaegeuk Kim { 766d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 76739a53e0cSJaegeuk Kim dn->inode = inode; 76839a53e0cSJaegeuk Kim dn->inode_page = ipage; 76939a53e0cSJaegeuk Kim dn->node_page = npage; 77039a53e0cSJaegeuk Kim dn->nid = nid; 77139a53e0cSJaegeuk Kim } 77239a53e0cSJaegeuk Kim 77339a53e0cSJaegeuk Kim /* 77439a53e0cSJaegeuk Kim * For SIT manager 77539a53e0cSJaegeuk Kim * 77639a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 77739a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 77839a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 77939a53e0cSJaegeuk Kim * respectively. 78039a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 78139a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 78239a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 78339a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 78439a53e0cSJaegeuk Kim * data and 8 for node logs. 78539a53e0cSJaegeuk Kim */ 78639a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 78739a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 78839a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 78939a53e0cSJaegeuk Kim 79039a53e0cSJaegeuk Kim enum { 79139a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 79239a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 79339a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 79439a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 79539a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 79639a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 79738aa0889SJaegeuk Kim NO_CHECK_TYPE, 79839a53e0cSJaegeuk Kim }; 79939a53e0cSJaegeuk Kim 8006b4afdd7SJaegeuk Kim struct flush_cmd { 8016b4afdd7SJaegeuk Kim struct completion wait; 802721bd4d5SGu Zheng struct llist_node llnode; 80339d787beSChao Yu nid_t ino; 8046b4afdd7SJaegeuk Kim int ret; 8056b4afdd7SJaegeuk Kim }; 8066b4afdd7SJaegeuk Kim 807a688b9d9SGu Zheng struct flush_cmd_control { 808a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 809a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 8108b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 8118b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 812721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 813721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 814a688b9d9SGu Zheng }; 815a688b9d9SGu Zheng 81639a53e0cSJaegeuk Kim struct f2fs_sm_info { 81739a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 81839a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 81939a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 82039a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 82139a53e0cSJaegeuk Kim 8222b60311dSChao Yu struct rw_semaphore curseg_lock; /* for preventing curseg change */ 8232b60311dSChao Yu 82439a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 82539a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 82639a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 82739a53e0cSJaegeuk Kim 82839a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 82939a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 83039a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 83139a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 83281eb8d6eSJaegeuk Kim 83381eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 83481eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 8357fd9e544SJaegeuk Kim 836bba681cbSJaegeuk Kim /* for batched trimming */ 837bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 838bba681cbSJaegeuk Kim 839184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 840184a5cd2SChao Yu 841216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 842216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 843c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 844ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 845a2a12b67SChao Yu unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ 8466b4afdd7SJaegeuk Kim 8476b4afdd7SJaegeuk Kim /* for flush command control */ 848b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 849a688b9d9SGu Zheng 8500b54fb84SJaegeuk Kim /* for discard command control */ 8510b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 85239a53e0cSJaegeuk Kim }; 85339a53e0cSJaegeuk Kim 85439a53e0cSJaegeuk Kim /* 85539a53e0cSJaegeuk Kim * For superblock 85639a53e0cSJaegeuk Kim */ 85739a53e0cSJaegeuk Kim /* 85839a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 85939a53e0cSJaegeuk Kim * 86039a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 86139a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 86239a53e0cSJaegeuk Kim */ 86336951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 86439a53e0cSJaegeuk Kim enum count_type { 86539a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 866c227f912SChao Yu F2FS_DIRTY_DATA, 8672c8a4a28SJaegeuk Kim F2FS_DIRTY_QDATA, 86839a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 86939a53e0cSJaegeuk Kim F2FS_DIRTY_META, 8708dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 8710f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 87236951b38SChao Yu F2FS_WB_CP_DATA, 87336951b38SChao Yu F2FS_WB_DATA, 87439a53e0cSJaegeuk Kim NR_COUNT_TYPE, 87539a53e0cSJaegeuk Kim }; 87639a53e0cSJaegeuk Kim 87739a53e0cSJaegeuk Kim /* 878e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 87939a53e0cSJaegeuk Kim * The available types are: 88039a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 88139a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 88239a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 88339a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 88439a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 88539a53e0cSJaegeuk Kim * with waiting the bio's completion 88639a53e0cSJaegeuk Kim * ... Only can be used with META. 88739a53e0cSJaegeuk Kim */ 8887d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 88939a53e0cSJaegeuk Kim enum page_type { 89039a53e0cSJaegeuk Kim DATA, 89139a53e0cSJaegeuk Kim NODE, 89239a53e0cSJaegeuk Kim META, 89339a53e0cSJaegeuk Kim NR_PAGE_TYPE, 89439a53e0cSJaegeuk Kim META_FLUSH, 8958ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 8968ce67cb0SJaegeuk Kim INMEM_DROP, 8978c242db9SJaegeuk Kim INMEM_INVALIDATE, 89828bc106bSChao Yu INMEM_REVOKE, 8998ce67cb0SJaegeuk Kim IPU, 9008ce67cb0SJaegeuk Kim OPU, 90139a53e0cSJaegeuk Kim }; 90239a53e0cSJaegeuk Kim 903a912b54dSJaegeuk Kim enum temp_type { 904a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 905a912b54dSJaegeuk Kim WARM, 906a912b54dSJaegeuk Kim COLD, 907a912b54dSJaegeuk Kim NR_TEMP_TYPE, 908a912b54dSJaegeuk Kim }; 909a912b54dSJaegeuk Kim 910cc15620bSJaegeuk Kim enum need_lock_type { 911cc15620bSJaegeuk Kim LOCK_REQ = 0, 912cc15620bSJaegeuk Kim LOCK_DONE, 913cc15620bSJaegeuk Kim LOCK_RETRY, 914cc15620bSJaegeuk Kim }; 915cc15620bSJaegeuk Kim 916a5fd5050SChao Yu enum cp_reason_type { 917a5fd5050SChao Yu CP_NO_NEEDED, 918a5fd5050SChao Yu CP_NON_REGULAR, 919a5fd5050SChao Yu CP_HARDLINK, 920a5fd5050SChao Yu CP_SB_NEED_CP, 921a5fd5050SChao Yu CP_WRONG_PINO, 922a5fd5050SChao Yu CP_NO_SPC_ROLL, 923a5fd5050SChao Yu CP_NODE_NEED_CP, 924a5fd5050SChao Yu CP_FASTBOOT_MODE, 925a5fd5050SChao Yu CP_SPEC_LOG_NUM, 926a5fd5050SChao Yu }; 927a5fd5050SChao Yu 928b0af6d49SChao Yu enum iostat_type { 929b0af6d49SChao Yu APP_DIRECT_IO, /* app direct IOs */ 930b0af6d49SChao Yu APP_BUFFERED_IO, /* app buffered IOs */ 931b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 932b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 933b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 934b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 935b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 936b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 937b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 938b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 939b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 940b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 941b0af6d49SChao Yu FS_DISCARD, /* discard */ 942b0af6d49SChao Yu NR_IO_TYPE, 943b0af6d49SChao Yu }; 944b0af6d49SChao Yu 945458e6197SJaegeuk Kim struct f2fs_io_info { 94605ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 94739d787beSChao Yu nid_t ino; /* inode number */ 948458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 949a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 95004d328deSMike Christie int op; /* contains REQ_OP_ */ 951ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 9527a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 95328bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 95405ca3632SJaegeuk Kim struct page *page; /* page to be written */ 9554375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 956fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 957d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 958cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 959fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 960b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 961458e6197SJaegeuk Kim }; 962458e6197SJaegeuk Kim 96368afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 9641ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 965458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 9661ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 9671ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 968458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 969df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 970fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 971fb830fc5SChao Yu struct list_head io_list; /* track fios */ 9721ff7bd3bSJaegeuk Kim }; 9731ff7bd3bSJaegeuk Kim 9743c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 9753c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 9763c62be17SJaegeuk Kim struct f2fs_dev_info { 9773c62be17SJaegeuk Kim struct block_device *bdev; 9783c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 9793c62be17SJaegeuk Kim unsigned int total_segments; 9803c62be17SJaegeuk Kim block_t start_blk; 9813c62be17SJaegeuk Kim block_t end_blk; 9823c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 9833c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 9843c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 9853c62be17SJaegeuk Kim #endif 9863c62be17SJaegeuk Kim }; 9873c62be17SJaegeuk Kim 988c227f912SChao Yu enum inode_type { 989c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 990c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 9910f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 99257864ae5SJaegeuk Kim ATOMIC_FILE, /* for all atomic files */ 993c227f912SChao Yu NR_INODE_TYPE, 994c227f912SChao Yu }; 995c227f912SChao Yu 99667298804SChao Yu /* for inner inode cache management */ 99767298804SChao Yu struct inode_management { 99867298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 99967298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 100067298804SChao Yu struct list_head ino_list; /* inode list head */ 100167298804SChao Yu unsigned long ino_num; /* number of entries */ 100267298804SChao Yu }; 100367298804SChao Yu 1004caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 1005caf0047eSChao Yu enum { 1006caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 1007caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 1008caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 1009caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 1010df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 1011bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 1012caf0047eSChao Yu }; 1013caf0047eSChao Yu 10146beceb54SJaegeuk Kim enum { 10156beceb54SJaegeuk Kim CP_TIME, 1016d0239e1bSJaegeuk Kim REQ_TIME, 10176beceb54SJaegeuk Kim MAX_TIME, 10186beceb54SJaegeuk Kim }; 10196beceb54SJaegeuk Kim 102039a53e0cSJaegeuk Kim struct f2fs_sb_info { 102139a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 10225e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 102339a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 1024e8240f65SChao Yu int valid_super_block; /* valid super block no */ 1025fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 102639a53e0cSJaegeuk Kim 1027178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 1028178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1029178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 1030178053e2SDamien Le Moal #endif 1031178053e2SDamien Le Moal 103239a53e0cSJaegeuk Kim /* for node-related operations */ 103339a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 103439a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 103539a53e0cSJaegeuk Kim 103639a53e0cSJaegeuk Kim /* for segment-related operations */ 103739a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 10381ff7bd3bSJaegeuk Kim 10391ff7bd3bSJaegeuk Kim /* for bio operations */ 1040a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1041e41e6d75SChao Yu struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 1042e41e6d75SChao Yu /* bio ordering for NODE/DATA */ 10430a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 10440a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 104539a53e0cSJaegeuk Kim 104639a53e0cSJaegeuk Kim /* for checkpoint */ 104739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 10488508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1049aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 105039a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 105139936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 1052b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1053b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 105459c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1055fb51b5efSChangman Lee wait_queue_head_t cp_wait; 10566beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 10576beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 105839a53e0cSJaegeuk Kim 105967298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 10606451e041SJaegeuk Kim 10616451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 10620d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 106339a53e0cSJaegeuk Kim 1064c227f912SChao Yu /* for inode management */ 1065c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1066c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 106739a53e0cSJaegeuk Kim 106813054c54SChao Yu /* for extent tree cache */ 106913054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 10705e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 107113054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 107213054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 10737441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1074137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 107574fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 107613054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 107713054c54SChao Yu 107839a53e0cSJaegeuk Kim /* basic filesystem units */ 107939a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 108039a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 108139a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 108239a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 108339a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 108439a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 108539a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 108639a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 108739a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 108839a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 108939a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 109039a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 109139a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1092e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 109339a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 1094ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 10956afc662eSChao Yu int inline_xattr_size; /* inline xattr size */ 1096a2a12b67SChao Yu unsigned int trigger_ssr_threshold; /* threshold to trigger ssr */ 1097f6df8f23SSheng Yong int readdir_ra; /* readahead inode in readdir */ 109839a53e0cSJaegeuk Kim 109939a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 110039a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1101a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 110239a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1103daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 110480d42145SYunlong Song block_t current_reserved_blocks; /* current reserved blocks */ 1105daeb433eSChao Yu 1106292c196aSChao Yu unsigned int nquota_files; /* # of quota sysfile */ 1107292c196aSChao Yu 110839a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 1109523be8a6SJaegeuk Kim 1110523be8a6SJaegeuk Kim /* # of pages, see count_type */ 111135782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 111241382ec4SJaegeuk Kim /* # of allocated blocks */ 111341382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 111439a53e0cSJaegeuk Kim 1115687de7f1SJaegeuk Kim /* writeback control */ 1116687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 1117687de7f1SJaegeuk Kim 1118513c5f37SJaegeuk Kim /* valid inode count */ 1119513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1120513c5f37SJaegeuk Kim 112139a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 112239a53e0cSJaegeuk Kim 112339a53e0cSJaegeuk Kim /* for cleaning operations */ 112439a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 112539a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 11265ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 112739a53e0cSJaegeuk Kim 1128e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 1129e93b9865SHou Pengyang u64 fggc_threshold; 1130e93b9865SHou Pengyang 1131b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1132b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1133b1c57c1cSJaegeuk Kim 113439a53e0cSJaegeuk Kim /* 113539a53e0cSJaegeuk Kim * for stat information. 113639a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 113739a53e0cSJaegeuk Kim */ 113835b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 113939a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 114039a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 114139a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1142b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 11435b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 11445b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 11455b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 11465b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1147d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 114803e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 114903e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 115026a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 1151648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 115226a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1153648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 115439a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 115533fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 115635b09d82SNamjae Jeon #endif 115739a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1158b59d0baeSNamjae Jeon 1159b0af6d49SChao Yu /* For app/fs IO statistics */ 1160b0af6d49SChao Yu spinlock_t iostat_lock; 1161b0af6d49SChao Yu unsigned long long write_iostat[NR_IO_TYPE]; 1162b0af6d49SChao Yu bool iostat_enable; 1163b0af6d49SChao Yu 1164b59d0baeSNamjae Jeon /* For sysfs suppport */ 1165b59d0baeSNamjae Jeon struct kobject s_kobj; 1166b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 11672658e50dSJaegeuk Kim 11682658e50dSJaegeuk Kim /* For shrinker support */ 11692658e50dSJaegeuk Kim struct list_head s_list; 11703c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 11713c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 11721228b482SChao Yu unsigned int dirty_device; /* for checkpoint data flush */ 11731228b482SChao Yu spinlock_t dev_lock; /* protect dirty_device */ 11742658e50dSJaegeuk Kim struct mutex umount_mutex; 11752658e50dSJaegeuk Kim unsigned int shrinker_run_no; 11768f1dbbbbSShuoran Liu 11778f1dbbbbSShuoran Liu /* For write statistics */ 11788f1dbbbbSShuoran Liu u64 sectors_written_start; 11798f1dbbbbSShuoran Liu u64 kbytes_written; 118043b6573bSKeith Mok 118143b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 118243b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 11831ecc0c5cSChao Yu 1184704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1185704956ecSChao Yu __u32 s_chksum_seed; 1186704956ecSChao Yu 11871ecc0c5cSChao Yu /* For fault injection */ 11881ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 11891ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 11901ecc0c5cSChao Yu #endif 11914b2414d0SChao Yu 11924b2414d0SChao Yu #ifdef CONFIG_QUOTA 11934b2414d0SChao Yu /* Names of quota files with journalled quota */ 11944b2414d0SChao Yu char *s_qf_names[MAXQUOTAS]; 11954b2414d0SChao Yu int s_jquota_fmt; /* Format of quota to use */ 11964b2414d0SChao Yu #endif 119739a53e0cSJaegeuk Kim }; 119839a53e0cSJaegeuk Kim 11991ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 120055523519SChao Yu #define f2fs_show_injection_info(type) \ 120155523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 120255523519SChao Yu KERN_INFO, fault_name[type], \ 120355523519SChao Yu __func__, __builtin_return_address(0)) 12041ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 12051ecc0c5cSChao Yu { 12061ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 12071ecc0c5cSChao Yu 12081ecc0c5cSChao Yu if (!ffi->inject_rate) 12091ecc0c5cSChao Yu return false; 12101ecc0c5cSChao Yu 12111ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 12121ecc0c5cSChao Yu return false; 12131ecc0c5cSChao Yu 12141ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 12151ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 12161ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 12171ecc0c5cSChao Yu return true; 12181ecc0c5cSChao Yu } 12191ecc0c5cSChao Yu return false; 12201ecc0c5cSChao Yu } 12211ecc0c5cSChao Yu #endif 12221ecc0c5cSChao Yu 12238f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 12248f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 12258f1dbbbbSShuoran Liu */ 12268f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 122768afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 122868afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 12298f1dbbbbSShuoran Liu 12306beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 12316beceb54SJaegeuk Kim { 12326beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 12336beceb54SJaegeuk Kim } 12346beceb54SJaegeuk Kim 12356beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 12366beceb54SJaegeuk Kim { 12376bccfa19SArnd Bergmann unsigned long interval = sbi->interval_time[type] * HZ; 12386beceb54SJaegeuk Kim 12396beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 12406beceb54SJaegeuk Kim } 12416beceb54SJaegeuk Kim 1242d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1243d0239e1bSJaegeuk Kim { 1244d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1245d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1246d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1247d0239e1bSJaegeuk Kim 1248d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1249d0239e1bSJaegeuk Kim return 0; 1250d0239e1bSJaegeuk Kim 1251d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1252d0239e1bSJaegeuk Kim } 1253d0239e1bSJaegeuk Kim 125439a53e0cSJaegeuk Kim /* 125539a53e0cSJaegeuk Kim * Inline functions 125639a53e0cSJaegeuk Kim */ 125743b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 125843b6573bSKeith Mok unsigned int length) 125943b6573bSKeith Mok { 126043b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 126143b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 1262d41519a6SDavid Miller u32 retval; 126343b6573bSKeith Mok int err; 126443b6573bSKeith Mok 126543b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 126643b6573bSKeith Mok shash->flags = 0; 126743b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 126843b6573bSKeith Mok 126943b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 127043b6573bSKeith Mok BUG_ON(err); 127143b6573bSKeith Mok 1272d41519a6SDavid Miller retval = *ctx; 1273d41519a6SDavid Miller barrier_data(ctx); 1274d41519a6SDavid Miller return retval; 127543b6573bSKeith Mok } 127643b6573bSKeith Mok 127743b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 127843b6573bSKeith Mok void *buf, size_t buf_size) 127943b6573bSKeith Mok { 128043b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 128143b6573bSKeith Mok } 128243b6573bSKeith Mok 1283704956ecSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1284704956ecSChao Yu const void *address, unsigned int length) 1285704956ecSChao Yu { 1286704956ecSChao Yu struct { 1287704956ecSChao Yu struct shash_desc shash; 1288704956ecSChao Yu char ctx[4]; 1289704956ecSChao Yu } desc; 1290704956ecSChao Yu int err; 1291704956ecSChao Yu 1292704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1293704956ecSChao Yu 1294704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1295704956ecSChao Yu desc.shash.flags = 0; 1296704956ecSChao Yu *(u32 *)desc.ctx = crc; 1297704956ecSChao Yu 1298704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1299704956ecSChao Yu BUG_ON(err); 1300704956ecSChao Yu 1301704956ecSChao Yu return *(u32 *)desc.ctx; 1302704956ecSChao Yu } 1303704956ecSChao Yu 130439a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 130539a53e0cSJaegeuk Kim { 130639a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 130739a53e0cSJaegeuk Kim } 130839a53e0cSJaegeuk Kim 130939a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 131039a53e0cSJaegeuk Kim { 131139a53e0cSJaegeuk Kim return sb->s_fs_info; 131239a53e0cSJaegeuk Kim } 131339a53e0cSJaegeuk Kim 13144081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 13154081363fSJaegeuk Kim { 13164081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 13174081363fSJaegeuk Kim } 13184081363fSJaegeuk Kim 13194081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 13204081363fSJaegeuk Kim { 13214081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 13224081363fSJaegeuk Kim } 13234081363fSJaegeuk Kim 13244081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 13254081363fSJaegeuk Kim { 13264081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 13274081363fSJaegeuk Kim } 13284081363fSJaegeuk Kim 132939a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 133039a53e0cSJaegeuk Kim { 133139a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 133239a53e0cSJaegeuk Kim } 133339a53e0cSJaegeuk Kim 133439a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 133539a53e0cSJaegeuk Kim { 133639a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 133739a53e0cSJaegeuk Kim } 133839a53e0cSJaegeuk Kim 133945590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 134045590710SGu Zheng { 134145590710SGu Zheng return (struct f2fs_node *)page_address(page); 134245590710SGu Zheng } 134345590710SGu Zheng 134458bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 134558bfaf44SJaegeuk Kim { 134658bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 134758bfaf44SJaegeuk Kim } 134858bfaf44SJaegeuk Kim 134939a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 135039a53e0cSJaegeuk Kim { 135139a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 135239a53e0cSJaegeuk Kim } 135339a53e0cSJaegeuk Kim 135439a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 135539a53e0cSJaegeuk Kim { 135639a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 135739a53e0cSJaegeuk Kim } 135839a53e0cSJaegeuk Kim 135939a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 136039a53e0cSJaegeuk Kim { 136139a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 136239a53e0cSJaegeuk Kim } 136339a53e0cSJaegeuk Kim 136439a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 136539a53e0cSJaegeuk Kim { 136639a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 136739a53e0cSJaegeuk Kim } 136839a53e0cSJaegeuk Kim 136939a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 137039a53e0cSJaegeuk Kim { 137139a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 137239a53e0cSJaegeuk Kim } 137339a53e0cSJaegeuk Kim 13749df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 13759df27d98SGu Zheng { 13769df27d98SGu Zheng return sbi->meta_inode->i_mapping; 13779df27d98SGu Zheng } 13789df27d98SGu Zheng 13794ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 13804ef51a8fSJaegeuk Kim { 13814ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 13824ef51a8fSJaegeuk Kim } 13834ef51a8fSJaegeuk Kim 1384caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 138539a53e0cSJaegeuk Kim { 1386fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 138739a53e0cSJaegeuk Kim } 138839a53e0cSJaegeuk Kim 1389caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 139039a53e0cSJaegeuk Kim { 1391fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1392caf0047eSChao Yu } 1393caf0047eSChao Yu 1394caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1395caf0047eSChao Yu { 1396fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 139739a53e0cSJaegeuk Kim } 139839a53e0cSJaegeuk Kim 1399d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1400d71b5564SJaegeuk Kim { 1401d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1402d71b5564SJaegeuk Kim } 1403d71b5564SJaegeuk Kim 1404ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) 1405ea676733SJaegeuk Kim { 1406ea676733SJaegeuk Kim if (type < F2FS_MAX_QUOTAS) 1407ea676733SJaegeuk Kim return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); 1408ea676733SJaegeuk Kim return 0; 1409ea676733SJaegeuk Kim } 1410ea676733SJaegeuk Kim 1411ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1412ced2c7eaSKinglong Mee { 1413ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1414ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1415ced2c7eaSKinglong Mee } 1416ced2c7eaSKinglong Mee 1417aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 141825ca923bSJaegeuk Kim { 141925ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1420aaec2b1dSChao Yu 142125ca923bSJaegeuk Kim return ckpt_flags & f; 142225ca923bSJaegeuk Kim } 142325ca923bSJaegeuk Kim 1424aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 142525ca923bSJaegeuk Kim { 1426aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1427aaec2b1dSChao Yu } 1428aaec2b1dSChao Yu 1429aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1430aaec2b1dSChao Yu { 1431aaec2b1dSChao Yu unsigned int ckpt_flags; 1432aaec2b1dSChao Yu 1433aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 143425ca923bSJaegeuk Kim ckpt_flags |= f; 143525ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 143625ca923bSJaegeuk Kim } 143725ca923bSJaegeuk Kim 1438aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 143925ca923bSJaegeuk Kim { 1440d1aa2453SChao Yu unsigned long flags; 1441d1aa2453SChao Yu 1442d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1443aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1444d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1445aaec2b1dSChao Yu } 1446aaec2b1dSChao Yu 1447aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1448aaec2b1dSChao Yu { 1449aaec2b1dSChao Yu unsigned int ckpt_flags; 1450aaec2b1dSChao Yu 1451aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 145225ca923bSJaegeuk Kim ckpt_flags &= (~f); 145325ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 145425ca923bSJaegeuk Kim } 145525ca923bSJaegeuk Kim 1456aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1457aaec2b1dSChao Yu { 1458d1aa2453SChao Yu unsigned long flags; 1459d1aa2453SChao Yu 1460d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1461aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1462d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1463aaec2b1dSChao Yu } 1464aaec2b1dSChao Yu 146522ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 146622ad0b6aSJaegeuk Kim { 1467d1aa2453SChao Yu unsigned long flags; 1468d1aa2453SChao Yu 146922ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 147022ad0b6aSJaegeuk Kim 147122ad0b6aSJaegeuk Kim if (lock) 1472d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 147322ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 147422ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 147522ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 147622ad0b6aSJaegeuk Kim if (lock) 1477d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 147822ad0b6aSJaegeuk Kim } 147922ad0b6aSJaegeuk Kim 148022ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 148122ad0b6aSJaegeuk Kim struct cp_control *cpc) 148222ad0b6aSJaegeuk Kim { 148322ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 148422ad0b6aSJaegeuk Kim 1485c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 148622ad0b6aSJaegeuk Kim } 148722ad0b6aSJaegeuk Kim 1488e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 148939a53e0cSJaegeuk Kim { 1490b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 149139a53e0cSJaegeuk Kim } 149239a53e0cSJaegeuk Kim 1493cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1494cc15620bSJaegeuk Kim { 1495cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1496cc15620bSJaegeuk Kim } 1497cc15620bSJaegeuk Kim 1498e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 149939a53e0cSJaegeuk Kim { 1500b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 150139936837SJaegeuk Kim } 150239936837SJaegeuk Kim 1503e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 150439936837SJaegeuk Kim { 1505b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 150639936837SJaegeuk Kim } 150739936837SJaegeuk Kim 1508e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 150939936837SJaegeuk Kim { 1510b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 151139a53e0cSJaegeuk Kim } 151239a53e0cSJaegeuk Kim 1513119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1514119ee914SJaegeuk Kim { 1515119ee914SJaegeuk Kim int reason = CP_SYNC; 1516119ee914SJaegeuk Kim 1517119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1518119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1519119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1520119ee914SJaegeuk Kim reason = CP_UMOUNT; 1521119ee914SJaegeuk Kim return reason; 1522119ee914SJaegeuk Kim } 1523119ee914SJaegeuk Kim 1524119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1525119ee914SJaegeuk Kim { 1526c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1527119ee914SJaegeuk Kim } 1528119ee914SJaegeuk Kim 1529119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1530119ee914SJaegeuk Kim { 1531aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1532aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1533119ee914SJaegeuk Kim } 1534119ee914SJaegeuk Kim 153539a53e0cSJaegeuk Kim /* 153639a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 153739a53e0cSJaegeuk Kim */ 1538064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 153939a53e0cSJaegeuk Kim { 1540d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1541d6b7d4b3SChao Yu return -EINVAL; 1542cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1543064e0823SNamjae Jeon return -EINVAL; 1544064e0823SNamjae Jeon return 0; 154539a53e0cSJaegeuk Kim } 154639a53e0cSJaegeuk Kim 154739a53e0cSJaegeuk Kim /* 154839a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 154939a53e0cSJaegeuk Kim */ 155039a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 155139a53e0cSJaegeuk Kim { 15520eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 15530eb0adadSChao Yu 1554000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 155539a53e0cSJaegeuk Kim } 155639a53e0cSJaegeuk Kim 15574bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 15584bc8e9bcSChao Yu { 15594bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 15604bc8e9bcSChao Yu } 15614bc8e9bcSChao Yu 15620abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 15630abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 156446008c6dSChao Yu struct inode *inode, blkcnt_t *count) 156539a53e0cSJaegeuk Kim { 15660abd675eSChao Yu blkcnt_t diff = 0, release = 0; 1567daeb433eSChao Yu block_t avail_user_block_count; 15680abd675eSChao Yu int ret; 15690abd675eSChao Yu 15700abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 15710abd675eSChao Yu if (ret) 15720abd675eSChao Yu return ret; 1573dd11a5dfSJaegeuk Kim 1574cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 157555523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 157655523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 15770abd675eSChao Yu release = *count; 15780abd675eSChao Yu goto enospc; 157955523519SChao Yu } 1580cb78942bSJaegeuk Kim #endif 1581dd11a5dfSJaegeuk Kim /* 1582dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1583dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1584dd11a5dfSJaegeuk Kim */ 1585dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1586cfb271d4SChao Yu 158739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 15882555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 158980d42145SYunlong Song avail_user_block_count = sbi->user_block_count - 159080d42145SYunlong Song sbi->current_reserved_blocks; 1591daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1592daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 1593dd11a5dfSJaegeuk Kim *count -= diff; 15940abd675eSChao Yu release = diff; 1595daeb433eSChao Yu sbi->total_valid_block_count = avail_user_block_count; 159646008c6dSChao Yu if (!*count) { 159739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1598dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 15990abd675eSChao Yu goto enospc; 160039a53e0cSJaegeuk Kim } 160146008c6dSChao Yu } 160239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 160341382ec4SJaegeuk Kim 16040abd675eSChao Yu if (release) 16050abd675eSChao Yu dquot_release_reservation_block(inode, release); 16060abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 16070abd675eSChao Yu return 0; 16080abd675eSChao Yu 16090abd675eSChao Yu enospc: 16100abd675eSChao Yu dquot_release_reservation_block(inode, release); 16110abd675eSChao Yu return -ENOSPC; 161239a53e0cSJaegeuk Kim } 161339a53e0cSJaegeuk Kim 1614da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 161539a53e0cSJaegeuk Kim struct inode *inode, 16160eb0adadSChao Yu block_t count) 161739a53e0cSJaegeuk Kim { 16180eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 16190eb0adadSChao Yu 162039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 16219850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 16220eb0adadSChao Yu f2fs_bug_on(sbi, inode->i_blocks < sectors); 162339a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 162480d42145SYunlong Song if (sbi->reserved_blocks && 162580d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 162680d42145SYunlong Song sbi->current_reserved_blocks = min(sbi->reserved_blocks, 162780d42145SYunlong Song sbi->current_reserved_blocks + count); 162839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 16290abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 163039a53e0cSJaegeuk Kim } 163139a53e0cSJaegeuk Kim 163239a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 163339a53e0cSJaegeuk Kim { 163435782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 16357c4abcbeSChao Yu 163636951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 163736951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 16387c4abcbeSChao Yu return; 16397c4abcbeSChao Yu 1640caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 164139a53e0cSJaegeuk Kim } 164239a53e0cSJaegeuk Kim 1643a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 164439a53e0cSJaegeuk Kim { 1645204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1646c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1647c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 16482c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 16492c8a4a28SJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 165039a53e0cSJaegeuk Kim } 165139a53e0cSJaegeuk Kim 165239a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 165339a53e0cSJaegeuk Kim { 165435782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 165539a53e0cSJaegeuk Kim } 165639a53e0cSJaegeuk Kim 1657a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 165839a53e0cSJaegeuk Kim { 16595ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 16605ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 16611fe54f9dSJaegeuk Kim return; 16621fe54f9dSJaegeuk Kim 1663204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1664c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1665c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 16662c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 16672c8a4a28SJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 166839a53e0cSJaegeuk Kim } 166939a53e0cSJaegeuk Kim 1670523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 167139a53e0cSJaegeuk Kim { 167235782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 167339a53e0cSJaegeuk Kim } 167439a53e0cSJaegeuk Kim 1675204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1676f8b2c1f9SJaegeuk Kim { 1677204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1678f8b2c1f9SJaegeuk Kim } 1679f8b2c1f9SJaegeuk Kim 16805ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 16815ac206cfSNamjae Jeon { 16823519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1683523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1684523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1685523be8a6SJaegeuk Kim 1686523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 16875ac206cfSNamjae Jeon } 16885ac206cfSNamjae Jeon 168939a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 169039a53e0cSJaegeuk Kim { 16918b8343faSJaegeuk Kim return sbi->total_valid_block_count; 169239a53e0cSJaegeuk Kim } 169339a53e0cSJaegeuk Kim 1694f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1695f83a2584SYunlei He { 1696f83a2584SYunlei He return sbi->discard_blks; 1697f83a2584SYunlei He } 1698f83a2584SYunlei He 169939a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 170039a53e0cSJaegeuk Kim { 170139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 170239a53e0cSJaegeuk Kim 170339a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 170439a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 170539a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 170639a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 170739a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 170839a53e0cSJaegeuk Kim 170939a53e0cSJaegeuk Kim return 0; 171039a53e0cSJaegeuk Kim } 171139a53e0cSJaegeuk Kim 171255141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 171355141486SWanpeng Li { 171455141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 171555141486SWanpeng Li } 171655141486SWanpeng Li 171739a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 171839a53e0cSJaegeuk Kim { 171939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 17201dbe4152SChangman Lee int offset; 17211dbe4152SChangman Lee 172255141486SWanpeng Li if (__cp_payload(sbi) > 0) { 17231dbe4152SChangman Lee if (flag == NAT_BITMAP) 17241dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 17251dbe4152SChangman Lee else 172665b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 17271dbe4152SChangman Lee } else { 17281dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 172925ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 173039a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 173139a53e0cSJaegeuk Kim } 17321dbe4152SChangman Lee } 173339a53e0cSJaegeuk Kim 173439a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 173539a53e0cSJaegeuk Kim { 17368508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 173739a53e0cSJaegeuk Kim 17388508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 173939a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 174039a53e0cSJaegeuk Kim return start_addr; 174139a53e0cSJaegeuk Kim } 174239a53e0cSJaegeuk Kim 17438508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 17448508e44aSJaegeuk Kim { 17458508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 17468508e44aSJaegeuk Kim 17478508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 17488508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 17498508e44aSJaegeuk Kim return start_addr; 17508508e44aSJaegeuk Kim } 17518508e44aSJaegeuk Kim 17528508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 17538508e44aSJaegeuk Kim { 17548508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 17558508e44aSJaegeuk Kim } 17568508e44aSJaegeuk Kim 175739a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 175839a53e0cSJaegeuk Kim { 175939a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 176039a53e0cSJaegeuk Kim } 176139a53e0cSJaegeuk Kim 17620abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 1763000519f2SChao Yu struct inode *inode, bool is_inode) 176439a53e0cSJaegeuk Kim { 176539a53e0cSJaegeuk Kim block_t valid_block_count; 176639a53e0cSJaegeuk Kim unsigned int valid_node_count; 17670abd675eSChao Yu bool quota = inode && !is_inode; 17680abd675eSChao Yu 17690abd675eSChao Yu if (quota) { 17700abd675eSChao Yu int ret = dquot_reserve_block(inode, 1); 17710abd675eSChao Yu if (ret) 17720abd675eSChao Yu return ret; 17730abd675eSChao Yu } 177439a53e0cSJaegeuk Kim 1775812c6056SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 1776812c6056SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 1777812c6056SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 1778812c6056SChao Yu goto enospc; 1779812c6056SChao Yu } 1780812c6056SChao Yu #endif 1781812c6056SChao Yu 178239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 178339a53e0cSJaegeuk Kim 1784ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 178580d42145SYunlong Song if (unlikely(valid_block_count + sbi->current_reserved_blocks > 1786daeb433eSChao Yu sbi->user_block_count)) { 178739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17880abd675eSChao Yu goto enospc; 178939a53e0cSJaegeuk Kim } 179039a53e0cSJaegeuk Kim 1791ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1792cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 179339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17940abd675eSChao Yu goto enospc; 179539a53e0cSJaegeuk Kim } 179639a53e0cSJaegeuk Kim 1797ef86d709SGu Zheng sbi->total_valid_node_count++; 1798ef86d709SGu Zheng sbi->total_valid_block_count++; 179939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 180039a53e0cSJaegeuk Kim 18010abd675eSChao Yu if (inode) { 18020abd675eSChao Yu if (is_inode) 18030abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 18040abd675eSChao Yu else 18050abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 18060abd675eSChao Yu } 18070abd675eSChao Yu 180841382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 18090abd675eSChao Yu return 0; 18100abd675eSChao Yu 18110abd675eSChao Yu enospc: 18120abd675eSChao Yu if (quota) 18130abd675eSChao Yu dquot_release_reservation_block(inode, 1); 18140abd675eSChao Yu return -ENOSPC; 181539a53e0cSJaegeuk Kim } 181639a53e0cSJaegeuk Kim 181739a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1818000519f2SChao Yu struct inode *inode, bool is_inode) 181939a53e0cSJaegeuk Kim { 182039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 182139a53e0cSJaegeuk Kim 18229850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 18239850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 1824000519f2SChao Yu f2fs_bug_on(sbi, !is_inode && !inode->i_blocks); 182539a53e0cSJaegeuk Kim 1826ef86d709SGu Zheng sbi->total_valid_node_count--; 1827ef86d709SGu Zheng sbi->total_valid_block_count--; 182880d42145SYunlong Song if (sbi->reserved_blocks && 182980d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 183080d42145SYunlong Song sbi->current_reserved_blocks++; 183139a53e0cSJaegeuk Kim 183239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 18330abd675eSChao Yu 18340abd675eSChao Yu if (!is_inode) 18350abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 183639a53e0cSJaegeuk Kim } 183739a53e0cSJaegeuk Kim 183839a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 183939a53e0cSJaegeuk Kim { 18408b8343faSJaegeuk Kim return sbi->total_valid_node_count; 184139a53e0cSJaegeuk Kim } 184239a53e0cSJaegeuk Kim 184339a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 184439a53e0cSJaegeuk Kim { 1845513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 184639a53e0cSJaegeuk Kim } 184739a53e0cSJaegeuk Kim 18480e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 184939a53e0cSJaegeuk Kim { 1850513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 185139a53e0cSJaegeuk Kim } 185239a53e0cSJaegeuk Kim 1853513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 185439a53e0cSJaegeuk Kim { 1855513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 185639a53e0cSJaegeuk Kim } 185739a53e0cSJaegeuk Kim 1858a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1859a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1860a56c7c6fSJaegeuk Kim { 1861c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1862c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1863cac5a3d8SDongOh Shin 1864c41f3cc3SJaegeuk Kim if (page) 1865c41f3cc3SJaegeuk Kim return page; 1866c41f3cc3SJaegeuk Kim 186755523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 186855523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1869c41f3cc3SJaegeuk Kim return NULL; 187055523519SChao Yu } 1871c41f3cc3SJaegeuk Kim #endif 1872a56c7c6fSJaegeuk Kim if (!for_write) 1873a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1874a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1875a56c7c6fSJaegeuk Kim } 1876a56c7c6fSJaegeuk Kim 187701eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page( 187801eccef7SChao Yu struct address_space *mapping, pgoff_t index, 187901eccef7SChao Yu int fgp_flags, gfp_t gfp_mask) 188001eccef7SChao Yu { 188101eccef7SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 188201eccef7SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { 188301eccef7SChao Yu f2fs_show_injection_info(FAULT_PAGE_GET); 188401eccef7SChao Yu return NULL; 188501eccef7SChao Yu } 188601eccef7SChao Yu #endif 188701eccef7SChao Yu return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); 188801eccef7SChao Yu } 188901eccef7SChao Yu 18906e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 18916e2c64adSJaegeuk Kim { 18926e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 18936e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 18946e2c64adSJaegeuk Kim 18956e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 18966e2c64adSJaegeuk Kim kunmap(dst); 18976e2c64adSJaegeuk Kim kunmap(src); 18986e2c64adSJaegeuk Kim } 18996e2c64adSJaegeuk Kim 190039a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 190139a53e0cSJaegeuk Kim { 1902031fa8ccSJaegeuk Kim if (!page) 190339a53e0cSJaegeuk Kim return; 190439a53e0cSJaegeuk Kim 190539a53e0cSJaegeuk Kim if (unlock) { 19069850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 190739a53e0cSJaegeuk Kim unlock_page(page); 190839a53e0cSJaegeuk Kim } 190909cbfeafSKirill A. Shutemov put_page(page); 191039a53e0cSJaegeuk Kim } 191139a53e0cSJaegeuk Kim 191239a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 191339a53e0cSJaegeuk Kim { 191439a53e0cSJaegeuk Kim if (dn->node_page) 191539a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 191639a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 191739a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 191839a53e0cSJaegeuk Kim dn->node_page = NULL; 191939a53e0cSJaegeuk Kim dn->inode_page = NULL; 192039a53e0cSJaegeuk Kim } 192139a53e0cSJaegeuk Kim 192239a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1923e8512d2eSGu Zheng size_t size) 192439a53e0cSJaegeuk Kim { 1925e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 192639a53e0cSJaegeuk Kim } 192739a53e0cSJaegeuk Kim 19287bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 19297bd59381SGu Zheng gfp_t flags) 19307bd59381SGu Zheng { 19317bd59381SGu Zheng void *entry; 19327bd59381SGu Zheng 193380c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 193480c54505SJaegeuk Kim if (!entry) 193580c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 19367bd59381SGu Zheng return entry; 19377bd59381SGu Zheng } 19387bd59381SGu Zheng 1939d62fe971SChao Yu static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, 1940d62fe971SChao Yu int npages, bool no_fail) 1941740432f8SJaegeuk Kim { 1942740432f8SJaegeuk Kim struct bio *bio; 1943740432f8SJaegeuk Kim 1944d62fe971SChao Yu if (no_fail) { 1945740432f8SJaegeuk Kim /* No failure on bio allocation */ 1946740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 194780c54505SJaegeuk Kim if (!bio) 194880c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1949740432f8SJaegeuk Kim return bio; 1950740432f8SJaegeuk Kim } 1951d62fe971SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 1952d62fe971SChao Yu if (time_to_inject(sbi, FAULT_ALLOC_BIO)) { 1953d62fe971SChao Yu f2fs_show_injection_info(FAULT_ALLOC_BIO); 1954d62fe971SChao Yu return NULL; 1955d62fe971SChao Yu } 1956d62fe971SChao Yu #endif 1957d62fe971SChao Yu return bio_alloc(GFP_KERNEL, npages); 1958d62fe971SChao Yu } 1959740432f8SJaegeuk Kim 19609be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 19619be32d72SJaegeuk Kim unsigned long index, void *item) 19629be32d72SJaegeuk Kim { 19639be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 19649be32d72SJaegeuk Kim cond_resched(); 19659be32d72SJaegeuk Kim } 19669be32d72SJaegeuk Kim 196739a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 196839a53e0cSJaegeuk Kim 196939a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 197039a53e0cSJaegeuk Kim { 197145590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1972cac5a3d8SDongOh Shin 197339a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 197439a53e0cSJaegeuk Kim } 197539a53e0cSJaegeuk Kim 19767a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 19777a2af766SChao Yu { 19787a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 19797a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 19807a2af766SChao Yu } 19817a2af766SChao Yu 198239a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 198339a53e0cSJaegeuk Kim { 198439a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 198539a53e0cSJaegeuk Kim } 198639a53e0cSJaegeuk Kim 19877a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 19887a2af766SChao Yu static inline block_t datablock_addr(struct inode *inode, 19897a2af766SChao Yu struct page *node_page, unsigned int offset) 199039a53e0cSJaegeuk Kim { 199139a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 199239a53e0cSJaegeuk Kim __le32 *addr_array; 19937a2af766SChao Yu int base = 0; 19947a2af766SChao Yu bool is_inode = IS_INODE(node_page); 1995cac5a3d8SDongOh Shin 199645590710SGu Zheng raw_node = F2FS_NODE(node_page); 19977a2af766SChao Yu 19987a2af766SChao Yu /* from GC path only */ 1999979f492fSLiFan if (is_inode) { 2000979f492fSLiFan if (!inode) 20017a2af766SChao Yu base = offset_in_addr(&raw_node->i); 2002979f492fSLiFan else if (f2fs_has_extra_attr(inode)) 20037a2af766SChao Yu base = get_extra_isize(inode); 20047a2af766SChao Yu } 20057a2af766SChao Yu 200639a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 20077a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 200839a53e0cSJaegeuk Kim } 200939a53e0cSJaegeuk Kim 201039a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 201139a53e0cSJaegeuk Kim { 201239a53e0cSJaegeuk Kim int mask; 201339a53e0cSJaegeuk Kim 201439a53e0cSJaegeuk Kim addr += (nr >> 3); 201539a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 201639a53e0cSJaegeuk Kim return mask & *addr; 201739a53e0cSJaegeuk Kim } 201839a53e0cSJaegeuk Kim 2019a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 2020a66cdd98SJaegeuk Kim { 2021a66cdd98SJaegeuk Kim int mask; 2022a66cdd98SJaegeuk Kim 2023a66cdd98SJaegeuk Kim addr += (nr >> 3); 2024a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2025a66cdd98SJaegeuk Kim *addr |= mask; 2026a66cdd98SJaegeuk Kim } 2027a66cdd98SJaegeuk Kim 2028a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 2029a66cdd98SJaegeuk Kim { 2030a66cdd98SJaegeuk Kim int mask; 2031a66cdd98SJaegeuk Kim 2032a66cdd98SJaegeuk Kim addr += (nr >> 3); 2033a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2034a66cdd98SJaegeuk Kim *addr &= ~mask; 2035a66cdd98SJaegeuk Kim } 2036a66cdd98SJaegeuk Kim 203752aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 203839a53e0cSJaegeuk Kim { 203939a53e0cSJaegeuk Kim int mask; 204039a53e0cSJaegeuk Kim int ret; 204139a53e0cSJaegeuk Kim 204239a53e0cSJaegeuk Kim addr += (nr >> 3); 204339a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 204439a53e0cSJaegeuk Kim ret = mask & *addr; 204539a53e0cSJaegeuk Kim *addr |= mask; 204639a53e0cSJaegeuk Kim return ret; 204739a53e0cSJaegeuk Kim } 204839a53e0cSJaegeuk Kim 204952aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 205039a53e0cSJaegeuk Kim { 205139a53e0cSJaegeuk Kim int mask; 205239a53e0cSJaegeuk Kim int ret; 205339a53e0cSJaegeuk Kim 205439a53e0cSJaegeuk Kim addr += (nr >> 3); 205539a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 205639a53e0cSJaegeuk Kim ret = mask & *addr; 205739a53e0cSJaegeuk Kim *addr &= ~mask; 205839a53e0cSJaegeuk Kim return ret; 205939a53e0cSJaegeuk Kim } 206039a53e0cSJaegeuk Kim 2061c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 2062c6ac4c0eSGu Zheng { 2063c6ac4c0eSGu Zheng int mask; 2064c6ac4c0eSGu Zheng 2065c6ac4c0eSGu Zheng addr += (nr >> 3); 2066c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 2067c6ac4c0eSGu Zheng *addr ^= mask; 2068c6ac4c0eSGu Zheng } 2069c6ac4c0eSGu Zheng 20705c57132eSChao Yu #define F2FS_REG_FLMASK (~(FS_DIRSYNC_FL | FS_TOPDIR_FL)) 20715c57132eSChao Yu #define F2FS_OTHER_FLMASK (FS_NODUMP_FL | FS_NOATIME_FL) 20725c57132eSChao Yu #define F2FS_FL_INHERITED (FS_PROJINHERIT_FL) 20735c57132eSChao Yu 20745c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 20755c57132eSChao Yu { 20765c57132eSChao Yu if (S_ISDIR(mode)) 20775c57132eSChao Yu return flags; 20785c57132eSChao Yu else if (S_ISREG(mode)) 20795c57132eSChao Yu return flags & F2FS_REG_FLMASK; 20805c57132eSChao Yu else 20815c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 20825c57132eSChao Yu } 20835c57132eSChao Yu 208439a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 208539a53e0cSJaegeuk Kim enum { 208639a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 2087b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 208826de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 2089ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 209039a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 209139a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 209239a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 2093c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 2094c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 2095444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 20961001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 209734d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 2098fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 2099fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 210088b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 210188b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 21025fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 210302a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 21043c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 21051e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 2106b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 2107510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 2108d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 2109c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 2110dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 2111ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 21127a2af766SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 21135c57132eSChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 211439a53e0cSJaegeuk Kim }; 211539a53e0cSJaegeuk Kim 2116205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2117205b9822SJaegeuk Kim int flag, bool set) 211839a53e0cSJaegeuk Kim { 2119205b9822SJaegeuk Kim switch (flag) { 2120205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2121205b9822SJaegeuk Kim case FI_INLINE_DATA: 2122205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 2123205b9822SJaegeuk Kim if (set) 2124205b9822SJaegeuk Kim return; 2125205b9822SJaegeuk Kim case FI_DATA_EXIST: 2126205b9822SJaegeuk Kim case FI_INLINE_DOTS: 21277c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2128205b9822SJaegeuk Kim } 212939a53e0cSJaegeuk Kim } 213039a53e0cSJaegeuk Kim 213191942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 213239a53e0cSJaegeuk Kim { 213391942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 213491942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 2135205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 213639a53e0cSJaegeuk Kim } 213739a53e0cSJaegeuk Kim 213891942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 213939a53e0cSJaegeuk Kim { 214091942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 214139a53e0cSJaegeuk Kim } 214239a53e0cSJaegeuk Kim 214391942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 214439a53e0cSJaegeuk Kim { 214591942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 214691942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 2147205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 214839a53e0cSJaegeuk Kim } 214939a53e0cSJaegeuk Kim 215091942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2151444c580fSJaegeuk Kim { 215291942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 215391942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 21547c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 215539a53e0cSJaegeuk Kim } 215639a53e0cSJaegeuk Kim 2157a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2158a1961246SJaegeuk Kim { 2159a1961246SJaegeuk Kim if (inc) 2160a1961246SJaegeuk Kim inc_nlink(inode); 2161a1961246SJaegeuk Kim else 2162a1961246SJaegeuk Kim drop_nlink(inode); 21637c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2164a1961246SJaegeuk Kim } 2165a1961246SJaegeuk Kim 21668edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 21670abd675eSChao Yu block_t diff, bool add, bool claim) 21688edd03c8SJaegeuk Kim { 216926de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 217026de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 217126de9b11SJaegeuk Kim 21720abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 21730abd675eSChao Yu if (add) { 21740abd675eSChao Yu if (claim) 21750abd675eSChao Yu dquot_claim_block(inode, diff); 21760abd675eSChao Yu else 21770abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 21780abd675eSChao Yu } else { 21790abd675eSChao Yu dquot_free_block(inode, diff); 21800abd675eSChao Yu } 21810abd675eSChao Yu 21827c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 218326de9b11SJaegeuk Kim if (clean || recover) 218426de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 21858edd03c8SJaegeuk Kim } 21868edd03c8SJaegeuk Kim 2187fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2188fc9581c8SJaegeuk Kim { 218926de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 219026de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 219126de9b11SJaegeuk Kim 2192fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2193fc9581c8SJaegeuk Kim return; 2194fc9581c8SJaegeuk Kim 2195fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 21967c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 219726de9b11SJaegeuk Kim if (clean || recover) 219826de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 219926de9b11SJaegeuk Kim } 220026de9b11SJaegeuk Kim 2201205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2202205b9822SJaegeuk Kim { 2203205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 22047c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2205205b9822SJaegeuk Kim } 2206205b9822SJaegeuk Kim 2207205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2208205b9822SJaegeuk Kim { 2209205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 22107c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2211205b9822SJaegeuk Kim } 2212205b9822SJaegeuk Kim 2213205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2214205b9822SJaegeuk Kim { 2215205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 22167c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2217205b9822SJaegeuk Kim } 2218205b9822SJaegeuk Kim 221991942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2220444c580fSJaegeuk Kim { 2221205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2222205b9822SJaegeuk Kim 2223444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 2224205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 22251001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 2226205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 222734d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 2228205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 2229b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 2230205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 2231510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 2232205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 22337a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 22347a2af766SChao Yu set_bit(FI_EXTRA_ATTR, &fi->flags); 2235444c580fSJaegeuk Kim } 2236444c580fSJaegeuk Kim 223791942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2238444c580fSJaegeuk Kim { 2239444c580fSJaegeuk Kim ri->i_inline = 0; 2240444c580fSJaegeuk Kim 224191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2242444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 224391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 22441001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 224591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 224634d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 224791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2248b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 224991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2250510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 22517a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 22527a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 22537a2af766SChao Yu } 22547a2af766SChao Yu 22557a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 22567a2af766SChao Yu { 22577a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2258444c580fSJaegeuk Kim } 2259444c580fSJaegeuk Kim 2260987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2261987c7c31SChao Yu { 226291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2263987c7c31SChao Yu } 2264987c7c31SChao Yu 226581ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2266de93653fSJaegeuk Kim { 22676afc662eSChao Yu return CUR_ADDRS_PER_INODE(inode) - F2FS_INLINE_XATTR_ADDRS(inode); 2268de93653fSJaegeuk Kim } 2269de93653fSJaegeuk Kim 22706afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page) 227165985d93SJaegeuk Kim { 2272695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2273cac5a3d8SDongOh Shin 227465985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 22756afc662eSChao Yu F2FS_INLINE_XATTR_ADDRS(inode)]); 227665985d93SJaegeuk Kim } 227765985d93SJaegeuk Kim 227865985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 227965985d93SJaegeuk Kim { 22806afc662eSChao Yu return get_inline_xattr_addrs(inode) * sizeof(__le32); 228165985d93SJaegeuk Kim } 228265985d93SJaegeuk Kim 22830dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 22840dbdc2aeSJaegeuk Kim { 228591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 22860dbdc2aeSJaegeuk Kim } 22870dbdc2aeSJaegeuk Kim 2288b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2289b3d208f9SJaegeuk Kim { 229091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2291b3d208f9SJaegeuk Kim } 2292b3d208f9SJaegeuk Kim 2293510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2294510022a8SJaegeuk Kim { 229591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2296510022a8SJaegeuk Kim } 2297510022a8SJaegeuk Kim 229888b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 229988b88a66SJaegeuk Kim { 230091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 230188b88a66SJaegeuk Kim } 230288b88a66SJaegeuk Kim 23035fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 23045fe45743SChao Yu { 23055fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 23065fe45743SChao Yu } 23075fe45743SChao Yu 230802a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 230902a1335fSJaegeuk Kim { 231091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 231102a1335fSJaegeuk Kim } 231202a1335fSJaegeuk Kim 23133c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 23143c6c2bebSJaegeuk Kim { 231591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 23163c6c2bebSJaegeuk Kim } 23173c6c2bebSJaegeuk Kim 23181e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 23191e84371fSJaegeuk Kim { 232091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 23211e84371fSJaegeuk Kim } 23221e84371fSJaegeuk Kim 2323f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 23241001b347SHuajun Li { 2325695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 23267a2af766SChao Yu int extra_size = get_extra_isize(inode); 2327cac5a3d8SDongOh Shin 23287a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 23291001b347SHuajun Li } 23301001b347SHuajun Li 233134d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 233234d67debSChao Yu { 233391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 233434d67debSChao Yu } 233534d67debSChao Yu 23369486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 23379486ba44SJaegeuk Kim { 23389486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 23399486ba44SJaegeuk Kim kunmap(page); 23409486ba44SJaegeuk Kim } 23419486ba44SJaegeuk Kim 2342b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2343b5492af7SJaegeuk Kim { 2344b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2345b5492af7SJaegeuk Kim } 2346b5492af7SJaegeuk Kim 2347b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2348b5492af7SJaegeuk Kim { 2349b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 23507c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2351b5492af7SJaegeuk Kim } 2352b5492af7SJaegeuk Kim 2353b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2354b5492af7SJaegeuk Kim { 2355b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 23567c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2357b5492af7SJaegeuk Kim } 2358b5492af7SJaegeuk Kim 235926787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 236026787236SJaegeuk Kim { 2361a0d00fadSChao Yu bool ret; 2362a0d00fadSChao Yu 236326787236SJaegeuk Kim if (dsync) { 236426787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 236526787236SJaegeuk Kim 236626787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 236726787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 236826787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 236926787236SJaegeuk Kim return ret; 237026787236SJaegeuk Kim } 237126787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 237226787236SJaegeuk Kim file_keep_isize(inode) || 237326787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 237426787236SJaegeuk Kim return false; 2375a0d00fadSChao Yu 2376a0d00fadSChao Yu down_read(&F2FS_I(inode)->i_sem); 2377a0d00fadSChao Yu ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 2378a0d00fadSChao Yu up_read(&F2FS_I(inode)->i_sem); 2379a0d00fadSChao Yu 2380a0d00fadSChao Yu return ret; 2381267378d4SChao Yu } 2382267378d4SChao Yu 2383267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 2384267378d4SChao Yu { 23851751e8a6SLinus Torvalds return sb->s_flags & SB_RDONLY; 238677888c1eSJaegeuk Kim } 238777888c1eSJaegeuk Kim 2388744602cfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 2389744602cfSJaegeuk Kim { 2390aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 2391744602cfSJaegeuk Kim } 2392744602cfSJaegeuk Kim 2393eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2394eaa693f4SJaegeuk Kim { 2395eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2396eaa693f4SJaegeuk Kim return true; 2397eaa693f4SJaegeuk Kim 2398eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2399eaa693f4SJaegeuk Kim return true; 2400eaa693f4SJaegeuk Kim 2401eaa693f4SJaegeuk Kim return false; 2402eaa693f4SJaegeuk Kim } 2403eaa693f4SJaegeuk Kim 24043e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 24053e72f721SJaegeuk Kim { 24063e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 240791942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 24083e72f721SJaegeuk Kim return false; 24093e72f721SJaegeuk Kim 2410886f56f9SAl Viro return S_ISREG(inode->i_mode); 24113e72f721SJaegeuk Kim } 24123e72f721SJaegeuk Kim 24131ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 24141ecc0c5cSChao Yu size_t size, gfp_t flags) 24150414b004SJaegeuk Kim { 24162c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 241755523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 241855523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 24192c63feadSJaegeuk Kim return NULL; 242055523519SChao Yu } 24212c63feadSJaegeuk Kim #endif 24220414b004SJaegeuk Kim return kmalloc(size, flags); 24230414b004SJaegeuk Kim } 24240414b004SJaegeuk Kim 2425*acbf054dSChao Yu static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, 2426*acbf054dSChao Yu size_t size, gfp_t flags) 2427*acbf054dSChao Yu { 2428*acbf054dSChao Yu return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); 2429*acbf054dSChao Yu } 2430*acbf054dSChao Yu 24317a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 2432f2470371SChao Yu { 24337a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 2434f2470371SChao Yu } 2435f2470371SChao Yu 24366afc662eSChao Yu static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb); 24376afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode) 24386afc662eSChao Yu { 24396afc662eSChao Yu return F2FS_I(inode)->i_inline_xattr_size; 24406afc662eSChao Yu } 24416afc662eSChao Yu 2442a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 244391942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 2444a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 2445a6dda0e6SChristoph Hellwig 24467a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 24477a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 24487a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 24497a2af766SChao Yu 24505c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 24515c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 24525c57132eSChao Yu ((offsetof(typeof(*f2fs_inode), field) + \ 24535c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 24545c57132eSChao Yu <= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize)) \ 24555c57132eSChao Yu 2456b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 2457b0af6d49SChao Yu { 2458b0af6d49SChao Yu int i; 2459b0af6d49SChao Yu 2460b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2461b0af6d49SChao Yu for (i = 0; i < NR_IO_TYPE; i++) 2462b0af6d49SChao Yu sbi->write_iostat[i] = 0; 2463b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2464b0af6d49SChao Yu } 2465b0af6d49SChao Yu 2466b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 2467b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 2468b0af6d49SChao Yu { 2469b0af6d49SChao Yu if (!sbi->iostat_enable) 2470b0af6d49SChao Yu return; 2471b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2472b0af6d49SChao Yu sbi->write_iostat[type] += io_bytes; 2473b0af6d49SChao Yu 2474b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 2475b0af6d49SChao Yu sbi->write_iostat[APP_BUFFERED_IO] = 2476b0af6d49SChao Yu sbi->write_iostat[APP_WRITE_IO] - 2477b0af6d49SChao Yu sbi->write_iostat[APP_DIRECT_IO]; 2478b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2479b0af6d49SChao Yu } 2480b0af6d49SChao Yu 248139a53e0cSJaegeuk Kim /* 248239a53e0cSJaegeuk Kim * file.c 248339a53e0cSJaegeuk Kim */ 2484cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2485cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2486cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2487cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2488a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2489a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2490cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2491cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2492cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2493cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2494cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 249539a53e0cSJaegeuk Kim 249639a53e0cSJaegeuk Kim /* 249739a53e0cSJaegeuk Kim * inode.c 249839a53e0cSJaegeuk Kim */ 2499cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2500704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 2501704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 2502cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2503cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2504cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2505cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2506cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2507cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2508cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2509cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 251039a53e0cSJaegeuk Kim 251139a53e0cSJaegeuk Kim /* 251239a53e0cSJaegeuk Kim * namei.c 251339a53e0cSJaegeuk Kim */ 251439a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 251539a53e0cSJaegeuk Kim 251639a53e0cSJaegeuk Kim /* 251739a53e0cSJaegeuk Kim * dir.c 251839a53e0cSJaegeuk Kim */ 2519cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2520cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2521cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2522cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2523cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2524cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2525cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2526cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2527cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2528cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2529cac5a3d8SDongOh Shin const struct qstr *new_name, 2530cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2531cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2532cac5a3d8SDongOh Shin unsigned int current_depth); 2533cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2534cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2535cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2536cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2537cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2538cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2539cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2540cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2541cac5a3d8SDongOh Shin struct page **page); 2542cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2543cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2544cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2545cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2546cac5a3d8SDongOh Shin unsigned int bit_pos); 2547cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2548cac5a3d8SDongOh Shin const struct qstr *orig_name, 2549cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2550cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2551cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2552cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2553cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2554cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2555cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2556cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2557cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 255839a53e0cSJaegeuk Kim 2559b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2560b7f7a5e0SAl Viro { 25612b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2562510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2563b7f7a5e0SAl Viro } 2564b7f7a5e0SAl Viro 256539a53e0cSJaegeuk Kim /* 256639a53e0cSJaegeuk Kim * super.c 256739a53e0cSJaegeuk Kim */ 2568cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2569cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2570ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); 25714b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 2572cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2573cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2574a07ef784SNamjae Jeon extern __printf(3, 4) 2575cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2576984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 257739a53e0cSJaegeuk Kim 257839a53e0cSJaegeuk Kim /* 257939a53e0cSJaegeuk Kim * hash.c 258039a53e0cSJaegeuk Kim */ 25816332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, 25826332cd32SJaegeuk Kim struct fscrypt_name *fname); 258339a53e0cSJaegeuk Kim 258439a53e0cSJaegeuk Kim /* 258539a53e0cSJaegeuk Kim * node.c 258639a53e0cSJaegeuk Kim */ 258739a53e0cSJaegeuk Kim struct dnode_of_data; 258839a53e0cSJaegeuk Kim struct node_info; 258939a53e0cSJaegeuk Kim 2590cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2591cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2592cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2593cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2594cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2595cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2596cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2597cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 25989c77f754SJaegeuk Kim int truncate_xattr_node(struct inode *inode); 2599cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2600cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2601cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 26025f4ce6abSYunlei He struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs); 2603cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2604cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2605cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2606cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2607cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2608cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2609401db79fSYunlong Song int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc, 2610b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 261122ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2612cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2613cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2614cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2615cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2616cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2617e17d488bSSheng Yong int recover_xattr_data(struct inode *inode, struct page *page); 2618cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2619cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2620cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 262122ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2622cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2623cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 26246e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 262539a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 262639a53e0cSJaegeuk Kim 262739a53e0cSJaegeuk Kim /* 262839a53e0cSJaegeuk Kim * segment.c 262939a53e0cSJaegeuk Kim */ 2630b3a97a2aSJaegeuk Kim bool need_SSR(struct f2fs_sb_info *sbi); 2631cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 263257864ae5SJaegeuk Kim void drop_inmem_pages_all(struct f2fs_sb_info *sbi); 2633cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 26348c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2635cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2636cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2637cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 263839d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 2639cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 26401228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); 2641cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2642cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2643cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 264478997b56SChao Yu void init_discard_policy(struct discard_policy *dpolicy, int discard_type, 264578997b56SChao Yu unsigned int granularity); 2646cce13252SChao Yu void stop_discard_thread(struct f2fs_sb_info *sbi); 2647cf5c759fSChao Yu bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2648cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2649cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2650cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2651cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2652cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2653cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2654cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2655cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2656b0af6d49SChao Yu void write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 2657b0af6d49SChao Yu enum iostat_type io_type); 2658cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2659cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2660d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2661cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2662cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2663cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2664cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2665cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2666cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2667cac5a3d8SDongOh Shin bool recover_newaddr); 2668cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2669cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2670fb830fc5SChao Yu struct f2fs_summary *sum, int type, 2671fb830fc5SChao Yu struct f2fs_io_info *fio, bool add_list); 2672cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2673cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2674d4c759eeSJaegeuk Kim void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr); 2675cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2676cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2677cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2678cac5a3d8SDongOh Shin unsigned int val, int alloc); 2679cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2680cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2681cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 26827fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 26837fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 2684d5097be5SHyunchul Lee int rw_hint_to_seg_type(enum rw_hint hint); 268539a53e0cSJaegeuk Kim 268639a53e0cSJaegeuk Kim /* 268739a53e0cSJaegeuk Kim * checkpoint.c 268839a53e0cSJaegeuk Kim */ 2689cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2690cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2691cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2692cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2693cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2694cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2695cac5a3d8SDongOh Shin int type, bool sync); 2696cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2697cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2698b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 2699cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2700cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2701cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2702cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 270339d787beSChao Yu void set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 270439d787beSChao Yu unsigned int devidx, int type); 270539d787beSChao Yu bool is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 270639d787beSChao Yu unsigned int devidx, int type); 2707cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2708cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2709cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2710cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2711cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2712cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2713cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2714cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2715cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2716cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2717cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2718cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 27196e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 272039a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 272139a53e0cSJaegeuk Kim 272239a53e0cSJaegeuk Kim /* 272339a53e0cSJaegeuk Kim * data.c 272439a53e0cSJaegeuk Kim */ 2725b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 2726b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 2727942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2728b9109b0eSJaegeuk Kim enum page_type type); 2729b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 2730cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2731b9109b0eSJaegeuk Kim int f2fs_submit_page_write(struct f2fs_io_info *fio); 2732cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2733cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2734cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2735cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2736cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2737cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2738cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2739cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2740cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2741cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2742cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2743cac5a3d8SDongOh Shin int op_flags, bool for_write); 2744cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2745cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2746cac5a3d8SDongOh Shin bool for_write); 2747cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2748cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2749cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2750cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2751cac5a3d8SDongOh Shin int create, int flag); 2752cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2753cac5a3d8SDongOh Shin u64 start, u64 len); 2754cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2755b0af6d49SChao Yu int __f2fs_write_data_pages(struct address_space *mapping, 2756b0af6d49SChao Yu struct writeback_control *wbc, 2757b0af6d49SChao Yu enum iostat_type io_type); 2758cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2759cac5a3d8SDongOh Shin unsigned int length); 2760cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 27615b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2762cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2763cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 27645b7a487cSWeichao Guo #endif 276539a53e0cSJaegeuk Kim 276639a53e0cSJaegeuk Kim /* 276739a53e0cSJaegeuk Kim * gc.c 276839a53e0cSJaegeuk Kim */ 2769cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2770cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2771cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2772e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 2773e066b83cSJaegeuk Kim unsigned int segno); 2774cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 277539a53e0cSJaegeuk Kim 277639a53e0cSJaegeuk Kim /* 277739a53e0cSJaegeuk Kim * recovery.c 277839a53e0cSJaegeuk Kim */ 2779cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2780cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 278139a53e0cSJaegeuk Kim 278239a53e0cSJaegeuk Kim /* 278339a53e0cSJaegeuk Kim * debug.c 278439a53e0cSJaegeuk Kim */ 278539a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 278639a53e0cSJaegeuk Kim struct f2fs_stat_info { 278739a53e0cSJaegeuk Kim struct list_head stat_list; 278839a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 278939a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 279039a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 27915b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 27925b7ee374SChao Yu unsigned long long hit_total, total_ext; 2793c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 27942c8a4a28SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; 27952c8a4a28SJaegeuk Kim int ndirty_data, ndirty_qdata; 279635782b23SJaegeuk Kim int inmem_pages; 27972c8a4a28SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; 27985b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 27995b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 280039a53e0cSJaegeuk Kim int total_count, utilization; 28018b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 280214d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 280314d8d5f7SChao Yu int nr_discarding, nr_discarded; 28045f32366aSChao Yu int nr_discard_cmd; 2805d84d1cbdSChao Yu unsigned int undiscard_blks; 2806a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2807648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2808f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 280939a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 281039a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 281139a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 281239a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 281342190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 281439a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2815e1235983SChangman Lee int bg_node_segs, bg_data_segs; 281639a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2817e1235983SChangman Lee int bg_data_blks, bg_node_blks; 281839a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 281939a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 282039a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 282139a53e0cSJaegeuk Kim 282239a53e0cSJaegeuk Kim unsigned int segment_count[2]; 282339a53e0cSJaegeuk Kim unsigned int block_count[2]; 2824b9a2c252SChangman Lee unsigned int inplace_count; 28259edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 282639a53e0cSJaegeuk Kim }; 282739a53e0cSJaegeuk Kim 2828963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2829963d4f7dSGu Zheng { 2830963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2831963d4f7dSGu Zheng } 2832963d4f7dSGu Zheng 2833942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 283442190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 283539a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2836dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 283733fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 283833fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 28395b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 28405b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 28415b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 28425b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2843d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2844d5e8f6c9SChao Yu do { \ 2845d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2846d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2847d5e8f6c9SChao Yu } while (0) 2848d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2849d5e8f6c9SChao Yu do { \ 2850d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2851d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2852d5e8f6c9SChao Yu } while (0) 28530dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 28540dbdc2aeSJaegeuk Kim do { \ 28550dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 285603e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 28570dbdc2aeSJaegeuk Kim } while (0) 28580dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 28590dbdc2aeSJaegeuk Kim do { \ 28600dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 286103e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 28620dbdc2aeSJaegeuk Kim } while (0) 28633289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 28643289c061SJaegeuk Kim do { \ 28653289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 286603e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 28673289c061SJaegeuk Kim } while (0) 28683289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 28693289c061SJaegeuk Kim do { \ 28703289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 287103e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 28723289c061SJaegeuk Kim } while (0) 2873dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2874dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2875dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2876dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2877b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2878b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 287926a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2880cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 288126a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2882cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 288326a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 288426a28a0cSJaegeuk Kim do { \ 288526a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 288626a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 288726a28a0cSJaegeuk Kim if (cur > max) \ 288826a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 288926a28a0cSJaegeuk Kim } while (0) 2890648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2891648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2892648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2893648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2894648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2895648d50baSChao Yu do { \ 2896648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2897648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2898648d50baSChao Yu if (cur > max) \ 2899648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2900648d50baSChao Yu } while (0) 2901e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 290239a53e0cSJaegeuk Kim do { \ 2903963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 290468afcf2dSTomohiro Kusumi si->tot_segs++; \ 290568afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 290639a53e0cSJaegeuk Kim si->data_segs++; \ 2907e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2908e1235983SChangman Lee } else { \ 290939a53e0cSJaegeuk Kim si->node_segs++; \ 2910e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2911e1235983SChangman Lee } \ 291239a53e0cSJaegeuk Kim } while (0) 291339a53e0cSJaegeuk Kim 291439a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 291568afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 291639a53e0cSJaegeuk Kim 2917e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 291839a53e0cSJaegeuk Kim do { \ 2919963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 292039a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 292139a53e0cSJaegeuk Kim si->data_blks += (blks); \ 292268afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 292339a53e0cSJaegeuk Kim } while (0) 292439a53e0cSJaegeuk Kim 2925e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 292639a53e0cSJaegeuk Kim do { \ 2927963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 292839a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 292939a53e0cSJaegeuk Kim si->node_blks += (blks); \ 293068afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 293139a53e0cSJaegeuk Kim } while (0) 293239a53e0cSJaegeuk Kim 2933cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2934cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2935787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 29364589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 293739a53e0cSJaegeuk Kim #else 2938d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 2939d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 2940d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 2941d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 2942d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 2943d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 2944d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 2945d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 2946d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 2947d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 2948d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 2949d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 2950d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 2951d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 2952d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 2953d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 2954d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 2955d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 2956d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 2957d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 2958d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 2959d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 2960d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 2961d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 2962d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 2963d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 2964d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 2965d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 2966d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 296739a53e0cSJaegeuk Kim 296839a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 296939a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2970787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 29714589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 297239a53e0cSJaegeuk Kim #endif 297339a53e0cSJaegeuk Kim 297439a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 297539a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 297639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 297739a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 297839a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 297939a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 298039a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 298139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2982cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 298339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 298429e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 29851001b347SHuajun Li 2986e18c65b2SHuajun Li /* 2987e18c65b2SHuajun Li * inline.c 2988e18c65b2SHuajun Li */ 2989cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2990cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2991cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2992bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2993cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2994cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2995cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2996cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2997cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2998cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2999cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 3000cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 3001cac5a3d8SDongOh Shin struct page *ipage); 3002cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 3003cac5a3d8SDongOh Shin const struct qstr *orig_name, 3004cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 3005cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 3006cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 3007cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 3008cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 3009cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 3010cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 3011cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 3012cac5a3d8SDongOh Shin __u64 start, __u64 len); 3013cde4de12SJaegeuk Kim 3014cde4de12SJaegeuk Kim /* 30152658e50dSJaegeuk Kim * shrinker.c 30162658e50dSJaegeuk Kim */ 3017cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 3018cac5a3d8SDongOh Shin struct shrink_control *sc); 3019cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 3020cac5a3d8SDongOh Shin struct shrink_control *sc); 3021cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 3022cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 30232658e50dSJaegeuk Kim 30242658e50dSJaegeuk Kim /* 3025a28ef1f5SChao Yu * extent_cache.c 3026a28ef1f5SChao Yu */ 3027004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 3028004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 3029004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 3030004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 3031004b6862SChao Yu unsigned int ofs); 3032004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 3033004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 3034004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 3035004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 3036004b6862SChao Yu bool force); 3037df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi, 3038df0f6b44SChao Yu struct rb_root *root); 3039cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 3040cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 3041cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 3042cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 3043cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 3044cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 3045cac5a3d8SDongOh Shin struct extent_info *ei); 3046cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 304719b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 3048cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 3049cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 3050a28ef1f5SChao Yu int __init create_extent_cache(void); 3051a28ef1f5SChao Yu void destroy_extent_cache(void); 3052a28ef1f5SChao Yu 3053a28ef1f5SChao Yu /* 30548ceffcb2SChao Yu * sysfs.c 30558ceffcb2SChao Yu */ 3056dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 3057dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 3058dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 3059dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 30608ceffcb2SChao Yu 30618ceffcb2SChao Yu /* 3062cde4de12SJaegeuk Kim * crypto support 3063cde4de12SJaegeuk Kim */ 30640b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 3065cde4de12SJaegeuk Kim { 3066cde4de12SJaegeuk Kim return file_is_encrypt(inode); 3067cde4de12SJaegeuk Kim } 3068cde4de12SJaegeuk Kim 30691958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 30701958593eSJaegeuk Kim { 30711958593eSJaegeuk Kim return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode); 30721958593eSJaegeuk Kim } 30731958593eSJaegeuk Kim 3074cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 3075cde4de12SJaegeuk Kim { 3076cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 3077cde4de12SJaegeuk Kim file_set_encrypt(inode); 30782ee6a576SEric Biggers inode->i_flags |= S_ENCRYPTED; 3079cde4de12SJaegeuk Kim #endif 3080cde4de12SJaegeuk Kim } 3081cde4de12SJaegeuk Kim 3082cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 3083cde4de12SJaegeuk Kim { 30840b81d077SJaegeuk Kim return bio->bi_private != NULL; 3085cde4de12SJaegeuk Kim } 3086cde4de12SJaegeuk Kim 3087cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 3088cde4de12SJaegeuk Kim { 3089cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 3090cde4de12SJaegeuk Kim } 3091f424f664SJaegeuk Kim 30920bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 309352763a4bSJaegeuk Kim { 30940bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 309552763a4bSJaegeuk Kim } 309652763a4bSJaegeuk Kim 30977a2af766SChao Yu static inline int f2fs_sb_has_extra_attr(struct super_block *sb) 30987a2af766SChao Yu { 30997a2af766SChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_EXTRA_ATTR); 31007a2af766SChao Yu } 31017a2af766SChao Yu 31025c57132eSChao Yu static inline int f2fs_sb_has_project_quota(struct super_block *sb) 31035c57132eSChao Yu { 31045c57132eSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_PRJQUOTA); 31055c57132eSChao Yu } 31065c57132eSChao Yu 3107704956ecSChao Yu static inline int f2fs_sb_has_inode_chksum(struct super_block *sb) 3108704956ecSChao Yu { 3109704956ecSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CHKSUM); 3110704956ecSChao Yu } 3111704956ecSChao Yu 31126afc662eSChao Yu static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb) 31136afc662eSChao Yu { 31146afc662eSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_FLEXIBLE_INLINE_XATTR); 31156afc662eSChao Yu } 31166afc662eSChao Yu 3117234a9689SJaegeuk Kim static inline int f2fs_sb_has_quota_ino(struct super_block *sb) 3118234a9689SJaegeuk Kim { 3119234a9689SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_QUOTA_INO); 3120234a9689SJaegeuk Kim } 3121234a9689SJaegeuk Kim 3122178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 3123178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 31243c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 3125178053e2SDamien Le Moal { 3126178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 31273c62be17SJaegeuk Kim int i; 3128178053e2SDamien Le Moal 31293c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 31303c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 31313c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 31323c62be17SJaegeuk Kim return -EINVAL; 3133178053e2SDamien Le Moal } 3134178053e2SDamien Le Moal #endif 3135178053e2SDamien Le Moal 313696ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 313796ba2decSDamien Le Moal { 313896ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 313996ba2decSDamien Le Moal 314096ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 314152763a4bSJaegeuk Kim } 314252763a4bSJaegeuk Kim 314352763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 314452763a4bSJaegeuk Kim { 314552763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 314652763a4bSJaegeuk Kim clear_opt(sbi, LFS); 314752763a4bSJaegeuk Kim 314852763a4bSJaegeuk Kim switch (mt) { 314952763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 315052763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 315152763a4bSJaegeuk Kim break; 315252763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 315352763a4bSJaegeuk Kim set_opt(sbi, LFS); 315452763a4bSJaegeuk Kim break; 315552763a4bSJaegeuk Kim } 315652763a4bSJaegeuk Kim } 315752763a4bSJaegeuk Kim 3158fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 3159fcc85a4dSJaegeuk Kim { 3160fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 3161886f56f9SAl Viro umode_t mode = inode->i_mode; 3162fcc85a4dSJaegeuk Kim 3163fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 3164fcc85a4dSJaegeuk Kim #else 3165fcc85a4dSJaegeuk Kim return 0; 3166fcc85a4dSJaegeuk Kim #endif 3167fcc85a4dSJaegeuk Kim } 3168fcc85a4dSJaegeuk Kim 316939a53e0cSJaegeuk Kim #endif 3170