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> 250b81d077SJaegeuk Kim #include <linux/fscrypto.h> 2643b6573bSKeith Mok #include <crypto/hash.h> 2739a53e0cSJaegeuk Kim 285d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 299850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 305d56b671SJaegeuk Kim #else 319850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 329850cf4aSJaegeuk Kim do { \ 339850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 349850cf4aSJaegeuk Kim WARN_ON(1); \ 35caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 369850cf4aSJaegeuk Kim } \ 379850cf4aSJaegeuk Kim } while (0) 385d56b671SJaegeuk Kim #endif 395d56b671SJaegeuk Kim 402c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 412c63feadSJaegeuk Kim enum { 422c63feadSJaegeuk Kim FAULT_KMALLOC, 43c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 44cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 45cb78942bSJaegeuk Kim FAULT_ORPHAN, 46cb78942bSJaegeuk Kim FAULT_BLOCK, 47cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 4853aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 498b038c70SChao Yu FAULT_IO, 500f348028SChao Yu FAULT_CHECKPOINT, 512c63feadSJaegeuk Kim FAULT_MAX, 522c63feadSJaegeuk Kim }; 532c63feadSJaegeuk Kim 5408796897SSheng Yong struct f2fs_fault_info { 5508796897SSheng Yong atomic_t inject_ops; 5608796897SSheng Yong unsigned int inject_rate; 5708796897SSheng Yong unsigned int inject_type; 5808796897SSheng Yong }; 5908796897SSheng Yong 602c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX]; 611ecc0c5cSChao Yu #define IS_FAULT_SET(fi, type) (fi->inject_type & (1 << (type))) 622c63feadSJaegeuk Kim #endif 632c63feadSJaegeuk Kim 6439a53e0cSJaegeuk Kim /* 6539a53e0cSJaegeuk Kim * For mount options 6639a53e0cSJaegeuk Kim */ 6739a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 6839a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 6939a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7039a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 7139a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 7239a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 7339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 74444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 751001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 7634d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 7734d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 7834d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 79d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8089672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 816aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 82343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 8373faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 8436abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 8536abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 8639a53e0cSJaegeuk Kim 8739a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 8839a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 8939a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 9039a53e0cSJaegeuk Kim 9139a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 9239a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 9339a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 9439a53e0cSJaegeuk Kim 95a9841c4dSJaegeuk Kim typedef u32 block_t; /* 96a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 97a9841c4dSJaegeuk Kim * address format, __le32. 98a9841c4dSJaegeuk Kim */ 9939a53e0cSJaegeuk Kim typedef u32 nid_t; 10039a53e0cSJaegeuk Kim 10139a53e0cSJaegeuk Kim struct f2fs_mount_info { 10239a53e0cSJaegeuk Kim unsigned int opt; 10339a53e0cSJaegeuk Kim }; 10439a53e0cSJaegeuk Kim 105cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1060bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 107cde4de12SJaegeuk Kim 10876f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 10976f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 11076f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 11176f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) 11276f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 11376f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) 11476f105a2SJaegeuk Kim 11539a53e0cSJaegeuk Kim /* 11639a53e0cSJaegeuk Kim * For checkpoint manager 11739a53e0cSJaegeuk Kim */ 11839a53e0cSJaegeuk Kim enum { 11939a53e0cSJaegeuk Kim NAT_BITMAP, 12039a53e0cSJaegeuk Kim SIT_BITMAP 12139a53e0cSJaegeuk Kim }; 12239a53e0cSJaegeuk Kim 12375ab4cb8SJaegeuk Kim enum { 12475ab4cb8SJaegeuk Kim CP_UMOUNT, 125119ee914SJaegeuk Kim CP_FASTBOOT, 12675ab4cb8SJaegeuk Kim CP_SYNC, 12710027551SJaegeuk Kim CP_RECOVERY, 1284b2fecc8SJaegeuk Kim CP_DISCARD, 12975ab4cb8SJaegeuk Kim }; 13075ab4cb8SJaegeuk Kim 1312d9e9c32SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2 132bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 133bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 134a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 135a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 136*15469963SJaegeuk Kim 137*15469963SJaegeuk Kim #define DISCARD_ISSUE_RATE 8 13860b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 139dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 140bba681cbSJaegeuk Kim 14175ab4cb8SJaegeuk Kim struct cp_control { 14275ab4cb8SJaegeuk Kim int reason; 1434b2fecc8SJaegeuk Kim __u64 trim_start; 1444b2fecc8SJaegeuk Kim __u64 trim_end; 1454b2fecc8SJaegeuk Kim __u64 trim_minlen; 1464b2fecc8SJaegeuk Kim __u64 trimmed; 14775ab4cb8SJaegeuk Kim }; 14875ab4cb8SJaegeuk Kim 149662befdaSChao Yu /* 15081c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 151662befdaSChao Yu */ 152662befdaSChao Yu enum { 153662befdaSChao Yu META_CP, 154662befdaSChao Yu META_NAT, 15581c1a0f1SChao Yu META_SIT, 1564c521f49SJaegeuk Kim META_SSA, 1574c521f49SJaegeuk Kim META_POR, 158662befdaSChao Yu }; 159662befdaSChao Yu 1606451e041SJaegeuk Kim /* for the list of ino */ 1616451e041SJaegeuk Kim enum { 1626451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 163fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 164fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1656451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1666451e041SJaegeuk Kim }; 1676451e041SJaegeuk Kim 1686451e041SJaegeuk Kim struct ino_entry { 16939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17039a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 17139a53e0cSJaegeuk Kim }; 17239a53e0cSJaegeuk Kim 1732710fd7eSChao Yu /* for the list of inodes to be GCed */ 17406292073SChao Yu struct inode_entry { 17539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 17739a53e0cSJaegeuk Kim }; 17839a53e0cSJaegeuk Kim 1797fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1807fd9e544SJaegeuk Kim struct discard_entry { 1817fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1827fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1837fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1847fd9e544SJaegeuk Kim }; 1857fd9e544SJaegeuk Kim 186*15469963SJaegeuk Kim enum { 187*15469963SJaegeuk Kim D_PREP, 188*15469963SJaegeuk Kim D_SUBMIT, 189*15469963SJaegeuk Kim D_DONE, 190*15469963SJaegeuk Kim }; 191*15469963SJaegeuk Kim 192b01a9201SJaegeuk Kim struct discard_cmd { 193b01a9201SJaegeuk Kim struct list_head list; /* command list */ 194b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 195b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 196b01a9201SJaegeuk Kim block_t len; /* length */ 197b01a9201SJaegeuk Kim struct bio *bio; /* bio */ 198*15469963SJaegeuk Kim int state; /* state */ 199275b66b0SChao Yu }; 200275b66b0SChao Yu 2010b54fb84SJaegeuk Kim struct discard_cmd_control { 202*15469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 2030b54fb84SJaegeuk Kim struct list_head discard_entry_list; /* 4KB discard entry list */ 2040b54fb84SJaegeuk Kim int nr_discards; /* # of discards in the list */ 2050b54fb84SJaegeuk Kim struct list_head discard_cmd_list; /* discard cmd list */ 206*15469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 207*15469963SJaegeuk Kim struct mutex cmd_lock; 2080b54fb84SJaegeuk Kim int max_discards; /* max. discards to be issued */ 2090b54fb84SJaegeuk Kim }; 2100b54fb84SJaegeuk Kim 21139a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 21239a53e0cSJaegeuk Kim struct fsync_inode_entry { 21339a53e0cSJaegeuk Kim struct list_head list; /* list head */ 21439a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 215c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 216c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 21739a53e0cSJaegeuk Kim }; 21839a53e0cSJaegeuk Kim 219dfc08a12SChao Yu #define nats_in_cursum(jnl) (le16_to_cpu(jnl->n_nats)) 220dfc08a12SChao Yu #define sits_in_cursum(jnl) (le16_to_cpu(jnl->n_sits)) 22139a53e0cSJaegeuk Kim 222dfc08a12SChao Yu #define nat_in_journal(jnl, i) (jnl->nat_j.entries[i].ne) 223dfc08a12SChao Yu #define nid_in_journal(jnl, i) (jnl->nat_j.entries[i].nid) 224dfc08a12SChao Yu #define sit_in_journal(jnl, i) (jnl->sit_j.entries[i].se) 225dfc08a12SChao Yu #define segno_in_journal(jnl, i) (jnl->sit_j.entries[i].segno) 22639a53e0cSJaegeuk Kim 227dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 228dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 229309cc2b6SJaegeuk Kim 230dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 23139a53e0cSJaegeuk Kim { 232dfc08a12SChao Yu int before = nats_in_cursum(journal); 233dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 23439a53e0cSJaegeuk Kim return before; 23539a53e0cSJaegeuk Kim } 23639a53e0cSJaegeuk Kim 237dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 23839a53e0cSJaegeuk Kim { 239dfc08a12SChao Yu int before = sits_in_cursum(journal); 240dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 24139a53e0cSJaegeuk Kim return before; 24239a53e0cSJaegeuk Kim } 24339a53e0cSJaegeuk Kim 244dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 245dfc08a12SChao Yu int size, int type) 246184a5cd2SChao Yu { 247184a5cd2SChao Yu if (type == NAT_JOURNAL) 248dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 249dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 250184a5cd2SChao Yu } 251184a5cd2SChao Yu 25239a53e0cSJaegeuk Kim /* 253e9750824SNamjae Jeon * ioctl commands 254e9750824SNamjae Jeon */ 255e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 256e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 257d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 258e9750824SNamjae Jeon 25988b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 26088b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 26188b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 26202a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2631e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2641e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 265c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 266456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 267d323d005SChao Yu #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) 2684dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 2694dd6f977SJaegeuk Kim struct f2fs_move_range) 27088b88a66SJaegeuk Kim 2710b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 2720b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 2730b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 274f424f664SJaegeuk Kim 2751abff93dSJaegeuk Kim /* 2761abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2771abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2781abff93dSJaegeuk Kim */ 2791abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2801abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2811abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2821abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 283c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 2841abff93dSJaegeuk Kim 285e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 286e9750824SNamjae Jeon /* 287e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 288e9750824SNamjae Jeon */ 289e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 290e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 29104ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 292e9750824SNamjae Jeon #endif 293e9750824SNamjae Jeon 294d323d005SChao Yu struct f2fs_defragment { 295d323d005SChao Yu u64 start; 296d323d005SChao Yu u64 len; 297d323d005SChao Yu }; 298d323d005SChao Yu 2994dd6f977SJaegeuk Kim struct f2fs_move_range { 3004dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3014dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3024dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3034dd6f977SJaegeuk Kim u64 len; /* size to move */ 3044dd6f977SJaegeuk Kim }; 3054dd6f977SJaegeuk Kim 306e9750824SNamjae Jeon /* 30739a53e0cSJaegeuk Kim * For INODE and NODE manager 30839a53e0cSJaegeuk Kim */ 3097b3cd7d6SJaegeuk Kim /* for directory operations */ 3107b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 311d8c6822aSJaegeuk Kim struct inode *inode; 3127b3cd7d6SJaegeuk Kim const void *bitmap; 3137b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 3147b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 3157b3cd7d6SJaegeuk Kim int max; 3167b3cd7d6SJaegeuk Kim }; 3177b3cd7d6SJaegeuk Kim 318d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode, 319d8c6822aSJaegeuk Kim struct f2fs_dentry_ptr *d, void *src, int type) 3207b3cd7d6SJaegeuk Kim { 321d8c6822aSJaegeuk Kim d->inode = inode; 322d8c6822aSJaegeuk Kim 3237b3cd7d6SJaegeuk Kim if (type == 1) { 3247b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 3257b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 3267b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3277b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3287b3cd7d6SJaegeuk Kim d->filename = t->filename; 3297b3cd7d6SJaegeuk Kim } else { 3307b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 3317b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3327b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3337b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3347b3cd7d6SJaegeuk Kim d->filename = t->filename; 3357b3cd7d6SJaegeuk Kim } 3367b3cd7d6SJaegeuk Kim } 3377b3cd7d6SJaegeuk Kim 338dbe6a5ffSJaegeuk Kim /* 339dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 340dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 341dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 34239a53e0cSJaegeuk Kim */ 343dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 344dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 345266e97a8SJaegeuk Kim enum { 346266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 347266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 348266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 349266e97a8SJaegeuk Kim * look up a node with readahead called 3504f4124d0SChao Yu * by get_data_block. 35139a53e0cSJaegeuk Kim */ 352266e97a8SJaegeuk Kim }; 353266e97a8SJaegeuk Kim 354a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 35539a53e0cSJaegeuk Kim 356817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 357817202d9SChao Yu 35813054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 35913054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 36013054c54SChao Yu 36139a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 36213054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 36313054c54SChao Yu 36413054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 36513054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 366c11abd1aSJaegeuk Kim 36739a53e0cSJaegeuk Kim struct extent_info { 36839a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3694d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 370111d2495SMasanari Iida unsigned int len; /* length of the extent */ 37139a53e0cSJaegeuk Kim }; 37239a53e0cSJaegeuk Kim 37313054c54SChao Yu struct extent_node { 37413054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 37513054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 37613054c54SChao Yu struct extent_info ei; /* extent info */ 377201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 37813054c54SChao Yu }; 37913054c54SChao Yu 38013054c54SChao Yu struct extent_tree { 38113054c54SChao Yu nid_t ino; /* inode number */ 38213054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 38362c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 3843e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 385137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 38613054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 38768e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 38813054c54SChao Yu }; 38913054c54SChao Yu 39039a53e0cSJaegeuk Kim /* 391003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 392003a3e1dSJaegeuk Kim * 393003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 394003a3e1dSJaegeuk Kim */ 395003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 396003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 3977f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 3987f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 3997f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 400003a3e1dSJaegeuk Kim 401003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 402003a3e1dSJaegeuk Kim block_t m_pblk; 403003a3e1dSJaegeuk Kim block_t m_lblk; 404003a3e1dSJaegeuk Kim unsigned int m_len; 405003a3e1dSJaegeuk Kim unsigned int m_flags; 406da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 407003a3e1dSJaegeuk Kim }; 408003a3e1dSJaegeuk Kim 409e2b4e2bcSChao Yu /* for flag in get_data_block */ 410e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 411e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 412e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 413e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 414b439b103SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_DIO 4 41524b84912SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_AIO 5 416e2b4e2bcSChao Yu 417003a3e1dSJaegeuk Kim /* 41839a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 41939a53e0cSJaegeuk Kim */ 42039a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 421354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 422cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 423e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 42426787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 42539a53e0cSJaegeuk Kim 426b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 427b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 428b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 429b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 430b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 431b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 432cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 433cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 434cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 435e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 436e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 43726787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 43826787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 439cde4de12SJaegeuk Kim 440ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 441ab9fa662SJaegeuk Kim 44239a53e0cSJaegeuk Kim struct f2fs_inode_info { 44339a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 44439a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 44539a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 44638431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 44739a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4486666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 44939a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 45039a53e0cSJaegeuk Kim 45139a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 45239a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 453d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 454204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 45539a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 45639a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 45739a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 458e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 45926de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 46088b88a66SJaegeuk Kim 4610f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 4620f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 46388b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 46488b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 4653e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 46682e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 46739a53e0cSJaegeuk Kim }; 46839a53e0cSJaegeuk Kim 46939a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 470bd933d4fSChao Yu struct f2fs_extent *i_ext) 47139a53e0cSJaegeuk Kim { 472bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 473bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 474bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 47539a53e0cSJaegeuk Kim } 47639a53e0cSJaegeuk Kim 47739a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 47839a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 47939a53e0cSJaegeuk Kim { 48039a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4814d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 48239a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 48339a53e0cSJaegeuk Kim } 48439a53e0cSJaegeuk Kim 485429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 486429511cdSChao Yu u32 blk, unsigned int len) 487429511cdSChao Yu { 488429511cdSChao Yu ei->fofs = fofs; 489429511cdSChao Yu ei->blk = blk; 490429511cdSChao Yu ei->len = len; 491429511cdSChao Yu } 492429511cdSChao Yu 4930bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1, 4940bdee482SChao Yu struct extent_info *ei2) 4950bdee482SChao Yu { 4960bdee482SChao Yu return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 4970bdee482SChao Yu ei1->len == ei2->len); 4980bdee482SChao Yu } 4990bdee482SChao Yu 500429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 501429511cdSChao Yu struct extent_info *front) 502429511cdSChao Yu { 503429511cdSChao Yu return (back->fofs + back->len == front->fofs && 504429511cdSChao Yu back->blk + back->len == front->blk); 505429511cdSChao Yu } 506429511cdSChao Yu 507429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 508429511cdSChao Yu struct extent_info *back) 509429511cdSChao Yu { 510429511cdSChao Yu return __is_extent_mergeable(back, cur); 511429511cdSChao Yu } 512429511cdSChao Yu 513429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 514429511cdSChao Yu struct extent_info *front) 515429511cdSChao Yu { 516429511cdSChao Yu return __is_extent_mergeable(cur, front); 517429511cdSChao Yu } 518429511cdSChao Yu 5197c45729aSJaegeuk Kim extern void f2fs_mark_inode_dirty_sync(struct inode *, bool); 520205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 521205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 5224abd3f5aSChao Yu { 523205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 5244abd3f5aSChao Yu et->largest = en->ei; 5257c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 526205b9822SJaegeuk Kim } 5274abd3f5aSChao Yu } 5284abd3f5aSChao Yu 529b8559dc2SChao Yu enum nid_list { 530b8559dc2SChao Yu FREE_NID_LIST, 531b8559dc2SChao Yu ALLOC_NID_LIST, 532b8559dc2SChao Yu MAX_NID_LIST, 533b8559dc2SChao Yu }; 534b8559dc2SChao Yu 53539a53e0cSJaegeuk Kim struct f2fs_nm_info { 53639a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 53739a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 53804d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 53939a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 540cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 541ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 5422304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 54339a53e0cSJaegeuk Kim 54439a53e0cSJaegeuk Kim /* NAT cache management */ 54539a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 546309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 547b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 54839a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 549309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 550aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 55139a53e0cSJaegeuk Kim 55239a53e0cSJaegeuk Kim /* free node ids management */ 5538a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 554b8559dc2SChao Yu struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ 555b8559dc2SChao Yu unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 556b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 55739a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 55839a53e0cSJaegeuk Kim 55939a53e0cSJaegeuk Kim /* for checkpoint */ 56039a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 561599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 562599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 563599a09b2SChao Yu #endif 56439a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 56539a53e0cSJaegeuk Kim }; 56639a53e0cSJaegeuk Kim 56739a53e0cSJaegeuk Kim /* 56839a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 56939a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 57039a53e0cSJaegeuk Kim * by the data offset in a file. 57139a53e0cSJaegeuk Kim */ 57239a53e0cSJaegeuk Kim struct dnode_of_data { 57339a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 57439a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 57539a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 57639a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 57739a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 57839a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 57993bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 5803cf45747SChao Yu char cur_level; /* level of hole node page */ 5813cf45747SChao Yu char max_level; /* level of current page located */ 58239a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 58339a53e0cSJaegeuk Kim }; 58439a53e0cSJaegeuk Kim 58539a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 58639a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 58739a53e0cSJaegeuk Kim { 588d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 58939a53e0cSJaegeuk Kim dn->inode = inode; 59039a53e0cSJaegeuk Kim dn->inode_page = ipage; 59139a53e0cSJaegeuk Kim dn->node_page = npage; 59239a53e0cSJaegeuk Kim dn->nid = nid; 59339a53e0cSJaegeuk Kim } 59439a53e0cSJaegeuk Kim 59539a53e0cSJaegeuk Kim /* 59639a53e0cSJaegeuk Kim * For SIT manager 59739a53e0cSJaegeuk Kim * 59839a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 59939a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 60039a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 60139a53e0cSJaegeuk Kim * respectively. 60239a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 60339a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 60439a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 60539a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 60639a53e0cSJaegeuk Kim * data and 8 for node logs. 60739a53e0cSJaegeuk Kim */ 60839a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 60939a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 61039a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 61139a53e0cSJaegeuk Kim 61239a53e0cSJaegeuk Kim enum { 61339a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 61439a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 61539a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 61639a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 61739a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 61839a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 61938aa0889SJaegeuk Kim NO_CHECK_TYPE, 62039a53e0cSJaegeuk Kim }; 62139a53e0cSJaegeuk Kim 6226b4afdd7SJaegeuk Kim struct flush_cmd { 6236b4afdd7SJaegeuk Kim struct completion wait; 624721bd4d5SGu Zheng struct llist_node llnode; 6256b4afdd7SJaegeuk Kim int ret; 6266b4afdd7SJaegeuk Kim }; 6276b4afdd7SJaegeuk Kim 628a688b9d9SGu Zheng struct flush_cmd_control { 629a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 630a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 6310a87f664SJaegeuk Kim atomic_t submit_flush; /* # of issued flushes */ 632721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 633721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 634a688b9d9SGu Zheng }; 635a688b9d9SGu Zheng 63639a53e0cSJaegeuk Kim struct f2fs_sm_info { 63739a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 63839a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 63939a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 64039a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 64139a53e0cSJaegeuk Kim 64239a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 64339a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 64439a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 64539a53e0cSJaegeuk Kim 64639a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 64739a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 64839a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 64939a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 65081eb8d6eSJaegeuk Kim 65181eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 65281eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 6537fd9e544SJaegeuk Kim 654bba681cbSJaegeuk Kim /* for batched trimming */ 655bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 656bba681cbSJaegeuk Kim 657184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 658184a5cd2SChao Yu 659216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 660216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 661c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 6626b4afdd7SJaegeuk Kim 6636b4afdd7SJaegeuk Kim /* for flush command control */ 664b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 6650b54fb84SJaegeuk Kim 6660b54fb84SJaegeuk Kim /* for discard command control */ 6670b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 66839a53e0cSJaegeuk Kim }; 66939a53e0cSJaegeuk Kim 67039a53e0cSJaegeuk Kim /* 67139a53e0cSJaegeuk Kim * For superblock 67239a53e0cSJaegeuk Kim */ 67339a53e0cSJaegeuk Kim /* 67439a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 67539a53e0cSJaegeuk Kim * 67639a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 67739a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 67839a53e0cSJaegeuk Kim */ 67936951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 68039a53e0cSJaegeuk Kim enum count_type { 68139a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 682c227f912SChao Yu F2FS_DIRTY_DATA, 68339a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 68439a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6858dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 6860f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 68736951b38SChao Yu F2FS_WB_CP_DATA, 68836951b38SChao Yu F2FS_WB_DATA, 68939a53e0cSJaegeuk Kim NR_COUNT_TYPE, 69039a53e0cSJaegeuk Kim }; 69139a53e0cSJaegeuk Kim 69239a53e0cSJaegeuk Kim /* 693e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 69439a53e0cSJaegeuk Kim * The available types are: 69539a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 69639a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 69739a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 69839a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 69939a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 70039a53e0cSJaegeuk Kim * with waiting the bio's completion 70139a53e0cSJaegeuk Kim * ... Only can be used with META. 70239a53e0cSJaegeuk Kim */ 7037d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 70439a53e0cSJaegeuk Kim enum page_type { 70539a53e0cSJaegeuk Kim DATA, 70639a53e0cSJaegeuk Kim NODE, 70739a53e0cSJaegeuk Kim META, 70839a53e0cSJaegeuk Kim NR_PAGE_TYPE, 70939a53e0cSJaegeuk Kim META_FLUSH, 7108ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 7118ce67cb0SJaegeuk Kim INMEM_DROP, 71228bc106bSChao Yu INMEM_REVOKE, 7138ce67cb0SJaegeuk Kim IPU, 7148ce67cb0SJaegeuk Kim OPU, 71539a53e0cSJaegeuk Kim }; 71639a53e0cSJaegeuk Kim 717458e6197SJaegeuk Kim struct f2fs_io_info { 71805ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 719458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 72004d328deSMike Christie int op; /* contains REQ_OP_ */ 721ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 7227a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 72328bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 72405ca3632SJaegeuk Kim struct page *page; /* page to be written */ 7254375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 726458e6197SJaegeuk Kim }; 727458e6197SJaegeuk Kim 72804d328deSMike Christie #define is_read_io(rw) (rw == READ) 7291ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 730458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 7311ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 7321ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 733458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 734df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 7351ff7bd3bSJaegeuk Kim }; 7361ff7bd3bSJaegeuk Kim 7373c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 7383c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 7393c62be17SJaegeuk Kim struct f2fs_dev_info { 7403c62be17SJaegeuk Kim struct block_device *bdev; 7413c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 7423c62be17SJaegeuk Kim unsigned int total_segments; 7433c62be17SJaegeuk Kim block_t start_blk; 7443c62be17SJaegeuk Kim block_t end_blk; 7453c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 7463c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 7473c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 7483c62be17SJaegeuk Kim #endif 7493c62be17SJaegeuk Kim }; 7503c62be17SJaegeuk Kim 751c227f912SChao Yu enum inode_type { 752c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 753c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 7540f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 755c227f912SChao Yu NR_INODE_TYPE, 756c227f912SChao Yu }; 757c227f912SChao Yu 75867298804SChao Yu /* for inner inode cache management */ 75967298804SChao Yu struct inode_management { 76067298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 76167298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 76267298804SChao Yu struct list_head ino_list; /* inode list head */ 76367298804SChao Yu unsigned long ino_num; /* number of entries */ 76467298804SChao Yu }; 76567298804SChao Yu 766caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 767caf0047eSChao Yu enum { 768caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 769caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 770caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 771caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 772df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 773bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 774caf0047eSChao Yu }; 775caf0047eSChao Yu 7766beceb54SJaegeuk Kim enum { 7776beceb54SJaegeuk Kim CP_TIME, 778d0239e1bSJaegeuk Kim REQ_TIME, 7796beceb54SJaegeuk Kim MAX_TIME, 7806beceb54SJaegeuk Kim }; 7816beceb54SJaegeuk Kim 782b5a7aef1SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 783b5a7aef1SJaegeuk Kim #define F2FS_KEY_DESC_PREFIX "f2fs:" 784b5a7aef1SJaegeuk Kim #define F2FS_KEY_DESC_PREFIX_SIZE 5 785b5a7aef1SJaegeuk Kim #endif 78639a53e0cSJaegeuk Kim struct f2fs_sb_info { 78739a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 7885e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 78939a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 790e8240f65SChao Yu int valid_super_block; /* valid super block no */ 791fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 79239a53e0cSJaegeuk Kim 793b5a7aef1SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 794b5a7aef1SJaegeuk Kim u8 key_prefix[F2FS_KEY_DESC_PREFIX_SIZE]; 795b5a7aef1SJaegeuk Kim u8 key_prefix_size; 796b5a7aef1SJaegeuk Kim #endif 797178053e2SDamien Le Moal 798178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 799178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 800178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 801178053e2SDamien Le Moal #endif 802178053e2SDamien Le Moal 80339a53e0cSJaegeuk Kim /* for node-related operations */ 80439a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 80539a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 80639a53e0cSJaegeuk Kim 80739a53e0cSJaegeuk Kim /* for segment-related operations */ 80839a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 8091ff7bd3bSJaegeuk Kim 8101ff7bd3bSJaegeuk Kim /* for bio operations */ 811924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 8121ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 8137dfeaa32SJaegeuk Kim struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ 8140a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 8150a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 81639a53e0cSJaegeuk Kim 81739a53e0cSJaegeuk Kim /* for checkpoint */ 81839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 8198508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 820aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 82139a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 82239936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 823b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 824b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 825fb51b5efSChangman Lee wait_queue_head_t cp_wait; 8266beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 8276beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 82839a53e0cSJaegeuk Kim 82967298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 8306451e041SJaegeuk Kim 8316451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 8320d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 83339a53e0cSJaegeuk Kim 834c227f912SChao Yu /* for inode management */ 835c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 836c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 83739a53e0cSJaegeuk Kim 83813054c54SChao Yu /* for extent tree cache */ 83913054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 84013054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 84113054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 84213054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 8437441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 844137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 84574fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 84613054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 84713054c54SChao Yu 84839a53e0cSJaegeuk Kim /* basic filesystem units */ 84939a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 85039a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 85139a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 85239a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 85339a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 85439a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 85539a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 85639a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 85739a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 85839a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 85939a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 86039a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 86139a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 862e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 86339a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 864ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 86539a53e0cSJaegeuk Kim 86639a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 86739a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 868a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 86939a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 87039a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 871523be8a6SJaegeuk Kim 872523be8a6SJaegeuk Kim /* # of pages, see count_type */ 87335782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 87441382ec4SJaegeuk Kim /* # of allocated blocks */ 87541382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 87639a53e0cSJaegeuk Kim 877513c5f37SJaegeuk Kim /* valid inode count */ 878513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 879513c5f37SJaegeuk Kim 88039a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 88139a53e0cSJaegeuk Kim 88239a53e0cSJaegeuk Kim /* for cleaning operations */ 88339a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 88439a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 8855ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 88639a53e0cSJaegeuk Kim 887b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 888b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 889b1c57c1cSJaegeuk Kim 89039a53e0cSJaegeuk Kim /* 89139a53e0cSJaegeuk Kim * for stat information. 89239a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 89339a53e0cSJaegeuk Kim */ 89435b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 89539a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 89639a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 89739a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 898b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 8995b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 9005b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 9015b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 9025b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 903d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 90403e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 90503e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 90626a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 90726a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 90839a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 90933fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 91035b09d82SNamjae Jeon #endif 91135b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 91239a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 913b59d0baeSNamjae Jeon 914b59d0baeSNamjae Jeon /* For sysfs suppport */ 915b59d0baeSNamjae Jeon struct kobject s_kobj; 916b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 9172658e50dSJaegeuk Kim 9182658e50dSJaegeuk Kim /* For shrinker support */ 9192658e50dSJaegeuk Kim struct list_head s_list; 9203c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 9213c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 9222658e50dSJaegeuk Kim struct mutex umount_mutex; 9232658e50dSJaegeuk Kim unsigned int shrinker_run_no; 9248f1dbbbbSShuoran Liu 9258f1dbbbbSShuoran Liu /* For write statistics */ 9268f1dbbbbSShuoran Liu u64 sectors_written_start; 9278f1dbbbbSShuoran Liu u64 kbytes_written; 92843b6573bSKeith Mok 92943b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 93043b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 9311ecc0c5cSChao Yu 9321ecc0c5cSChao Yu /* For fault injection */ 9331ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 9341ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 9351ecc0c5cSChao Yu #endif 93639a53e0cSJaegeuk Kim }; 93739a53e0cSJaegeuk Kim 9381ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 9391ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 9401ecc0c5cSChao Yu { 9411ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 9421ecc0c5cSChao Yu 9431ecc0c5cSChao Yu if (!ffi->inject_rate) 9441ecc0c5cSChao Yu return false; 9451ecc0c5cSChao Yu 9461ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 9471ecc0c5cSChao Yu return false; 9481ecc0c5cSChao Yu 9491ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 9501ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 9511ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 9521ecc0c5cSChao Yu printk("%sF2FS-fs : inject %s in %pF\n", 9531ecc0c5cSChao Yu KERN_INFO, 9541ecc0c5cSChao Yu fault_name[type], 9551ecc0c5cSChao Yu __builtin_return_address(0)); 9561ecc0c5cSChao Yu return true; 9571ecc0c5cSChao Yu } 9581ecc0c5cSChao Yu return false; 9591ecc0c5cSChao Yu } 9601ecc0c5cSChao Yu #endif 9611ecc0c5cSChao Yu 9628f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 9638f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 9648f1dbbbbSShuoran Liu */ 9658f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 9668f1dbbbbSShuoran Liu (((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) - \ 9678f1dbbbbSShuoran Liu s->sectors_written_start) >> 1) 9688f1dbbbbSShuoran Liu 9696beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 9706beceb54SJaegeuk Kim { 9716beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 9726beceb54SJaegeuk Kim } 9736beceb54SJaegeuk Kim 9746beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 9756beceb54SJaegeuk Kim { 9766beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 9776beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 9786beceb54SJaegeuk Kim 9796beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 9806beceb54SJaegeuk Kim } 9816beceb54SJaegeuk Kim 982d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 983d0239e1bSJaegeuk Kim { 984d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 985d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 986d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 987d0239e1bSJaegeuk Kim 988d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 989d0239e1bSJaegeuk Kim return 0; 990d0239e1bSJaegeuk Kim 991d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 992d0239e1bSJaegeuk Kim } 993d0239e1bSJaegeuk Kim 99439a53e0cSJaegeuk Kim /* 99539a53e0cSJaegeuk Kim * Inline functions 99639a53e0cSJaegeuk Kim */ 99743b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 99843b6573bSKeith Mok unsigned int length) 99943b6573bSKeith Mok { 100043b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 100143b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 100243b6573bSKeith Mok int err; 100343b6573bSKeith Mok 100443b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 100543b6573bSKeith Mok shash->flags = 0; 100643b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 100743b6573bSKeith Mok 100843b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 100943b6573bSKeith Mok BUG_ON(err); 101043b6573bSKeith Mok 101143b6573bSKeith Mok return *ctx; 101243b6573bSKeith Mok } 101343b6573bSKeith Mok 101443b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 101543b6573bSKeith Mok void *buf, size_t buf_size) 101643b6573bSKeith Mok { 101743b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 101843b6573bSKeith Mok } 101943b6573bSKeith Mok 102039a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 102139a53e0cSJaegeuk Kim { 102239a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 102339a53e0cSJaegeuk Kim } 102439a53e0cSJaegeuk Kim 102539a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 102639a53e0cSJaegeuk Kim { 102739a53e0cSJaegeuk Kim return sb->s_fs_info; 102839a53e0cSJaegeuk Kim } 102939a53e0cSJaegeuk Kim 10304081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 10314081363fSJaegeuk Kim { 10324081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 10334081363fSJaegeuk Kim } 10344081363fSJaegeuk Kim 10354081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 10364081363fSJaegeuk Kim { 10374081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 10384081363fSJaegeuk Kim } 10394081363fSJaegeuk Kim 10404081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 10414081363fSJaegeuk Kim { 10424081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 10434081363fSJaegeuk Kim } 10444081363fSJaegeuk Kim 104539a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 104639a53e0cSJaegeuk Kim { 104739a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 104839a53e0cSJaegeuk Kim } 104939a53e0cSJaegeuk Kim 105039a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 105139a53e0cSJaegeuk Kim { 105239a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 105339a53e0cSJaegeuk Kim } 105439a53e0cSJaegeuk Kim 105545590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 105645590710SGu Zheng { 105745590710SGu Zheng return (struct f2fs_node *)page_address(page); 105845590710SGu Zheng } 105945590710SGu Zheng 106058bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 106158bfaf44SJaegeuk Kim { 106258bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 106358bfaf44SJaegeuk Kim } 106458bfaf44SJaegeuk Kim 106539a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 106639a53e0cSJaegeuk Kim { 106739a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 106839a53e0cSJaegeuk Kim } 106939a53e0cSJaegeuk Kim 107039a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 107139a53e0cSJaegeuk Kim { 107239a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 107339a53e0cSJaegeuk Kim } 107439a53e0cSJaegeuk Kim 107539a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 107639a53e0cSJaegeuk Kim { 107739a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 107839a53e0cSJaegeuk Kim } 107939a53e0cSJaegeuk Kim 108039a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 108139a53e0cSJaegeuk Kim { 108239a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 108339a53e0cSJaegeuk Kim } 108439a53e0cSJaegeuk Kim 108539a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 108639a53e0cSJaegeuk Kim { 108739a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 108839a53e0cSJaegeuk Kim } 108939a53e0cSJaegeuk Kim 10909df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 10919df27d98SGu Zheng { 10929df27d98SGu Zheng return sbi->meta_inode->i_mapping; 10939df27d98SGu Zheng } 10949df27d98SGu Zheng 10954ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 10964ef51a8fSJaegeuk Kim { 10974ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 10984ef51a8fSJaegeuk Kim } 10994ef51a8fSJaegeuk Kim 1100caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 110139a53e0cSJaegeuk Kim { 1102fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 110339a53e0cSJaegeuk Kim } 110439a53e0cSJaegeuk Kim 1105caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 110639a53e0cSJaegeuk Kim { 1107fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1108caf0047eSChao Yu } 1109caf0047eSChao Yu 1110caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1111caf0047eSChao Yu { 1112fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 111339a53e0cSJaegeuk Kim } 111439a53e0cSJaegeuk Kim 1115d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1116d71b5564SJaegeuk Kim { 1117d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1118d71b5564SJaegeuk Kim } 1119d71b5564SJaegeuk Kim 1120aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 112125ca923bSJaegeuk Kim { 112225ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1123aaec2b1dSChao Yu 112425ca923bSJaegeuk Kim return ckpt_flags & f; 112525ca923bSJaegeuk Kim } 112625ca923bSJaegeuk Kim 1127aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 112825ca923bSJaegeuk Kim { 1129aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1130aaec2b1dSChao Yu } 1131aaec2b1dSChao Yu 1132aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1133aaec2b1dSChao Yu { 1134aaec2b1dSChao Yu unsigned int ckpt_flags; 1135aaec2b1dSChao Yu 1136aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 113725ca923bSJaegeuk Kim ckpt_flags |= f; 113825ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 113925ca923bSJaegeuk Kim } 114025ca923bSJaegeuk Kim 1141aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 114225ca923bSJaegeuk Kim { 1143aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1144aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1145aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1146aaec2b1dSChao Yu } 1147aaec2b1dSChao Yu 1148aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1149aaec2b1dSChao Yu { 1150aaec2b1dSChao Yu unsigned int ckpt_flags; 1151aaec2b1dSChao Yu 1152aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 115325ca923bSJaegeuk Kim ckpt_flags &= (~f); 115425ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 115525ca923bSJaegeuk Kim } 115625ca923bSJaegeuk Kim 1157aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1158aaec2b1dSChao Yu { 1159aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1160aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1161aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1162aaec2b1dSChao Yu } 1163aaec2b1dSChao Yu 1164e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 116539a53e0cSJaegeuk Kim { 1166b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 116739a53e0cSJaegeuk Kim } 116839a53e0cSJaegeuk Kim 1169e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 117039a53e0cSJaegeuk Kim { 1171b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 117239936837SJaegeuk Kim } 117339936837SJaegeuk Kim 1174e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 117539936837SJaegeuk Kim { 1176b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 117739936837SJaegeuk Kim } 117839936837SJaegeuk Kim 1179e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 118039936837SJaegeuk Kim { 1181b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 118239a53e0cSJaegeuk Kim } 118339a53e0cSJaegeuk Kim 1184119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1185119ee914SJaegeuk Kim { 1186119ee914SJaegeuk Kim int reason = CP_SYNC; 1187119ee914SJaegeuk Kim 1188119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1189119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1190119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1191119ee914SJaegeuk Kim reason = CP_UMOUNT; 1192119ee914SJaegeuk Kim return reason; 1193119ee914SJaegeuk Kim } 1194119ee914SJaegeuk Kim 1195119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1196119ee914SJaegeuk Kim { 1197119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 1198119ee914SJaegeuk Kim } 1199119ee914SJaegeuk Kim 1200119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1201119ee914SJaegeuk Kim { 1202aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1203aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1204119ee914SJaegeuk Kim } 1205119ee914SJaegeuk Kim 120639a53e0cSJaegeuk Kim /* 120739a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 120839a53e0cSJaegeuk Kim */ 1209064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 121039a53e0cSJaegeuk Kim { 1211d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1212d6b7d4b3SChao Yu return -EINVAL; 1213cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1214064e0823SNamjae Jeon return -EINVAL; 1215064e0823SNamjae Jeon return 0; 121639a53e0cSJaegeuk Kim } 121739a53e0cSJaegeuk Kim 121839a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 121939a53e0cSJaegeuk Kim 122039a53e0cSJaegeuk Kim /* 122139a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 122239a53e0cSJaegeuk Kim */ 122339a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 122439a53e0cSJaegeuk Kim { 122539a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 12266c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 122739a53e0cSJaegeuk Kim else 12286c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 122939a53e0cSJaegeuk Kim } 123039a53e0cSJaegeuk Kim 12314bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 12324bc8e9bcSChao Yu { 12334bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 12344bc8e9bcSChao Yu } 12354bc8e9bcSChao Yu 12368edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 123739a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 123846008c6dSChao Yu struct inode *inode, blkcnt_t *count) 123939a53e0cSJaegeuk Kim { 1240dd11a5dfSJaegeuk Kim blkcnt_t diff; 1241dd11a5dfSJaegeuk Kim 1242cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 12431ecc0c5cSChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) 1244cb78942bSJaegeuk Kim return false; 1245cb78942bSJaegeuk Kim #endif 1246dd11a5dfSJaegeuk Kim /* 1247dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1248dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1249dd11a5dfSJaegeuk Kim */ 1250dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1251cfb271d4SChao Yu 125239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12532555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 12542555a2d5SJaegeuk Kim if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { 1255dd11a5dfSJaegeuk Kim diff = sbi->total_valid_block_count - sbi->user_block_count; 1256dd11a5dfSJaegeuk Kim *count -= diff; 12572555a2d5SJaegeuk Kim sbi->total_valid_block_count = sbi->user_block_count; 125846008c6dSChao Yu if (!*count) { 125939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1260dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 126139a53e0cSJaegeuk Kim return false; 126239a53e0cSJaegeuk Kim } 126346008c6dSChao Yu } 126439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 126541382ec4SJaegeuk Kim 12662555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, *count, true); 126739a53e0cSJaegeuk Kim return true; 126839a53e0cSJaegeuk Kim } 126939a53e0cSJaegeuk Kim 1270da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 127139a53e0cSJaegeuk Kim struct inode *inode, 127239a53e0cSJaegeuk Kim blkcnt_t count) 127339a53e0cSJaegeuk Kim { 127439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12759850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 12769850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 127739a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 127839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 12792555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, count, false); 128039a53e0cSJaegeuk Kim } 128139a53e0cSJaegeuk Kim 128239a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 128339a53e0cSJaegeuk Kim { 128435782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 12857c4abcbeSChao Yu 128636951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 128736951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 12887c4abcbeSChao Yu return; 12897c4abcbeSChao Yu 1290caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 129139a53e0cSJaegeuk Kim } 129239a53e0cSJaegeuk Kim 1293a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 129439a53e0cSJaegeuk Kim { 1295204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1296c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1297c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 129839a53e0cSJaegeuk Kim } 129939a53e0cSJaegeuk Kim 130039a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 130139a53e0cSJaegeuk Kim { 130235782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 130339a53e0cSJaegeuk Kim } 130439a53e0cSJaegeuk Kim 1305a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 130639a53e0cSJaegeuk Kim { 13075ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 13085ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 13091fe54f9dSJaegeuk Kim return; 13101fe54f9dSJaegeuk Kim 1311204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1312c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1313c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 131439a53e0cSJaegeuk Kim } 131539a53e0cSJaegeuk Kim 1316523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 131739a53e0cSJaegeuk Kim { 131835782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 131939a53e0cSJaegeuk Kim } 132039a53e0cSJaegeuk Kim 1321204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1322f8b2c1f9SJaegeuk Kim { 1323204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1324f8b2c1f9SJaegeuk Kim } 1325f8b2c1f9SJaegeuk Kim 13265ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 13275ac206cfSNamjae Jeon { 13283519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1329523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1330523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1331523be8a6SJaegeuk Kim 1332523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 13335ac206cfSNamjae Jeon } 13345ac206cfSNamjae Jeon 133539a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 133639a53e0cSJaegeuk Kim { 13378b8343faSJaegeuk Kim return sbi->total_valid_block_count; 133839a53e0cSJaegeuk Kim } 133939a53e0cSJaegeuk Kim 1340f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1341f83a2584SYunlei He { 1342f83a2584SYunlei He return sbi->discard_blks; 1343f83a2584SYunlei He } 1344f83a2584SYunlei He 134539a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 134639a53e0cSJaegeuk Kim { 134739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 134839a53e0cSJaegeuk Kim 134939a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 135039a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 135139a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 135239a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 135339a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 135439a53e0cSJaegeuk Kim 135539a53e0cSJaegeuk Kim return 0; 135639a53e0cSJaegeuk Kim } 135739a53e0cSJaegeuk Kim 135855141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 135955141486SWanpeng Li { 136055141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 136155141486SWanpeng Li } 136255141486SWanpeng Li 136339a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 136439a53e0cSJaegeuk Kim { 136539a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 13661dbe4152SChangman Lee int offset; 13671dbe4152SChangman Lee 136855141486SWanpeng Li if (__cp_payload(sbi) > 0) { 13691dbe4152SChangman Lee if (flag == NAT_BITMAP) 13701dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 13711dbe4152SChangman Lee else 137265b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 13731dbe4152SChangman Lee } else { 13741dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 137525ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 137639a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 137739a53e0cSJaegeuk Kim } 13781dbe4152SChangman Lee } 137939a53e0cSJaegeuk Kim 138039a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 138139a53e0cSJaegeuk Kim { 13828508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 138339a53e0cSJaegeuk Kim 13848508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 138539a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 138639a53e0cSJaegeuk Kim return start_addr; 138739a53e0cSJaegeuk Kim } 138839a53e0cSJaegeuk Kim 13898508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 13908508e44aSJaegeuk Kim { 13918508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 13928508e44aSJaegeuk Kim 13938508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 13948508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 13958508e44aSJaegeuk Kim return start_addr; 13968508e44aSJaegeuk Kim } 13978508e44aSJaegeuk Kim 13988508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 13998508e44aSJaegeuk Kim { 14008508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 14018508e44aSJaegeuk Kim } 14028508e44aSJaegeuk Kim 140339a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 140439a53e0cSJaegeuk Kim { 140539a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 140639a53e0cSJaegeuk Kim } 140739a53e0cSJaegeuk Kim 140839a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1409ef86d709SGu Zheng struct inode *inode) 141039a53e0cSJaegeuk Kim { 141139a53e0cSJaegeuk Kim block_t valid_block_count; 141239a53e0cSJaegeuk Kim unsigned int valid_node_count; 141339a53e0cSJaegeuk Kim 141439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 141539a53e0cSJaegeuk Kim 1416ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1417cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 141839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 141939a53e0cSJaegeuk Kim return false; 142039a53e0cSJaegeuk Kim } 142139a53e0cSJaegeuk Kim 1422ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1423cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 142439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 142539a53e0cSJaegeuk Kim return false; 142639a53e0cSJaegeuk Kim } 142739a53e0cSJaegeuk Kim 142839a53e0cSJaegeuk Kim if (inode) 14298edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, true); 1430ef86d709SGu Zheng 1431ef86d709SGu Zheng sbi->total_valid_node_count++; 1432ef86d709SGu Zheng sbi->total_valid_block_count++; 143339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 143439a53e0cSJaegeuk Kim 143541382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 143639a53e0cSJaegeuk Kim return true; 143739a53e0cSJaegeuk Kim } 143839a53e0cSJaegeuk Kim 143939a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1440ef86d709SGu Zheng struct inode *inode) 144139a53e0cSJaegeuk Kim { 144239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 144339a53e0cSJaegeuk Kim 14449850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 14459850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 14469850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 144739a53e0cSJaegeuk Kim 14488edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, false); 1449ef86d709SGu Zheng sbi->total_valid_node_count--; 1450ef86d709SGu Zheng sbi->total_valid_block_count--; 145139a53e0cSJaegeuk Kim 145239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 145339a53e0cSJaegeuk Kim } 145439a53e0cSJaegeuk Kim 145539a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 145639a53e0cSJaegeuk Kim { 14578b8343faSJaegeuk Kim return sbi->total_valid_node_count; 145839a53e0cSJaegeuk Kim } 145939a53e0cSJaegeuk Kim 146039a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 146139a53e0cSJaegeuk Kim { 1462513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 146339a53e0cSJaegeuk Kim } 146439a53e0cSJaegeuk Kim 14650e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 146639a53e0cSJaegeuk Kim { 1467513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 146839a53e0cSJaegeuk Kim } 146939a53e0cSJaegeuk Kim 1470513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 147139a53e0cSJaegeuk Kim { 1472513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 147339a53e0cSJaegeuk Kim } 147439a53e0cSJaegeuk Kim 1475a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1476a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1477a56c7c6fSJaegeuk Kim { 1478c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1479c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1480c41f3cc3SJaegeuk Kim if (page) 1481c41f3cc3SJaegeuk Kim return page; 1482c41f3cc3SJaegeuk Kim 14831ecc0c5cSChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) 1484c41f3cc3SJaegeuk Kim return NULL; 1485c41f3cc3SJaegeuk Kim #endif 1486a56c7c6fSJaegeuk Kim if (!for_write) 1487a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1488a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1489a56c7c6fSJaegeuk Kim } 1490a56c7c6fSJaegeuk Kim 14916e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 14926e2c64adSJaegeuk Kim { 14936e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 14946e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 14956e2c64adSJaegeuk Kim 14966e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 14976e2c64adSJaegeuk Kim kunmap(dst); 14986e2c64adSJaegeuk Kim kunmap(src); 14996e2c64adSJaegeuk Kim } 15006e2c64adSJaegeuk Kim 150139a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 150239a53e0cSJaegeuk Kim { 1503031fa8ccSJaegeuk Kim if (!page) 150439a53e0cSJaegeuk Kim return; 150539a53e0cSJaegeuk Kim 150639a53e0cSJaegeuk Kim if (unlock) { 15079850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 150839a53e0cSJaegeuk Kim unlock_page(page); 150939a53e0cSJaegeuk Kim } 151009cbfeafSKirill A. Shutemov put_page(page); 151139a53e0cSJaegeuk Kim } 151239a53e0cSJaegeuk Kim 151339a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 151439a53e0cSJaegeuk Kim { 151539a53e0cSJaegeuk Kim if (dn->node_page) 151639a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 151739a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 151839a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 151939a53e0cSJaegeuk Kim dn->node_page = NULL; 152039a53e0cSJaegeuk Kim dn->inode_page = NULL; 152139a53e0cSJaegeuk Kim } 152239a53e0cSJaegeuk Kim 152339a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1524e8512d2eSGu Zheng size_t size) 152539a53e0cSJaegeuk Kim { 1526e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 152739a53e0cSJaegeuk Kim } 152839a53e0cSJaegeuk Kim 15297bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 15307bd59381SGu Zheng gfp_t flags) 15317bd59381SGu Zheng { 15327bd59381SGu Zheng void *entry; 15337bd59381SGu Zheng 153480c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 153580c54505SJaegeuk Kim if (!entry) 153680c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 15377bd59381SGu Zheng return entry; 15387bd59381SGu Zheng } 15397bd59381SGu Zheng 1540740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1541740432f8SJaegeuk Kim { 1542740432f8SJaegeuk Kim struct bio *bio; 1543740432f8SJaegeuk Kim 1544740432f8SJaegeuk Kim /* No failure on bio allocation */ 1545740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 154680c54505SJaegeuk Kim if (!bio) 154780c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1548740432f8SJaegeuk Kim return bio; 1549740432f8SJaegeuk Kim } 1550740432f8SJaegeuk Kim 15519be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 15529be32d72SJaegeuk Kim unsigned long index, void *item) 15539be32d72SJaegeuk Kim { 15549be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 15559be32d72SJaegeuk Kim cond_resched(); 15569be32d72SJaegeuk Kim } 15579be32d72SJaegeuk Kim 155839a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 155939a53e0cSJaegeuk Kim 156039a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 156139a53e0cSJaegeuk Kim { 156245590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 156339a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 156439a53e0cSJaegeuk Kim } 156539a53e0cSJaegeuk Kim 156639a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 156739a53e0cSJaegeuk Kim { 156839a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 156939a53e0cSJaegeuk Kim } 157039a53e0cSJaegeuk Kim 157139a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 157239a53e0cSJaegeuk Kim unsigned int offset) 157339a53e0cSJaegeuk Kim { 157439a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 157539a53e0cSJaegeuk Kim __le32 *addr_array; 157645590710SGu Zheng raw_node = F2FS_NODE(node_page); 157739a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 157839a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 157939a53e0cSJaegeuk Kim } 158039a53e0cSJaegeuk Kim 158139a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 158239a53e0cSJaegeuk Kim { 158339a53e0cSJaegeuk Kim int mask; 158439a53e0cSJaegeuk Kim 158539a53e0cSJaegeuk Kim addr += (nr >> 3); 158639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 158739a53e0cSJaegeuk Kim return mask & *addr; 158839a53e0cSJaegeuk Kim } 158939a53e0cSJaegeuk Kim 1590a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1591a66cdd98SJaegeuk Kim { 1592a66cdd98SJaegeuk Kim int mask; 1593a66cdd98SJaegeuk Kim 1594a66cdd98SJaegeuk Kim addr += (nr >> 3); 1595a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1596a66cdd98SJaegeuk Kim *addr |= mask; 1597a66cdd98SJaegeuk Kim } 1598a66cdd98SJaegeuk Kim 1599a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1600a66cdd98SJaegeuk Kim { 1601a66cdd98SJaegeuk Kim int mask; 1602a66cdd98SJaegeuk Kim 1603a66cdd98SJaegeuk Kim addr += (nr >> 3); 1604a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1605a66cdd98SJaegeuk Kim *addr &= ~mask; 1606a66cdd98SJaegeuk Kim } 1607a66cdd98SJaegeuk Kim 160852aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 160939a53e0cSJaegeuk Kim { 161039a53e0cSJaegeuk Kim int mask; 161139a53e0cSJaegeuk Kim int ret; 161239a53e0cSJaegeuk Kim 161339a53e0cSJaegeuk Kim addr += (nr >> 3); 161439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 161539a53e0cSJaegeuk Kim ret = mask & *addr; 161639a53e0cSJaegeuk Kim *addr |= mask; 161739a53e0cSJaegeuk Kim return ret; 161839a53e0cSJaegeuk Kim } 161939a53e0cSJaegeuk Kim 162052aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 162139a53e0cSJaegeuk Kim { 162239a53e0cSJaegeuk Kim int mask; 162339a53e0cSJaegeuk Kim int ret; 162439a53e0cSJaegeuk Kim 162539a53e0cSJaegeuk Kim addr += (nr >> 3); 162639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 162739a53e0cSJaegeuk Kim ret = mask & *addr; 162839a53e0cSJaegeuk Kim *addr &= ~mask; 162939a53e0cSJaegeuk Kim return ret; 163039a53e0cSJaegeuk Kim } 163139a53e0cSJaegeuk Kim 1632c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1633c6ac4c0eSGu Zheng { 1634c6ac4c0eSGu Zheng int mask; 1635c6ac4c0eSGu Zheng 1636c6ac4c0eSGu Zheng addr += (nr >> 3); 1637c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1638c6ac4c0eSGu Zheng *addr ^= mask; 1639c6ac4c0eSGu Zheng } 1640c6ac4c0eSGu Zheng 164139a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 164239a53e0cSJaegeuk Kim enum { 164339a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1644b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 164526de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1646ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 164739a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 164839a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 164939a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1650c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1651c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1652444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 16531001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 165434d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1655fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1656fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 165788b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 165888b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 16595fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 166002a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 16613c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 16621e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1663b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1664510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1665d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1666c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 166739a53e0cSJaegeuk Kim }; 166839a53e0cSJaegeuk Kim 1669205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 1670205b9822SJaegeuk Kim int flag, bool set) 167139a53e0cSJaegeuk Kim { 1672205b9822SJaegeuk Kim switch (flag) { 1673205b9822SJaegeuk Kim case FI_INLINE_XATTR: 1674205b9822SJaegeuk Kim case FI_INLINE_DATA: 1675205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 1676205b9822SJaegeuk Kim if (set) 1677205b9822SJaegeuk Kim return; 1678205b9822SJaegeuk Kim case FI_DATA_EXIST: 1679205b9822SJaegeuk Kim case FI_INLINE_DOTS: 16807c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1681205b9822SJaegeuk Kim } 168239a53e0cSJaegeuk Kim } 168339a53e0cSJaegeuk Kim 168491942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 168539a53e0cSJaegeuk Kim { 168691942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 168791942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 1688205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 168939a53e0cSJaegeuk Kim } 169039a53e0cSJaegeuk Kim 169191942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 169239a53e0cSJaegeuk Kim { 169391942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 169439a53e0cSJaegeuk Kim } 169539a53e0cSJaegeuk Kim 169691942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 169739a53e0cSJaegeuk Kim { 169891942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 169991942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 1700205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 170139a53e0cSJaegeuk Kim } 170239a53e0cSJaegeuk Kim 170391942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 1704444c580fSJaegeuk Kim { 170591942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 170691942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 17077c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 170839a53e0cSJaegeuk Kim } 170939a53e0cSJaegeuk Kim 1710a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 1711a1961246SJaegeuk Kim { 1712a1961246SJaegeuk Kim if (inc) 1713a1961246SJaegeuk Kim inc_nlink(inode); 1714a1961246SJaegeuk Kim else 1715a1961246SJaegeuk Kim drop_nlink(inode); 17167c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1717a1961246SJaegeuk Kim } 1718a1961246SJaegeuk Kim 17198edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 17208edd03c8SJaegeuk Kim blkcnt_t diff, bool add) 17218edd03c8SJaegeuk Kim { 172226de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 172326de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 172426de9b11SJaegeuk Kim 17258edd03c8SJaegeuk Kim inode->i_blocks = add ? inode->i_blocks + diff : 17268edd03c8SJaegeuk Kim inode->i_blocks - diff; 17277c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 172826de9b11SJaegeuk Kim if (clean || recover) 172926de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 17308edd03c8SJaegeuk Kim } 17318edd03c8SJaegeuk Kim 1732fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 1733fc9581c8SJaegeuk Kim { 173426de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 173526de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 173626de9b11SJaegeuk Kim 1737fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 1738fc9581c8SJaegeuk Kim return; 1739fc9581c8SJaegeuk Kim 1740fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 17417c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 174226de9b11SJaegeuk Kim if (clean || recover) 174326de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 174426de9b11SJaegeuk Kim } 174526de9b11SJaegeuk Kim 1746205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 1747205b9822SJaegeuk Kim { 1748205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 17497c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1750205b9822SJaegeuk Kim } 1751205b9822SJaegeuk Kim 1752205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 1753205b9822SJaegeuk Kim { 1754205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 17557c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1756205b9822SJaegeuk Kim } 1757205b9822SJaegeuk Kim 1758205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 1759205b9822SJaegeuk Kim { 1760205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 17617c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1762205b9822SJaegeuk Kim } 1763205b9822SJaegeuk Kim 176491942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 1765444c580fSJaegeuk Kim { 1766205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 1767205b9822SJaegeuk Kim 1768444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1769205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 17701001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 1771205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 177234d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1773205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 1774b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1775205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 1776510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1777205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 1778444c580fSJaegeuk Kim } 1779444c580fSJaegeuk Kim 178091942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 1781444c580fSJaegeuk Kim { 1782444c580fSJaegeuk Kim ri->i_inline = 0; 1783444c580fSJaegeuk Kim 178491942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 1785444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 178691942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 17871001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 178891942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 178934d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 179091942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 1791b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 179291942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 1793510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1794444c580fSJaegeuk Kim } 1795444c580fSJaegeuk Kim 1796987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1797987c7c31SChao Yu { 179891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 1799987c7c31SChao Yu } 1800987c7c31SChao Yu 180181ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1802de93653fSJaegeuk Kim { 180381ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1804de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1805de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1806de93653fSJaegeuk Kim } 1807de93653fSJaegeuk Kim 180865985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 180965985d93SJaegeuk Kim { 1810695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 181165985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 181265985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 181365985d93SJaegeuk Kim } 181465985d93SJaegeuk Kim 181565985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 181665985d93SJaegeuk Kim { 1817987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 181865985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 181965985d93SJaegeuk Kim else 182065985d93SJaegeuk Kim return 0; 182165985d93SJaegeuk Kim } 182265985d93SJaegeuk Kim 18230dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 18240dbdc2aeSJaegeuk Kim { 182591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 18260dbdc2aeSJaegeuk Kim } 18270dbdc2aeSJaegeuk Kim 1828b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1829b3d208f9SJaegeuk Kim { 183091942321SJaegeuk Kim clear_inode_flag(inode, FI_INLINE_DATA); 183191942321SJaegeuk Kim clear_inode_flag(inode, FI_DATA_EXIST); 1832b3d208f9SJaegeuk Kim } 1833b3d208f9SJaegeuk Kim 1834b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1835b3d208f9SJaegeuk Kim { 183691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 1837b3d208f9SJaegeuk Kim } 1838b3d208f9SJaegeuk Kim 1839510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1840510022a8SJaegeuk Kim { 184191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 1842510022a8SJaegeuk Kim } 1843510022a8SJaegeuk Kim 184488b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 184588b88a66SJaegeuk Kim { 184691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 184788b88a66SJaegeuk Kim } 184888b88a66SJaegeuk Kim 18495fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 18505fe45743SChao Yu { 18515fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 18525fe45743SChao Yu } 18535fe45743SChao Yu 185402a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 185502a1335fSJaegeuk Kim { 185691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 185702a1335fSJaegeuk Kim } 185802a1335fSJaegeuk Kim 18593c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 18603c6c2bebSJaegeuk Kim { 186191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 18623c6c2bebSJaegeuk Kim } 18633c6c2bebSJaegeuk Kim 18641e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 18651e84371fSJaegeuk Kim { 186691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 18671e84371fSJaegeuk Kim } 18681e84371fSJaegeuk Kim 18691001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 18701001b347SHuajun Li { 1871695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 18721001b347SHuajun Li return (void *)&(ri->i_addr[1]); 18731001b347SHuajun Li } 18741001b347SHuajun Li 187534d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 187634d67debSChao Yu { 187791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 187834d67debSChao Yu } 187934d67debSChao Yu 18809486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 18819486ba44SJaegeuk Kim { 18829486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 18839486ba44SJaegeuk Kim kunmap(page); 18849486ba44SJaegeuk Kim } 18859486ba44SJaegeuk Kim 1886b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1887b5492af7SJaegeuk Kim { 1888b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1889b5492af7SJaegeuk Kim } 1890b5492af7SJaegeuk Kim 1891b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1892b5492af7SJaegeuk Kim { 1893b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 18947c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1895b5492af7SJaegeuk Kim } 1896b5492af7SJaegeuk Kim 1897b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1898b5492af7SJaegeuk Kim { 1899b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 19007c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1901b5492af7SJaegeuk Kim } 1902b5492af7SJaegeuk Kim 190326787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 190426787236SJaegeuk Kim { 190526787236SJaegeuk Kim if (dsync) { 190626787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 190726787236SJaegeuk Kim bool ret; 190826787236SJaegeuk Kim 190926787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 191026787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 191126787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 191226787236SJaegeuk Kim return ret; 191326787236SJaegeuk Kim } 191426787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 191526787236SJaegeuk Kim file_keep_isize(inode) || 191626787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 191726787236SJaegeuk Kim return false; 191826787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 1919267378d4SChao Yu } 1920267378d4SChao Yu 1921267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 1922267378d4SChao Yu { 1923267378d4SChao Yu return sb->s_flags & MS_RDONLY; 1924267378d4SChao Yu } 192539a53e0cSJaegeuk Kim 192639a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 192739a53e0cSJaegeuk Kim { 1928aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 192939a53e0cSJaegeuk Kim } 193039a53e0cSJaegeuk Kim 1931eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1932eaa693f4SJaegeuk Kim { 1933eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1934eaa693f4SJaegeuk Kim return true; 1935eaa693f4SJaegeuk Kim 1936eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1937eaa693f4SJaegeuk Kim return true; 1938eaa693f4SJaegeuk Kim 1939eaa693f4SJaegeuk Kim return false; 1940eaa693f4SJaegeuk Kim } 1941eaa693f4SJaegeuk Kim 19423e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 19433e72f721SJaegeuk Kim { 19443e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 194591942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 19463e72f721SJaegeuk Kim return false; 19473e72f721SJaegeuk Kim 1948886f56f9SAl Viro return S_ISREG(inode->i_mode); 19493e72f721SJaegeuk Kim } 19503e72f721SJaegeuk Kim 19511ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 19521ecc0c5cSChao Yu size_t size, gfp_t flags) 19530414b004SJaegeuk Kim { 19542c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 19551ecc0c5cSChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) 19562c63feadSJaegeuk Kim return NULL; 19572c63feadSJaegeuk Kim #endif 19580414b004SJaegeuk Kim return kmalloc(size, flags); 19590414b004SJaegeuk Kim } 19600414b004SJaegeuk Kim 196139307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 196239307a8eSJaegeuk Kim { 196339307a8eSJaegeuk Kim void *ret; 196439307a8eSJaegeuk Kim 196539307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 196639307a8eSJaegeuk Kim if (!ret) 196739307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 196839307a8eSJaegeuk Kim return ret; 196939307a8eSJaegeuk Kim } 197039307a8eSJaegeuk Kim 197139307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 197239307a8eSJaegeuk Kim { 197339307a8eSJaegeuk Kim void *ret; 197439307a8eSJaegeuk Kim 197539307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 197639307a8eSJaegeuk Kim if (!ret) 197739307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 197839307a8eSJaegeuk Kim return ret; 197939307a8eSJaegeuk Kim } 198039307a8eSJaegeuk Kim 198139a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 198291942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 198339a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 198439a53e0cSJaegeuk Kim 198539a53e0cSJaegeuk Kim /* get offset of first page in next direct node */ 198681ca7350SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, inode) \ 198781ca7350SChao Yu ((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) : \ 198881ca7350SChao Yu (pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) / \ 198981ca7350SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode)) 19901e1bb4baSJaegeuk Kim 199139a53e0cSJaegeuk Kim /* 19922d4d9fb5SJaegeuk Kim * file.c 199339a53e0cSJaegeuk Kim */ 199439a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 1995b292dcabSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1996764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 19979a449e9cSJaegeuk Kim int f2fs_truncate(struct inode *); 199839a53e0cSJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 199939a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 200039a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 2001e9750824SNamjae Jeon int truncate_data_blocks_range(struct dnode_of_data *, int); 200239a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 200339a53e0cSJaegeuk Kim long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 200439a53e0cSJaegeuk Kim 200539a53e0cSJaegeuk Kim /* 200639a53e0cSJaegeuk Kim * inode.c 200739a53e0cSJaegeuk Kim */ 200839a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 200939936837SJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 2010e8ea9b3dSJaegeuk Kim struct inode *f2fs_iget_retry(struct super_block *, unsigned long); 20114660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 201212719ae1SJaegeuk Kim int update_inode(struct inode *, struct page *); 201312719ae1SJaegeuk Kim int update_inode_page(struct inode *); 201439a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 201539a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 201644c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 201739a53e0cSJaegeuk Kim 201839a53e0cSJaegeuk Kim /* 201939a53e0cSJaegeuk Kim * namei.c 202039a53e0cSJaegeuk Kim */ 202139a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 202239a53e0cSJaegeuk Kim 202339a53e0cSJaegeuk Kim /* 202439a53e0cSJaegeuk Kim * dir.c 202539a53e0cSJaegeuk Kim */ 2026510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 2027675f10bdSChao Yu unsigned char get_de_type(struct f2fs_dir_entry *); 20280b81d077SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *, 20296e22c691SJaegeuk Kim f2fs_hash_t, int *, struct f2fs_dentry_ptr *); 2030ed6bd4b1SChao Yu int f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 20310b81d077SJaegeuk Kim unsigned int, struct fscrypt_str *); 2032062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 2033062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 2034dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 20359421d570SChao Yu const struct qstr *, const struct qstr *, struct page *); 2036dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 2037a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 20389f7c45ccSJaegeuk Kim void f2fs_drop_nlink(struct inode *, struct inode *); 2039e7ba108aSShuoran Liu struct f2fs_dir_entry *__f2fs_find_entry(struct inode *, struct fscrypt_name *, 2040e7ba108aSShuoran Liu struct page **); 2041185de68fSAl Viro struct f2fs_dir_entry *f2fs_find_entry(struct inode *, const struct qstr *, 204239a53e0cSJaegeuk Kim struct page **); 204339a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 2044835c92d4SLinus Torvalds ino_t f2fs_inode_by_name(struct inode *, const struct qstr *, struct page **); 204539a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 204639a53e0cSJaegeuk Kim struct page *, struct inode *); 2047e7d55452SJaegeuk Kim int update_dent_inode(struct inode *, struct inode *, const struct qstr *); 2048510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 20493b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 2050675f10bdSChao Yu int f2fs_add_regular_entry(struct inode *, const struct qstr *, 20519421d570SChao Yu const struct qstr *, struct inode *, nid_t, umode_t); 2052e7ba108aSShuoran Liu int __f2fs_do_add_link(struct inode *, struct fscrypt_name*, struct inode *, 2053e7ba108aSShuoran Liu nid_t, umode_t); 2054510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 2055510022a8SJaegeuk Kim umode_t); 2056dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 2057dbeacf02SChao Yu struct inode *); 2058b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 205939a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 206039a53e0cSJaegeuk Kim 2061b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2062b7f7a5e0SAl Viro { 20632b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2064510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2065b7f7a5e0SAl Viro } 2066b7f7a5e0SAl Viro 206739a53e0cSJaegeuk Kim /* 206839a53e0cSJaegeuk Kim * super.c 206939a53e0cSJaegeuk Kim */ 20707c45729aSJaegeuk Kim int f2fs_inode_dirtied(struct inode *, bool); 20710f18b462SJaegeuk Kim void f2fs_inode_synced(struct inode *); 2072c5bda1c8SChao Yu int f2fs_commit_super(struct f2fs_sb_info *, bool); 207339a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 2074a07ef784SNamjae Jeon extern __printf(3, 4) 2075a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 2076984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 207739a53e0cSJaegeuk Kim 207839a53e0cSJaegeuk Kim /* 207939a53e0cSJaegeuk Kim * hash.c 208039a53e0cSJaegeuk Kim */ 2081eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 208239a53e0cSJaegeuk Kim 208339a53e0cSJaegeuk Kim /* 208439a53e0cSJaegeuk Kim * node.c 208539a53e0cSJaegeuk Kim */ 208639a53e0cSJaegeuk Kim struct dnode_of_data; 208739a53e0cSJaegeuk Kim struct node_info; 208839a53e0cSJaegeuk Kim 20896fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 20902dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t); 209188bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 209288bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 209339a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 20943cf45747SChao Yu pgoff_t get_next_page_offset(struct dnode_of_data *, pgoff_t); 209539a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 209639a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 20974f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 2098cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 209913ec7297SChao Yu int remove_inode_page(struct inode *); 2100a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 21018ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 210239a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 210339a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 210439a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 2105da011cc0SChao Yu void move_node_page(struct page *, int); 210626de9b11SJaegeuk Kim int fsync_node_pages(struct f2fs_sb_info *, struct inode *, 210726de9b11SJaegeuk Kim struct writeback_control *, bool); 210852681375SJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, struct writeback_control *); 21093a2ad567SChao Yu void build_free_nids(struct f2fs_sb_info *, bool); 211039a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 211139a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 211239a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 211331696580SChao Yu int try_to_free_nids(struct f2fs_sb_info *, int); 211470cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 21151c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 211639a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 211739a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 211839a53e0cSJaegeuk Kim struct f2fs_summary_block *); 211939a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 212039a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 212139a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 21226e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 212339a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 212439a53e0cSJaegeuk Kim 212539a53e0cSJaegeuk Kim /* 212639a53e0cSJaegeuk Kim * segment.c 212739a53e0cSJaegeuk Kim */ 212888b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 212929b96b54SChao Yu void drop_inmem_pages(struct inode *); 213029b96b54SChao Yu int commit_inmem_pages(struct inode *); 21312c4db1a6SJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *, bool); 21324660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 21336b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 21342163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 21355eba8c5dSJaegeuk Kim void destroy_flush_cmd_control(struct f2fs_sb_info *, bool); 213639a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 21376e2c64adSJaegeuk Kim bool is_checkpointed_data(struct f2fs_sb_info *, block_t); 21385e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 21394e6a8d9bSJaegeuk Kim void f2fs_wait_discard_bio(struct f2fs_sb_info *, block_t); 2140836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 21414b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 21423fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 214339a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 21444b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 214525290fa5SJaegeuk Kim bool exist_trim_candidates(struct f2fs_sb_info *, struct cp_control *); 214639a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 2147381722d2SChao Yu void update_meta_page(struct f2fs_sb_info *, void *, block_t); 2148577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 214905ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 215005ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 215105ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 21524356e48eSChao Yu void __f2fs_replace_block(struct f2fs_sb_info *, struct f2fs_summary *, 21534356e48eSChao Yu block_t, block_t, bool, bool); 2154528e3459SChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *, 215528bc106bSChao Yu block_t, block_t, unsigned char, bool, bool); 2156bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 2157bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 2158fec1d657SJaegeuk Kim void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool); 215908b39fbdSChao Yu void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t); 216039a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 216139a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 2162dfc08a12SChao Yu int lookup_journal_in_cursum(struct f2fs_journal *, int, unsigned int, int); 21634b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 216439a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 216539a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 21667fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 21677fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 216839a53e0cSJaegeuk Kim 216939a53e0cSJaegeuk Kim /* 217039a53e0cSJaegeuk Kim * checkpoint.c 217139a53e0cSJaegeuk Kim */ 217238f91ca8SJaegeuk Kim void f2fs_stop_checkpoint(struct f2fs_sb_info *, bool); 217339a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 217439a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 21752b947003SChao Yu struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t); 2176f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 217726879fb1SChao Yu int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool); 2178635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 217939a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 2180a49324f1SChao Yu void add_ino_entry(struct f2fs_sb_info *, nid_t, int type); 2181a49324f1SChao Yu void remove_ino_entry(struct f2fs_sb_info *, nid_t, int type); 218274ef9241SJaegeuk Kim void release_ino_entry(struct f2fs_sb_info *, bool); 2183fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 21840f18b462SJaegeuk Kim int f2fs_sync_inode_meta(struct f2fs_sb_info *); 2185cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 2186cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 218767c3758dSJaegeuk Kim void add_orphan_inode(struct inode *); 218839a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 21898c14bfadSChao Yu int recover_orphan_inodes(struct f2fs_sb_info *); 219039a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 2191a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 2192c227f912SChao Yu void remove_dirty_inode(struct inode *); 21936d5a1495SChao Yu int sync_dirty_inodes(struct f2fs_sb_info *, enum inode_type); 2194c34f42e2SChao Yu int write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 21956451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 21966e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 219739a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 219839a53e0cSJaegeuk Kim 219939a53e0cSJaegeuk Kim /* 220039a53e0cSJaegeuk Kim * data.c 220139a53e0cSJaegeuk Kim */ 2202458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 22030c3a5797SChao Yu void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *, struct inode *, 22040c3a5797SChao Yu struct page *, nid_t, enum page_type, int); 2205406657ddSChao Yu void f2fs_flush_merged_bios(struct f2fs_sb_info *); 220605ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 22070a595ebaSJaegeuk Kim int f2fs_submit_page_mbio(struct f2fs_io_info *); 22083c62be17SJaegeuk Kim struct block_device *f2fs_target_device(struct f2fs_sb_info *, 22093c62be17SJaegeuk Kim block_t, struct bio *); 22103c62be17SJaegeuk Kim int f2fs_target_device_index(struct f2fs_sb_info *, block_t); 2211216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 2212f28b3434SChao Yu void f2fs_update_data_blkaddr(struct dnode_of_data *, block_t); 221346008c6dSChao Yu int reserve_new_blocks(struct dnode_of_data *, blkcnt_t); 221439a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 2215759af1c9SFan Li int f2fs_get_block(struct dnode_of_data *, pgoff_t); 2216a7de6086SJaegeuk Kim int f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *); 2217b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 2218a56c7c6fSJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int, bool); 221943f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t); 2220a56c7c6fSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t, bool); 222164aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 222205ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 2223d323d005SChao Yu int f2fs_map_blocks(struct inode *, struct f2fs_map_blocks *, int, int); 22249ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 2225fe76b796SJaegeuk Kim void f2fs_set_page_dirty_nobuffers(struct page *); 2226487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 2227487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 22285b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 22295b7a487cSWeichao Guo int f2fs_migrate_page(struct address_space *, struct page *, struct page *, 22305b7a487cSWeichao Guo enum migrate_mode); 22315b7a487cSWeichao Guo #endif 223239a53e0cSJaegeuk Kim 223339a53e0cSJaegeuk Kim /* 223439a53e0cSJaegeuk Kim * gc.c 223539a53e0cSJaegeuk Kim */ 223639a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 223739a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 223881ca7350SChao Yu block_t start_bidx_of_node(unsigned int, struct inode *); 22397702bdbeSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *, bool, bool); 224039a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 224139a53e0cSJaegeuk Kim 224239a53e0cSJaegeuk Kim /* 224339a53e0cSJaegeuk Kim * recovery.c 224439a53e0cSJaegeuk Kim */ 22456781eabbSJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *, bool); 224639a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 224739a53e0cSJaegeuk Kim 224839a53e0cSJaegeuk Kim /* 224939a53e0cSJaegeuk Kim * debug.c 225039a53e0cSJaegeuk Kim */ 225139a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 225239a53e0cSJaegeuk Kim struct f2fs_stat_info { 225339a53e0cSJaegeuk Kim struct list_head stat_list; 225439a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 225539a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 225639a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 22575b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 22585b7ee374SChao Yu unsigned long long hit_total, total_ext; 2259c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 226035782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 226135782b23SJaegeuk Kim int inmem_pages; 22620f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 2263b8559dc2SChao Yu int nats, dirty_nats, sits, dirty_sits, free_nids, alloc_nids; 226439a53e0cSJaegeuk Kim int total_count, utilization; 226536951b38SChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 2266652be551SJaegeuk Kim int inline_xattr, inline_inode, inline_dir, orphans; 226726a28a0cSJaegeuk Kim int aw_cnt, max_aw_cnt; 2268f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 226939a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 227039a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 227139a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 227239a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 227342190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 227439a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2275e1235983SChangman Lee int bg_node_segs, bg_data_segs; 227639a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2277e1235983SChangman Lee int bg_data_blks, bg_node_blks; 227839a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 227939a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 228039a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 228139a53e0cSJaegeuk Kim 228239a53e0cSJaegeuk Kim unsigned int segment_count[2]; 228339a53e0cSJaegeuk Kim unsigned int block_count[2]; 2284b9a2c252SChangman Lee unsigned int inplace_count; 22859edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 228639a53e0cSJaegeuk Kim }; 228739a53e0cSJaegeuk Kim 2288963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2289963d4f7dSGu Zheng { 2290963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2291963d4f7dSGu Zheng } 2292963d4f7dSGu Zheng 2293942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 229442190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 229539a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2296dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 229733fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 229833fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 22995b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 23005b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 23015b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 23025b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2303d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2304d5e8f6c9SChao Yu do { \ 2305d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2306d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2307d5e8f6c9SChao Yu } while (0) 2308d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2309d5e8f6c9SChao Yu do { \ 2310d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2311d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2312d5e8f6c9SChao Yu } while (0) 23130dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 23140dbdc2aeSJaegeuk Kim do { \ 23150dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 231603e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 23170dbdc2aeSJaegeuk Kim } while (0) 23180dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 23190dbdc2aeSJaegeuk Kim do { \ 23200dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 232103e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 23220dbdc2aeSJaegeuk Kim } while (0) 23233289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 23243289c061SJaegeuk Kim do { \ 23253289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 232603e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 23273289c061SJaegeuk Kim } while (0) 23283289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 23293289c061SJaegeuk Kim do { \ 23303289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 233103e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 23323289c061SJaegeuk Kim } while (0) 2333dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2334dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2335dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2336dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2337b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2338b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 233926a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 234026a28a0cSJaegeuk Kim (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)); 234126a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 234226a28a0cSJaegeuk Kim (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)); 234326a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 234426a28a0cSJaegeuk Kim do { \ 234526a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 234626a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 234726a28a0cSJaegeuk Kim if (cur > max) \ 234826a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 234926a28a0cSJaegeuk Kim } while (0) 2350e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 235139a53e0cSJaegeuk Kim do { \ 2352963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 235339a53e0cSJaegeuk Kim (si)->tot_segs++; \ 2354e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 235539a53e0cSJaegeuk Kim si->data_segs++; \ 2356e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2357e1235983SChangman Lee } else { \ 235839a53e0cSJaegeuk Kim si->node_segs++; \ 2359e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2360e1235983SChangman Lee } \ 236139a53e0cSJaegeuk Kim } while (0) 236239a53e0cSJaegeuk Kim 236339a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 236439a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 236539a53e0cSJaegeuk Kim 2366e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 236739a53e0cSJaegeuk Kim do { \ 2368963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 236939a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 237039a53e0cSJaegeuk Kim si->data_blks += (blks); \ 2371e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 237239a53e0cSJaegeuk Kim } while (0) 237339a53e0cSJaegeuk Kim 2374e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 237539a53e0cSJaegeuk Kim do { \ 2376963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 237739a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 237839a53e0cSJaegeuk Kim si->node_blks += (blks); \ 2379e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 238039a53e0cSJaegeuk Kim } while (0) 238139a53e0cSJaegeuk Kim 238239a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 238339a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 2384787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 23854589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 238639a53e0cSJaegeuk Kim #else 2387942e0be6SChangman Lee #define stat_inc_cp_count(si) 238842190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) 238939a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 2390dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 239133fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) 239233fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) 2393dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 2394029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 239591c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 239691c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 2397d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 2398d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 23990dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 24000dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 24013289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 24023289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 240326a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) 240426a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) 240526a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) 2406dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 2407dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 2408b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 2409e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 241039a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 2411e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 2412e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 241339a53e0cSJaegeuk Kim 241439a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 241539a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2416787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 24174589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 241839a53e0cSJaegeuk Kim #endif 241939a53e0cSJaegeuk Kim 242039a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 242139a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 242239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 242339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 242439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 242539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 242639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 242739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2428cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 242939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 243029e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 24311001b347SHuajun Li 2432e18c65b2SHuajun Li /* 2433e18c65b2SHuajun Li * inline.c 2434e18c65b2SHuajun Li */ 243501b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 243601b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 2437b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 24380bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 2439e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 2440b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 2441b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 2442b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 24430342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 24446e22c691SJaegeuk Kim struct f2fs_dir_entry *find_in_inline_dir(struct inode *, 24450b81d077SJaegeuk Kim struct fscrypt_name *, struct page **); 2446201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 24479421d570SChao Yu int f2fs_add_inline_entry(struct inode *, const struct qstr *, 24489421d570SChao Yu const struct qstr *, struct inode *, nid_t, umode_t); 2449201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 2450201a05beSChao Yu struct inode *, struct inode *); 2451201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 2452d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *, struct dir_context *, 24530b81d077SJaegeuk Kim struct fscrypt_str *); 245467f8cf3cSJaegeuk Kim int f2fs_inline_data_fiemap(struct inode *, 245567f8cf3cSJaegeuk Kim struct fiemap_extent_info *, __u64, __u64); 2456cde4de12SJaegeuk Kim 2457cde4de12SJaegeuk Kim /* 24582658e50dSJaegeuk Kim * shrinker.c 24592658e50dSJaegeuk Kim */ 24602658e50dSJaegeuk Kim unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *); 24612658e50dSJaegeuk Kim unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *); 24622658e50dSJaegeuk Kim void f2fs_join_shrinker(struct f2fs_sb_info *); 24632658e50dSJaegeuk Kim void f2fs_leave_shrinker(struct f2fs_sb_info *); 24642658e50dSJaegeuk Kim 24652658e50dSJaegeuk Kim /* 2466a28ef1f5SChao Yu * extent_cache.c 2467a28ef1f5SChao Yu */ 2468a28ef1f5SChao Yu unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 2469ed3d1256SJaegeuk Kim bool f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 24705f281fabSJaegeuk Kim void f2fs_drop_extent_tree(struct inode *); 2471a28ef1f5SChao Yu unsigned int f2fs_destroy_extent_node(struct inode *); 2472a28ef1f5SChao Yu void f2fs_destroy_extent_tree(struct inode *); 2473a28ef1f5SChao Yu bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *); 2474a28ef1f5SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 247519b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 247619b2c30dSChao Yu pgoff_t, block_t, unsigned int); 2477a28ef1f5SChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 2478a28ef1f5SChao Yu int __init create_extent_cache(void); 2479a28ef1f5SChao Yu void destroy_extent_cache(void); 2480a28ef1f5SChao Yu 2481a28ef1f5SChao Yu /* 2482cde4de12SJaegeuk Kim * crypto support 2483cde4de12SJaegeuk Kim */ 24840b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2485cde4de12SJaegeuk Kim { 2486cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2487cde4de12SJaegeuk Kim } 2488cde4de12SJaegeuk Kim 2489cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2490cde4de12SJaegeuk Kim { 2491cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2492cde4de12SJaegeuk Kim file_set_encrypt(inode); 2493cde4de12SJaegeuk Kim #endif 2494cde4de12SJaegeuk Kim } 2495cde4de12SJaegeuk Kim 2496cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2497cde4de12SJaegeuk Kim { 24980b81d077SJaegeuk Kim return bio->bi_private != NULL; 2499cde4de12SJaegeuk Kim } 2500cde4de12SJaegeuk Kim 2501cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2502cde4de12SJaegeuk Kim { 2503cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2504cde4de12SJaegeuk Kim } 2505f424f664SJaegeuk Kim 25060bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 250752763a4bSJaegeuk Kim { 25080bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 250952763a4bSJaegeuk Kim } 251052763a4bSJaegeuk Kim 2511178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2512178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 25133c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2514178053e2SDamien Le Moal { 2515178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 25163c62be17SJaegeuk Kim int i; 2517178053e2SDamien Le Moal 25183c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 25193c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 25203c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 25213c62be17SJaegeuk Kim return -EINVAL; 2522178053e2SDamien Le Moal } 2523178053e2SDamien Le Moal #endif 2524178053e2SDamien Le Moal 252596ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 252696ba2decSDamien Le Moal { 252796ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 252896ba2decSDamien Le Moal 252996ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 253052763a4bSJaegeuk Kim } 253152763a4bSJaegeuk Kim 253252763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 253352763a4bSJaegeuk Kim { 253452763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 253552763a4bSJaegeuk Kim clear_opt(sbi, LFS); 253652763a4bSJaegeuk Kim 253752763a4bSJaegeuk Kim switch (mt) { 253852763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 253952763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 254052763a4bSJaegeuk Kim break; 254152763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 254252763a4bSJaegeuk Kim set_opt(sbi, LFS); 254352763a4bSJaegeuk Kim break; 254452763a4bSJaegeuk Kim } 254552763a4bSJaegeuk Kim } 254652763a4bSJaegeuk Kim 2547fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2548fcc85a4dSJaegeuk Kim { 2549fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2550886f56f9SAl Viro umode_t mode = inode->i_mode; 2551fcc85a4dSJaegeuk Kim 2552fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2553fcc85a4dSJaegeuk Kim #else 2554fcc85a4dSJaegeuk Kim return 0; 2555fcc85a4dSJaegeuk Kim #endif 2556fcc85a4dSJaegeuk Kim } 2557fcc85a4dSJaegeuk Kim 25580b81d077SJaegeuk Kim #ifndef CONFIG_F2FS_FS_ENCRYPTION 25590b81d077SJaegeuk Kim #define fscrypt_set_d_op(i) 25600b81d077SJaegeuk Kim #define fscrypt_get_ctx fscrypt_notsupp_get_ctx 25610b81d077SJaegeuk Kim #define fscrypt_release_ctx fscrypt_notsupp_release_ctx 25620b81d077SJaegeuk Kim #define fscrypt_encrypt_page fscrypt_notsupp_encrypt_page 25630b81d077SJaegeuk Kim #define fscrypt_decrypt_page fscrypt_notsupp_decrypt_page 25640b81d077SJaegeuk Kim #define fscrypt_decrypt_bio_pages fscrypt_notsupp_decrypt_bio_pages 25650b81d077SJaegeuk Kim #define fscrypt_pullback_bio_page fscrypt_notsupp_pullback_bio_page 25660b81d077SJaegeuk Kim #define fscrypt_restore_control_page fscrypt_notsupp_restore_control_page 25670b81d077SJaegeuk Kim #define fscrypt_zeroout_range fscrypt_notsupp_zeroout_range 2568db717d8eSEric Biggers #define fscrypt_ioctl_set_policy fscrypt_notsupp_ioctl_set_policy 2569db717d8eSEric Biggers #define fscrypt_ioctl_get_policy fscrypt_notsupp_ioctl_get_policy 25700b81d077SJaegeuk Kim #define fscrypt_has_permitted_context fscrypt_notsupp_has_permitted_context 25710b81d077SJaegeuk Kim #define fscrypt_inherit_context fscrypt_notsupp_inherit_context 25720b81d077SJaegeuk Kim #define fscrypt_get_encryption_info fscrypt_notsupp_get_encryption_info 25730b81d077SJaegeuk Kim #define fscrypt_put_encryption_info fscrypt_notsupp_put_encryption_info 25740b81d077SJaegeuk Kim #define fscrypt_setup_filename fscrypt_notsupp_setup_filename 25750b81d077SJaegeuk Kim #define fscrypt_free_filename fscrypt_notsupp_free_filename 25760b81d077SJaegeuk Kim #define fscrypt_fname_encrypted_size fscrypt_notsupp_fname_encrypted_size 25770b81d077SJaegeuk Kim #define fscrypt_fname_alloc_buffer fscrypt_notsupp_fname_alloc_buffer 25780b81d077SJaegeuk Kim #define fscrypt_fname_free_buffer fscrypt_notsupp_fname_free_buffer 25790b81d077SJaegeuk Kim #define fscrypt_fname_disk_to_usr fscrypt_notsupp_fname_disk_to_usr 25800b81d077SJaegeuk Kim #define fscrypt_fname_usr_to_disk fscrypt_notsupp_fname_usr_to_disk 258157e5055bSJaegeuk Kim #endif 258239a53e0cSJaegeuk Kim #endif 2583