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, 482c63feadSJaegeuk Kim FAULT_MAX, 492c63feadSJaegeuk Kim }; 502c63feadSJaegeuk Kim 5108796897SSheng Yong struct f2fs_fault_info { 5208796897SSheng Yong atomic_t inject_ops; 5308796897SSheng Yong unsigned int inject_rate; 5408796897SSheng Yong unsigned int inject_type; 5508796897SSheng Yong }; 5608796897SSheng Yong 5708796897SSheng Yong extern struct f2fs_fault_info f2fs_fault; 582c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX]; 5908796897SSheng Yong #define IS_FAULT_SET(type) (f2fs_fault.inject_type & (1 << (type))) 602c63feadSJaegeuk Kim 612c63feadSJaegeuk Kim static inline bool time_to_inject(int type) 622c63feadSJaegeuk Kim { 6308796897SSheng Yong if (!f2fs_fault.inject_rate) 6408796897SSheng Yong return false; 6508796897SSheng Yong if (type == FAULT_KMALLOC && !IS_FAULT_SET(type)) 6608796897SSheng Yong return false; 6708796897SSheng Yong else if (type == FAULT_PAGE_ALLOC && !IS_FAULT_SET(type)) 6808796897SSheng Yong return false; 6908796897SSheng Yong else if (type == FAULT_ALLOC_NID && !IS_FAULT_SET(type)) 7008796897SSheng Yong return false; 7108796897SSheng Yong else if (type == FAULT_ORPHAN && !IS_FAULT_SET(type)) 7208796897SSheng Yong return false; 7308796897SSheng Yong else if (type == FAULT_BLOCK && !IS_FAULT_SET(type)) 7408796897SSheng Yong return false; 7508796897SSheng Yong else if (type == FAULT_DIR_DEPTH && !IS_FAULT_SET(type)) 7608796897SSheng Yong return false; 7708796897SSheng Yong 7808796897SSheng Yong atomic_inc(&f2fs_fault.inject_ops); 7908796897SSheng Yong if (atomic_read(&f2fs_fault.inject_ops) >= f2fs_fault.inject_rate) { 8008796897SSheng Yong atomic_set(&f2fs_fault.inject_ops, 0); 812c63feadSJaegeuk Kim printk("%sF2FS-fs : inject %s in %pF\n", 822c63feadSJaegeuk Kim KERN_INFO, 832c63feadSJaegeuk Kim fault_name[type], 842c63feadSJaegeuk Kim __builtin_return_address(0)); 852c63feadSJaegeuk Kim return true; 862c63feadSJaegeuk Kim } 872c63feadSJaegeuk Kim return false; 882c63feadSJaegeuk Kim } 892c63feadSJaegeuk Kim #endif 902c63feadSJaegeuk Kim 9139a53e0cSJaegeuk Kim /* 9239a53e0cSJaegeuk Kim * For mount options 9339a53e0cSJaegeuk Kim */ 9439a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 9539a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 9639a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 9739a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 9839a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 9939a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 10039a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 101444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 1021001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 10334d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 10434d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 10534d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 106d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 10789672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 1086aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 109343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 11073faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 11139a53e0cSJaegeuk Kim 11239a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 11339a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 11439a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 11539a53e0cSJaegeuk Kim 11639a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 11739a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 11839a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 11939a53e0cSJaegeuk Kim 120a9841c4dSJaegeuk Kim typedef u32 block_t; /* 121a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 122a9841c4dSJaegeuk Kim * address format, __le32. 123a9841c4dSJaegeuk Kim */ 12439a53e0cSJaegeuk Kim typedef u32 nid_t; 12539a53e0cSJaegeuk Kim 12639a53e0cSJaegeuk Kim struct f2fs_mount_info { 12739a53e0cSJaegeuk Kim unsigned int opt; 12839a53e0cSJaegeuk Kim }; 12939a53e0cSJaegeuk Kim 130cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 131cde4de12SJaegeuk Kim 13276f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 13376f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 13476f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 13576f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) 13676f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 13776f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) 13876f105a2SJaegeuk Kim 13939a53e0cSJaegeuk Kim /* 14039a53e0cSJaegeuk Kim * For checkpoint manager 14139a53e0cSJaegeuk Kim */ 14239a53e0cSJaegeuk Kim enum { 14339a53e0cSJaegeuk Kim NAT_BITMAP, 14439a53e0cSJaegeuk Kim SIT_BITMAP 14539a53e0cSJaegeuk Kim }; 14639a53e0cSJaegeuk Kim 14775ab4cb8SJaegeuk Kim enum { 14875ab4cb8SJaegeuk Kim CP_UMOUNT, 149119ee914SJaegeuk Kim CP_FASTBOOT, 15075ab4cb8SJaegeuk Kim CP_SYNC, 15110027551SJaegeuk Kim CP_RECOVERY, 1524b2fecc8SJaegeuk Kim CP_DISCARD, 15375ab4cb8SJaegeuk Kim }; 15475ab4cb8SJaegeuk Kim 155bba681cbSJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 32 156bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 157bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 158a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 159a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 16060b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 161d0239e1bSJaegeuk Kim #define DEF_IDLE_INTERVAL 120 /* 2 mins */ 162bba681cbSJaegeuk Kim 16375ab4cb8SJaegeuk Kim struct cp_control { 16475ab4cb8SJaegeuk Kim int reason; 1654b2fecc8SJaegeuk Kim __u64 trim_start; 1664b2fecc8SJaegeuk Kim __u64 trim_end; 1674b2fecc8SJaegeuk Kim __u64 trim_minlen; 1684b2fecc8SJaegeuk Kim __u64 trimmed; 16975ab4cb8SJaegeuk Kim }; 17075ab4cb8SJaegeuk Kim 171662befdaSChao Yu /* 17281c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 173662befdaSChao Yu */ 174662befdaSChao Yu enum { 175662befdaSChao Yu META_CP, 176662befdaSChao Yu META_NAT, 17781c1a0f1SChao Yu META_SIT, 1784c521f49SJaegeuk Kim META_SSA, 1794c521f49SJaegeuk Kim META_POR, 180662befdaSChao Yu }; 181662befdaSChao Yu 1826451e041SJaegeuk Kim /* for the list of ino */ 1836451e041SJaegeuk Kim enum { 1846451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 185fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 186fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1876451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1886451e041SJaegeuk Kim }; 1896451e041SJaegeuk Kim 1906451e041SJaegeuk Kim struct ino_entry { 19139a53e0cSJaegeuk Kim struct list_head list; /* list head */ 19239a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 19339a53e0cSJaegeuk Kim }; 19439a53e0cSJaegeuk Kim 1952710fd7eSChao Yu /* for the list of inodes to be GCed */ 19606292073SChao Yu struct inode_entry { 19739a53e0cSJaegeuk Kim struct list_head list; /* list head */ 19839a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 19939a53e0cSJaegeuk Kim }; 20039a53e0cSJaegeuk Kim 2017fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 2027fd9e544SJaegeuk Kim struct discard_entry { 2037fd9e544SJaegeuk Kim struct list_head list; /* list head */ 2047fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 2057fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 2067fd9e544SJaegeuk Kim }; 2077fd9e544SJaegeuk Kim 20839a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 20939a53e0cSJaegeuk Kim struct fsync_inode_entry { 21039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 21139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 212c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 213c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 21439a53e0cSJaegeuk Kim }; 21539a53e0cSJaegeuk Kim 216dfc08a12SChao Yu #define nats_in_cursum(jnl) (le16_to_cpu(jnl->n_nats)) 217dfc08a12SChao Yu #define sits_in_cursum(jnl) (le16_to_cpu(jnl->n_sits)) 21839a53e0cSJaegeuk Kim 219dfc08a12SChao Yu #define nat_in_journal(jnl, i) (jnl->nat_j.entries[i].ne) 220dfc08a12SChao Yu #define nid_in_journal(jnl, i) (jnl->nat_j.entries[i].nid) 221dfc08a12SChao Yu #define sit_in_journal(jnl, i) (jnl->sit_j.entries[i].se) 222dfc08a12SChao Yu #define segno_in_journal(jnl, i) (jnl->sit_j.entries[i].segno) 22339a53e0cSJaegeuk Kim 224dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 225dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 226309cc2b6SJaegeuk Kim 227dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 22839a53e0cSJaegeuk Kim { 229dfc08a12SChao Yu int before = nats_in_cursum(journal); 230dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 23139a53e0cSJaegeuk Kim return before; 23239a53e0cSJaegeuk Kim } 23339a53e0cSJaegeuk Kim 234dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 23539a53e0cSJaegeuk Kim { 236dfc08a12SChao Yu int before = sits_in_cursum(journal); 237dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 23839a53e0cSJaegeuk Kim return before; 23939a53e0cSJaegeuk Kim } 24039a53e0cSJaegeuk Kim 241dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 242dfc08a12SChao Yu int size, int type) 243184a5cd2SChao Yu { 244184a5cd2SChao Yu if (type == NAT_JOURNAL) 245dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 246dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 247184a5cd2SChao Yu } 248184a5cd2SChao Yu 24939a53e0cSJaegeuk Kim /* 250e9750824SNamjae Jeon * ioctl commands 251e9750824SNamjae Jeon */ 252e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 253e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 254d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 255e9750824SNamjae Jeon 25688b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 25788b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 25888b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 25902a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2601e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2611e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 262c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 263456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 264d323d005SChao Yu #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) 26588b88a66SJaegeuk Kim 2660b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 2670b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 2680b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 269f424f664SJaegeuk Kim 2701abff93dSJaegeuk Kim /* 2711abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2721abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2731abff93dSJaegeuk Kim */ 2741abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2751abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2761abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2771abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 278c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 2791abff93dSJaegeuk Kim 280e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 281e9750824SNamjae Jeon /* 282e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 283e9750824SNamjae Jeon */ 284e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 285e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 28604ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 287e9750824SNamjae Jeon #endif 288e9750824SNamjae Jeon 289d323d005SChao Yu struct f2fs_defragment { 290d323d005SChao Yu u64 start; 291d323d005SChao Yu u64 len; 292d323d005SChao Yu }; 293d323d005SChao Yu 294e9750824SNamjae Jeon /* 29539a53e0cSJaegeuk Kim * For INODE and NODE manager 29639a53e0cSJaegeuk Kim */ 2977b3cd7d6SJaegeuk Kim /* for directory operations */ 2987b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 299d8c6822aSJaegeuk Kim struct inode *inode; 3007b3cd7d6SJaegeuk Kim const void *bitmap; 3017b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 3027b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 3037b3cd7d6SJaegeuk Kim int max; 3047b3cd7d6SJaegeuk Kim }; 3057b3cd7d6SJaegeuk Kim 306d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode, 307d8c6822aSJaegeuk Kim struct f2fs_dentry_ptr *d, void *src, int type) 3087b3cd7d6SJaegeuk Kim { 309d8c6822aSJaegeuk Kim d->inode = inode; 310d8c6822aSJaegeuk Kim 3117b3cd7d6SJaegeuk Kim if (type == 1) { 3127b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 3137b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 3147b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3157b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3167b3cd7d6SJaegeuk Kim d->filename = t->filename; 3177b3cd7d6SJaegeuk Kim } else { 3187b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 3197b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3207b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3217b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3227b3cd7d6SJaegeuk Kim d->filename = t->filename; 3237b3cd7d6SJaegeuk Kim } 3247b3cd7d6SJaegeuk Kim } 3257b3cd7d6SJaegeuk Kim 326dbe6a5ffSJaegeuk Kim /* 327dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 328dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 329dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 33039a53e0cSJaegeuk Kim */ 331dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 332dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 333266e97a8SJaegeuk Kim enum { 334266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 335266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 336266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 337266e97a8SJaegeuk Kim * look up a node with readahead called 3384f4124d0SChao Yu * by get_data_block. 33939a53e0cSJaegeuk Kim */ 340266e97a8SJaegeuk Kim }; 341266e97a8SJaegeuk Kim 342a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 34339a53e0cSJaegeuk Kim 344817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 345817202d9SChao Yu 34613054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 34713054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 34813054c54SChao Yu 34939a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 35013054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 35113054c54SChao Yu 35213054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 35313054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 354c11abd1aSJaegeuk Kim 35539a53e0cSJaegeuk Kim struct extent_info { 35639a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3574d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 358111d2495SMasanari Iida unsigned int len; /* length of the extent */ 35939a53e0cSJaegeuk Kim }; 36039a53e0cSJaegeuk Kim 36113054c54SChao Yu struct extent_node { 36213054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 36313054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 36413054c54SChao Yu struct extent_info ei; /* extent info */ 365201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 36613054c54SChao Yu }; 36713054c54SChao Yu 36813054c54SChao Yu struct extent_tree { 36913054c54SChao Yu nid_t ino; /* inode number */ 37013054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 37162c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 3723e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 373137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 37413054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 37568e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 37613054c54SChao Yu }; 37713054c54SChao Yu 37839a53e0cSJaegeuk Kim /* 379003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 380003a3e1dSJaegeuk Kim * 381003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 382003a3e1dSJaegeuk Kim */ 383003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 384003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 3857f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 3867f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 3877f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 388003a3e1dSJaegeuk Kim 389003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 390003a3e1dSJaegeuk Kim block_t m_pblk; 391003a3e1dSJaegeuk Kim block_t m_lblk; 392003a3e1dSJaegeuk Kim unsigned int m_len; 393003a3e1dSJaegeuk Kim unsigned int m_flags; 394da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 395003a3e1dSJaegeuk Kim }; 396003a3e1dSJaegeuk Kim 397e2b4e2bcSChao Yu /* for flag in get_data_block */ 398e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 399e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 400e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 401e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 402b439b103SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_DIO 4 40324b84912SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_AIO 5 404e2b4e2bcSChao Yu 405003a3e1dSJaegeuk Kim /* 40639a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 40739a53e0cSJaegeuk Kim */ 40839a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 409354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 410cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 411e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 41239a53e0cSJaegeuk Kim 413b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 414b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 415b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 416b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 417b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 418b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 419cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 420cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 421cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 422e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 423e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 424cde4de12SJaegeuk Kim 425ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 426ab9fa662SJaegeuk Kim 42739a53e0cSJaegeuk Kim struct f2fs_inode_info { 42839a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 42939a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 43039a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 43138431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 43239a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4336666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 43439a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 43539a53e0cSJaegeuk Kim 43639a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 43739a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 438d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 4391beba1b3SJaegeuk Kim struct percpu_counter dirty_pages; /* # of dirty pages */ 44039a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 44139a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 44239a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 443e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 44488b88a66SJaegeuk Kim 4452710fd7eSChao Yu struct list_head dirty_list; /* linked in global dirty list */ 44688b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 44788b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 4483e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 44939a53e0cSJaegeuk Kim }; 45039a53e0cSJaegeuk Kim 45139a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 452bd933d4fSChao Yu struct f2fs_extent *i_ext) 45339a53e0cSJaegeuk Kim { 454bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 455bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 456bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 45739a53e0cSJaegeuk Kim } 45839a53e0cSJaegeuk Kim 45939a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 46039a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 46139a53e0cSJaegeuk Kim { 46239a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4634d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 46439a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 46539a53e0cSJaegeuk Kim } 46639a53e0cSJaegeuk Kim 467429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 468429511cdSChao Yu u32 blk, unsigned int len) 469429511cdSChao Yu { 470429511cdSChao Yu ei->fofs = fofs; 471429511cdSChao Yu ei->blk = blk; 472429511cdSChao Yu ei->len = len; 473429511cdSChao Yu } 474429511cdSChao Yu 4750bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1, 4760bdee482SChao Yu struct extent_info *ei2) 4770bdee482SChao Yu { 4780bdee482SChao Yu return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 4790bdee482SChao Yu ei1->len == ei2->len); 4800bdee482SChao Yu } 4810bdee482SChao Yu 482429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 483429511cdSChao Yu struct extent_info *front) 484429511cdSChao Yu { 485429511cdSChao Yu return (back->fofs + back->len == front->fofs && 486429511cdSChao Yu back->blk + back->len == front->blk); 487429511cdSChao Yu } 488429511cdSChao Yu 489429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 490429511cdSChao Yu struct extent_info *back) 491429511cdSChao Yu { 492429511cdSChao Yu return __is_extent_mergeable(back, cur); 493429511cdSChao Yu } 494429511cdSChao Yu 495429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 496429511cdSChao Yu struct extent_info *front) 497429511cdSChao Yu { 498429511cdSChao Yu return __is_extent_mergeable(cur, front); 499429511cdSChao Yu } 500429511cdSChao Yu 5014abd3f5aSChao Yu static inline void __try_update_largest_extent(struct extent_tree *et, 5024abd3f5aSChao Yu struct extent_node *en) 5034abd3f5aSChao Yu { 5044abd3f5aSChao Yu if (en->ei.len > et->largest.len) 5054abd3f5aSChao Yu et->largest = en->ei; 5064abd3f5aSChao Yu } 5074abd3f5aSChao Yu 50839a53e0cSJaegeuk Kim struct f2fs_nm_info { 50939a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 51039a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 5117ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 51239a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 513cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 514ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 5152304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 51639a53e0cSJaegeuk Kim 51739a53e0cSJaegeuk Kim /* NAT cache management */ 51839a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 519309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 5208b26ef98SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 52139a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 522309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 523aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 52439a53e0cSJaegeuk Kim 52539a53e0cSJaegeuk Kim /* free node ids management */ 5268a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 52739a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 52839a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 52939a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 53039a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 53139a53e0cSJaegeuk Kim 53239a53e0cSJaegeuk Kim /* for checkpoint */ 53339a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 53439a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 53539a53e0cSJaegeuk Kim }; 53639a53e0cSJaegeuk Kim 53739a53e0cSJaegeuk Kim /* 53839a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 53939a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 54039a53e0cSJaegeuk Kim * by the data offset in a file. 54139a53e0cSJaegeuk Kim */ 54239a53e0cSJaegeuk Kim struct dnode_of_data { 54339a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 54439a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 54539a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 54639a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 54739a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 54839a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 54993bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 5503cf45747SChao Yu char cur_level; /* level of hole node page */ 5513cf45747SChao Yu char max_level; /* level of current page located */ 55239a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 55339a53e0cSJaegeuk Kim }; 55439a53e0cSJaegeuk Kim 55539a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 55639a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 55739a53e0cSJaegeuk Kim { 558d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 55939a53e0cSJaegeuk Kim dn->inode = inode; 56039a53e0cSJaegeuk Kim dn->inode_page = ipage; 56139a53e0cSJaegeuk Kim dn->node_page = npage; 56239a53e0cSJaegeuk Kim dn->nid = nid; 56339a53e0cSJaegeuk Kim } 56439a53e0cSJaegeuk Kim 56539a53e0cSJaegeuk Kim /* 56639a53e0cSJaegeuk Kim * For SIT manager 56739a53e0cSJaegeuk Kim * 56839a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 56939a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 57039a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 57139a53e0cSJaegeuk Kim * respectively. 57239a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 57339a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 57439a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 57539a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 57639a53e0cSJaegeuk Kim * data and 8 for node logs. 57739a53e0cSJaegeuk Kim */ 57839a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 57939a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 58039a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 58139a53e0cSJaegeuk Kim 58239a53e0cSJaegeuk Kim enum { 58339a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 58439a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 58539a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 58639a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 58739a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 58839a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 58938aa0889SJaegeuk Kim NO_CHECK_TYPE, 59038aa0889SJaegeuk Kim CURSEG_DIRECT_IO, /* to use for the direct IO path */ 59139a53e0cSJaegeuk Kim }; 59239a53e0cSJaegeuk Kim 5936b4afdd7SJaegeuk Kim struct flush_cmd { 5946b4afdd7SJaegeuk Kim struct completion wait; 595721bd4d5SGu Zheng struct llist_node llnode; 5966b4afdd7SJaegeuk Kim int ret; 5976b4afdd7SJaegeuk Kim }; 5986b4afdd7SJaegeuk Kim 599a688b9d9SGu Zheng struct flush_cmd_control { 600a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 601a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 602721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 603721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 604a688b9d9SGu Zheng }; 605a688b9d9SGu Zheng 60639a53e0cSJaegeuk Kim struct f2fs_sm_info { 60739a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 60839a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 60939a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 61039a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 61139a53e0cSJaegeuk Kim 61239a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 61339a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 61439a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 61539a53e0cSJaegeuk Kim 61639a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 61739a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 61839a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 61939a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 62081eb8d6eSJaegeuk Kim 62181eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 62281eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 6237fd9e544SJaegeuk Kim 6247fd9e544SJaegeuk Kim /* for small discard management */ 6257fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 6267fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 6277fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 628216fbd64SJaegeuk Kim 629bba681cbSJaegeuk Kim /* for batched trimming */ 630bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 631bba681cbSJaegeuk Kim 632184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 633184a5cd2SChao Yu 634216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 635216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 636c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 6376b4afdd7SJaegeuk Kim 6386b4afdd7SJaegeuk Kim /* for flush command control */ 639a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 640a688b9d9SGu Zheng 64139a53e0cSJaegeuk Kim }; 64239a53e0cSJaegeuk Kim 64339a53e0cSJaegeuk Kim /* 64439a53e0cSJaegeuk Kim * For superblock 64539a53e0cSJaegeuk Kim */ 64639a53e0cSJaegeuk Kim /* 64739a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 64839a53e0cSJaegeuk Kim * 64939a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 65039a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 65139a53e0cSJaegeuk Kim */ 65239a53e0cSJaegeuk Kim enum count_type { 65339a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 654c227f912SChao Yu F2FS_DIRTY_DATA, 65539a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 65639a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6578dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 65839a53e0cSJaegeuk Kim NR_COUNT_TYPE, 65939a53e0cSJaegeuk Kim }; 66039a53e0cSJaegeuk Kim 66139a53e0cSJaegeuk Kim /* 662e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 66339a53e0cSJaegeuk Kim * The available types are: 66439a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 66539a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 66639a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 66739a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 66839a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 66939a53e0cSJaegeuk Kim * with waiting the bio's completion 67039a53e0cSJaegeuk Kim * ... Only can be used with META. 67139a53e0cSJaegeuk Kim */ 6727d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 67339a53e0cSJaegeuk Kim enum page_type { 67439a53e0cSJaegeuk Kim DATA, 67539a53e0cSJaegeuk Kim NODE, 67639a53e0cSJaegeuk Kim META, 67739a53e0cSJaegeuk Kim NR_PAGE_TYPE, 67839a53e0cSJaegeuk Kim META_FLUSH, 6798ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 6808ce67cb0SJaegeuk Kim INMEM_DROP, 68128bc106bSChao Yu INMEM_REVOKE, 6828ce67cb0SJaegeuk Kim IPU, 6838ce67cb0SJaegeuk Kim OPU, 68439a53e0cSJaegeuk Kim }; 68539a53e0cSJaegeuk Kim 686458e6197SJaegeuk Kim struct f2fs_io_info { 68705ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 688458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 6897e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 6907a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 69128bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 69205ca3632SJaegeuk Kim struct page *page; /* page to be written */ 6934375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 694458e6197SJaegeuk Kim }; 695458e6197SJaegeuk Kim 69693dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 6971ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 698458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 6991ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 7001ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 701458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 702df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 7031ff7bd3bSJaegeuk Kim }; 7041ff7bd3bSJaegeuk Kim 705c227f912SChao Yu enum inode_type { 706c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 707c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 708c227f912SChao Yu NR_INODE_TYPE, 709c227f912SChao Yu }; 710c227f912SChao Yu 71167298804SChao Yu /* for inner inode cache management */ 71267298804SChao Yu struct inode_management { 71367298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 71467298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 71567298804SChao Yu struct list_head ino_list; /* inode list head */ 71667298804SChao Yu unsigned long ino_num; /* number of entries */ 71767298804SChao Yu }; 71867298804SChao Yu 719caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 720caf0047eSChao Yu enum { 721caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 722caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 723caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 724caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 725df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 726caf0047eSChao Yu }; 727caf0047eSChao Yu 7286beceb54SJaegeuk Kim enum { 7296beceb54SJaegeuk Kim CP_TIME, 730d0239e1bSJaegeuk Kim REQ_TIME, 7316beceb54SJaegeuk Kim MAX_TIME, 7326beceb54SJaegeuk Kim }; 7336beceb54SJaegeuk Kim 734b5a7aef1SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 735b5a7aef1SJaegeuk Kim #define F2FS_KEY_DESC_PREFIX "f2fs:" 736b5a7aef1SJaegeuk Kim #define F2FS_KEY_DESC_PREFIX_SIZE 5 737b5a7aef1SJaegeuk Kim #endif 73839a53e0cSJaegeuk Kim struct f2fs_sb_info { 73939a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 7405e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 74139a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 742e8240f65SChao Yu int valid_super_block; /* valid super block no */ 743caf0047eSChao Yu int s_flag; /* flags for sbi */ 74439a53e0cSJaegeuk Kim 745b5a7aef1SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 746b5a7aef1SJaegeuk Kim u8 key_prefix[F2FS_KEY_DESC_PREFIX_SIZE]; 747b5a7aef1SJaegeuk Kim u8 key_prefix_size; 748b5a7aef1SJaegeuk Kim #endif 74939a53e0cSJaegeuk Kim /* for node-related operations */ 75039a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 75139a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 75239a53e0cSJaegeuk Kim 75339a53e0cSJaegeuk Kim /* for segment-related operations */ 75439a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 7551ff7bd3bSJaegeuk Kim 7561ff7bd3bSJaegeuk Kim /* for bio operations */ 757924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 7581ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 75939a53e0cSJaegeuk Kim 76039a53e0cSJaegeuk Kim /* for checkpoint */ 76139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 76239a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 76339936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 764e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 765b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 7665463e7c1SJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 767fb51b5efSChangman Lee wait_queue_head_t cp_wait; 7686beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 7696beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 77039a53e0cSJaegeuk Kim 77167298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 7726451e041SJaegeuk Kim 7736451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 7740d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 77539a53e0cSJaegeuk Kim 776c227f912SChao Yu /* for inode management */ 777c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 778c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 77939a53e0cSJaegeuk Kim 78013054c54SChao Yu /* for extent tree cache */ 78113054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 78213054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 78313054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 78413054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 7857441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 786137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 78774fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 78813054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 78913054c54SChao Yu 79039a53e0cSJaegeuk Kim /* basic filesystem units */ 79139a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 79239a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 79339a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 79439a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 79539a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 79639a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 79739a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 79839a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 79939a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 80039a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 80139a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 80239a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 80339a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 804e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 80539a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 806ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 80739a53e0cSJaegeuk Kim 80839a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 80939a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 810a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 81139a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 81239a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 813f5730184SJaegeuk Kim atomic_t nr_wb_bios; /* # of writeback bios */ 814523be8a6SJaegeuk Kim 815523be8a6SJaegeuk Kim /* # of pages, see count_type */ 816523be8a6SJaegeuk Kim struct percpu_counter nr_pages[NR_COUNT_TYPE]; 81741382ec4SJaegeuk Kim /* # of allocated blocks */ 81841382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 81939a53e0cSJaegeuk Kim 820513c5f37SJaegeuk Kim /* valid inode count */ 821513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 822513c5f37SJaegeuk Kim 82339a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 82439a53e0cSJaegeuk Kim 82539a53e0cSJaegeuk Kim /* for cleaning operations */ 82639a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 82739a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 8285ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 82939a53e0cSJaegeuk Kim 830b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 831b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 832b1c57c1cSJaegeuk Kim 83339a53e0cSJaegeuk Kim /* 83439a53e0cSJaegeuk Kim * for stat information. 83539a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 83639a53e0cSJaegeuk Kim */ 83735b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 83839a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 83939a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 84039a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 841b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 8425b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 8435b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 8445b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 8455b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 846d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 84703e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 84803e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 84939a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 85033fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 85135b09d82SNamjae Jeon #endif 85235b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 85339a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 854b59d0baeSNamjae Jeon 855b59d0baeSNamjae Jeon /* For sysfs suppport */ 856b59d0baeSNamjae Jeon struct kobject s_kobj; 857b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 8582658e50dSJaegeuk Kim 8592658e50dSJaegeuk Kim /* For shrinker support */ 8602658e50dSJaegeuk Kim struct list_head s_list; 8612658e50dSJaegeuk Kim struct mutex umount_mutex; 8622658e50dSJaegeuk Kim unsigned int shrinker_run_no; 8638f1dbbbbSShuoran Liu 8648f1dbbbbSShuoran Liu /* For write statistics */ 8658f1dbbbbSShuoran Liu u64 sectors_written_start; 8668f1dbbbbSShuoran Liu u64 kbytes_written; 86743b6573bSKeith Mok 86843b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 86943b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 87039a53e0cSJaegeuk Kim }; 87139a53e0cSJaegeuk Kim 8728f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 8738f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 8748f1dbbbbSShuoran Liu */ 8758f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 8768f1dbbbbSShuoran Liu (((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) - \ 8778f1dbbbbSShuoran Liu s->sectors_written_start) >> 1) 8788f1dbbbbSShuoran Liu 8796beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 8806beceb54SJaegeuk Kim { 8816beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 8826beceb54SJaegeuk Kim } 8836beceb54SJaegeuk Kim 8846beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 8856beceb54SJaegeuk Kim { 8866beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 8876beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 8886beceb54SJaegeuk Kim 8896beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 8906beceb54SJaegeuk Kim } 8916beceb54SJaegeuk Kim 892d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 893d0239e1bSJaegeuk Kim { 894d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 895d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 896d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 897d0239e1bSJaegeuk Kim 898d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 899d0239e1bSJaegeuk Kim return 0; 900d0239e1bSJaegeuk Kim 901d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 902d0239e1bSJaegeuk Kim } 903d0239e1bSJaegeuk Kim 90439a53e0cSJaegeuk Kim /* 90539a53e0cSJaegeuk Kim * Inline functions 90639a53e0cSJaegeuk Kim */ 90743b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 90843b6573bSKeith Mok unsigned int length) 90943b6573bSKeith Mok { 91043b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 91143b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 91243b6573bSKeith Mok int err; 91343b6573bSKeith Mok 91443b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 91543b6573bSKeith Mok shash->flags = 0; 91643b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 91743b6573bSKeith Mok 91843b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 91943b6573bSKeith Mok BUG_ON(err); 92043b6573bSKeith Mok 92143b6573bSKeith Mok return *ctx; 92243b6573bSKeith Mok } 92343b6573bSKeith Mok 92443b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 92543b6573bSKeith Mok void *buf, size_t buf_size) 92643b6573bSKeith Mok { 92743b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 92843b6573bSKeith Mok } 92943b6573bSKeith Mok 93039a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 93139a53e0cSJaegeuk Kim { 93239a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 93339a53e0cSJaegeuk Kim } 93439a53e0cSJaegeuk Kim 93539a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 93639a53e0cSJaegeuk Kim { 93739a53e0cSJaegeuk Kim return sb->s_fs_info; 93839a53e0cSJaegeuk Kim } 93939a53e0cSJaegeuk Kim 9404081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 9414081363fSJaegeuk Kim { 9424081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 9434081363fSJaegeuk Kim } 9444081363fSJaegeuk Kim 9454081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 9464081363fSJaegeuk Kim { 9474081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 9484081363fSJaegeuk Kim } 9494081363fSJaegeuk Kim 9504081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 9514081363fSJaegeuk Kim { 9524081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 9534081363fSJaegeuk Kim } 9544081363fSJaegeuk Kim 95539a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 95639a53e0cSJaegeuk Kim { 95739a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 95839a53e0cSJaegeuk Kim } 95939a53e0cSJaegeuk Kim 96039a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 96139a53e0cSJaegeuk Kim { 96239a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 96339a53e0cSJaegeuk Kim } 96439a53e0cSJaegeuk Kim 96545590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 96645590710SGu Zheng { 96745590710SGu Zheng return (struct f2fs_node *)page_address(page); 96845590710SGu Zheng } 96945590710SGu Zheng 97058bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 97158bfaf44SJaegeuk Kim { 97258bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 97358bfaf44SJaegeuk Kim } 97458bfaf44SJaegeuk Kim 97539a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 97639a53e0cSJaegeuk Kim { 97739a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 97839a53e0cSJaegeuk Kim } 97939a53e0cSJaegeuk Kim 98039a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 98139a53e0cSJaegeuk Kim { 98239a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 98339a53e0cSJaegeuk Kim } 98439a53e0cSJaegeuk Kim 98539a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 98639a53e0cSJaegeuk Kim { 98739a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 98839a53e0cSJaegeuk Kim } 98939a53e0cSJaegeuk Kim 99039a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 99139a53e0cSJaegeuk Kim { 99239a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 99339a53e0cSJaegeuk Kim } 99439a53e0cSJaegeuk Kim 99539a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 99639a53e0cSJaegeuk Kim { 99739a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 99839a53e0cSJaegeuk Kim } 99939a53e0cSJaegeuk Kim 10009df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 10019df27d98SGu Zheng { 10029df27d98SGu Zheng return sbi->meta_inode->i_mapping; 10039df27d98SGu Zheng } 10049df27d98SGu Zheng 10054ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 10064ef51a8fSJaegeuk Kim { 10074ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 10084ef51a8fSJaegeuk Kim } 10094ef51a8fSJaegeuk Kim 1010caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 101139a53e0cSJaegeuk Kim { 1012caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 101339a53e0cSJaegeuk Kim } 101439a53e0cSJaegeuk Kim 1015caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 101639a53e0cSJaegeuk Kim { 1017caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 1018caf0047eSChao Yu } 1019caf0047eSChao Yu 1020caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1021caf0047eSChao Yu { 1022caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 102339a53e0cSJaegeuk Kim } 102439a53e0cSJaegeuk Kim 1025d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1026d71b5564SJaegeuk Kim { 1027d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1028d71b5564SJaegeuk Kim } 1029d71b5564SJaegeuk Kim 103025ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 103125ca923bSJaegeuk Kim { 103225ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 103325ca923bSJaegeuk Kim return ckpt_flags & f; 103425ca923bSJaegeuk Kim } 103525ca923bSJaegeuk Kim 103625ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 103725ca923bSJaegeuk Kim { 103825ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 103925ca923bSJaegeuk Kim ckpt_flags |= f; 104025ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 104125ca923bSJaegeuk Kim } 104225ca923bSJaegeuk Kim 104325ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 104425ca923bSJaegeuk Kim { 104525ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 104625ca923bSJaegeuk Kim ckpt_flags &= (~f); 104725ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 104825ca923bSJaegeuk Kim } 104925ca923bSJaegeuk Kim 1050e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 105139a53e0cSJaegeuk Kim { 1052e479556bSGu Zheng down_read(&sbi->cp_rwsem); 105339a53e0cSJaegeuk Kim } 105439a53e0cSJaegeuk Kim 1055e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 105639a53e0cSJaegeuk Kim { 1057e479556bSGu Zheng up_read(&sbi->cp_rwsem); 105839936837SJaegeuk Kim } 105939936837SJaegeuk Kim 1060e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 106139936837SJaegeuk Kim { 106259692b7cSYang Shi down_write(&sbi->cp_rwsem); 106339936837SJaegeuk Kim } 106439936837SJaegeuk Kim 1065e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 106639936837SJaegeuk Kim { 1067e479556bSGu Zheng up_write(&sbi->cp_rwsem); 106839a53e0cSJaegeuk Kim } 106939a53e0cSJaegeuk Kim 1070119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1071119ee914SJaegeuk Kim { 1072119ee914SJaegeuk Kim int reason = CP_SYNC; 1073119ee914SJaegeuk Kim 1074119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1075119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1076119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1077119ee914SJaegeuk Kim reason = CP_UMOUNT; 1078119ee914SJaegeuk Kim return reason; 1079119ee914SJaegeuk Kim } 1080119ee914SJaegeuk Kim 1081119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1082119ee914SJaegeuk Kim { 1083119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 1084119ee914SJaegeuk Kim } 1085119ee914SJaegeuk Kim 1086119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1087119ee914SJaegeuk Kim { 1088119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 1089119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 1090119ee914SJaegeuk Kim } 1091119ee914SJaegeuk Kim 109239a53e0cSJaegeuk Kim /* 109339a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 109439a53e0cSJaegeuk Kim */ 1095064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 109639a53e0cSJaegeuk Kim { 1097d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1098d6b7d4b3SChao Yu return -EINVAL; 1099cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1100064e0823SNamjae Jeon return -EINVAL; 1101064e0823SNamjae Jeon return 0; 110239a53e0cSJaegeuk Kim } 110339a53e0cSJaegeuk Kim 110439a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 110539a53e0cSJaegeuk Kim 110639a53e0cSJaegeuk Kim /* 110739a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 110839a53e0cSJaegeuk Kim */ 110939a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 111039a53e0cSJaegeuk Kim { 111139a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 11126c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 111339a53e0cSJaegeuk Kim else 11146c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 111539a53e0cSJaegeuk Kim } 111639a53e0cSJaegeuk Kim 11174bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 11184bc8e9bcSChao Yu { 11194bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 11204bc8e9bcSChao Yu } 11214bc8e9bcSChao Yu 112239a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 112346008c6dSChao Yu struct inode *inode, blkcnt_t *count) 112439a53e0cSJaegeuk Kim { 112539a53e0cSJaegeuk Kim block_t valid_block_count; 112639a53e0cSJaegeuk Kim 112739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 1128cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1129cb78942bSJaegeuk Kim if (time_to_inject(FAULT_BLOCK)) { 1130cb78942bSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1131cb78942bSJaegeuk Kim return false; 1132cb78942bSJaegeuk Kim } 1133cb78942bSJaegeuk Kim #endif 113439a53e0cSJaegeuk Kim valid_block_count = 113546008c6dSChao Yu sbi->total_valid_block_count + (block_t)(*count); 1136cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 113746008c6dSChao Yu *count = sbi->user_block_count - sbi->total_valid_block_count; 113846008c6dSChao Yu if (!*count) { 113939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 114039a53e0cSJaegeuk Kim return false; 114139a53e0cSJaegeuk Kim } 114246008c6dSChao Yu } 114346008c6dSChao Yu /* *count can be recalculated */ 114446008c6dSChao Yu inode->i_blocks += *count; 114546008c6dSChao Yu sbi->total_valid_block_count = 114646008c6dSChao Yu sbi->total_valid_block_count + (block_t)(*count); 114739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 114841382ec4SJaegeuk Kim 114941382ec4SJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 115039a53e0cSJaegeuk Kim return true; 115139a53e0cSJaegeuk Kim } 115239a53e0cSJaegeuk Kim 1153da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 115439a53e0cSJaegeuk Kim struct inode *inode, 115539a53e0cSJaegeuk Kim blkcnt_t count) 115639a53e0cSJaegeuk Kim { 115739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 11589850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 11599850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 116039a53e0cSJaegeuk Kim inode->i_blocks -= count; 116139a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 116239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 116339a53e0cSJaegeuk Kim } 116439a53e0cSJaegeuk Kim 116539a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 116639a53e0cSJaegeuk Kim { 1167523be8a6SJaegeuk Kim percpu_counter_inc(&sbi->nr_pages[count_type]); 1168caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 116939a53e0cSJaegeuk Kim } 117039a53e0cSJaegeuk Kim 1171a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 117239a53e0cSJaegeuk Kim { 11731beba1b3SJaegeuk Kim percpu_counter_inc(&F2FS_I(inode)->dirty_pages); 1174c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1175c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 117639a53e0cSJaegeuk Kim } 117739a53e0cSJaegeuk Kim 117839a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 117939a53e0cSJaegeuk Kim { 1180523be8a6SJaegeuk Kim percpu_counter_dec(&sbi->nr_pages[count_type]); 118139a53e0cSJaegeuk Kim } 118239a53e0cSJaegeuk Kim 1183a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 118439a53e0cSJaegeuk Kim { 11855ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 11865ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 11871fe54f9dSJaegeuk Kim return; 11881fe54f9dSJaegeuk Kim 11891beba1b3SJaegeuk Kim percpu_counter_dec(&F2FS_I(inode)->dirty_pages); 1190c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1191c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 119239a53e0cSJaegeuk Kim } 119339a53e0cSJaegeuk Kim 1194523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 119539a53e0cSJaegeuk Kim { 1196523be8a6SJaegeuk Kim return percpu_counter_sum_positive(&sbi->nr_pages[count_type]); 119739a53e0cSJaegeuk Kim } 119839a53e0cSJaegeuk Kim 11991beba1b3SJaegeuk Kim static inline s64 get_dirty_pages(struct inode *inode) 1200f8b2c1f9SJaegeuk Kim { 12011beba1b3SJaegeuk Kim return percpu_counter_sum_positive(&F2FS_I(inode)->dirty_pages); 1202f8b2c1f9SJaegeuk Kim } 1203f8b2c1f9SJaegeuk Kim 12045ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 12055ac206cfSNamjae Jeon { 12063519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1207523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1208523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1209523be8a6SJaegeuk Kim 1210523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 12115ac206cfSNamjae Jeon } 12125ac206cfSNamjae Jeon 121339a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 121439a53e0cSJaegeuk Kim { 12158b8343faSJaegeuk Kim return sbi->total_valid_block_count; 121639a53e0cSJaegeuk Kim } 121739a53e0cSJaegeuk Kim 121839a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 121939a53e0cSJaegeuk Kim { 122039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 122139a53e0cSJaegeuk Kim 122239a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 122339a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 122439a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 122539a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 122639a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 122739a53e0cSJaegeuk Kim 122839a53e0cSJaegeuk Kim return 0; 122939a53e0cSJaegeuk Kim } 123039a53e0cSJaegeuk Kim 123155141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 123255141486SWanpeng Li { 123355141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 123455141486SWanpeng Li } 123555141486SWanpeng Li 123639a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 123739a53e0cSJaegeuk Kim { 123839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 12391dbe4152SChangman Lee int offset; 12401dbe4152SChangman Lee 124155141486SWanpeng Li if (__cp_payload(sbi) > 0) { 12421dbe4152SChangman Lee if (flag == NAT_BITMAP) 12431dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 12441dbe4152SChangman Lee else 124565b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 12461dbe4152SChangman Lee } else { 12471dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 124825ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 124939a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 125039a53e0cSJaegeuk Kim } 12511dbe4152SChangman Lee } 125239a53e0cSJaegeuk Kim 125339a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 125439a53e0cSJaegeuk Kim { 125539a53e0cSJaegeuk Kim block_t start_addr; 125639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1257d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 125839a53e0cSJaegeuk Kim 125925ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 126039a53e0cSJaegeuk Kim 126139a53e0cSJaegeuk Kim /* 126239a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1263e1c42045Sarter97 * and even segment must be at cp segment 1 126439a53e0cSJaegeuk Kim */ 126539a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 126639a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 126739a53e0cSJaegeuk Kim 126839a53e0cSJaegeuk Kim return start_addr; 126939a53e0cSJaegeuk Kim } 127039a53e0cSJaegeuk Kim 127139a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 127239a53e0cSJaegeuk Kim { 127339a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 127439a53e0cSJaegeuk Kim } 127539a53e0cSJaegeuk Kim 127639a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1277ef86d709SGu Zheng struct inode *inode) 127839a53e0cSJaegeuk Kim { 127939a53e0cSJaegeuk Kim block_t valid_block_count; 128039a53e0cSJaegeuk Kim unsigned int valid_node_count; 128139a53e0cSJaegeuk Kim 128239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 128339a53e0cSJaegeuk Kim 1284ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1285cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 128639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 128739a53e0cSJaegeuk Kim return false; 128839a53e0cSJaegeuk Kim } 128939a53e0cSJaegeuk Kim 1290ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1291cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 129239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 129339a53e0cSJaegeuk Kim return false; 129439a53e0cSJaegeuk Kim } 129539a53e0cSJaegeuk Kim 129639a53e0cSJaegeuk Kim if (inode) 1297ef86d709SGu Zheng inode->i_blocks++; 1298ef86d709SGu Zheng 1299ef86d709SGu Zheng sbi->total_valid_node_count++; 1300ef86d709SGu Zheng sbi->total_valid_block_count++; 130139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 130239a53e0cSJaegeuk Kim 130341382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 130439a53e0cSJaegeuk Kim return true; 130539a53e0cSJaegeuk Kim } 130639a53e0cSJaegeuk Kim 130739a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1308ef86d709SGu Zheng struct inode *inode) 130939a53e0cSJaegeuk Kim { 131039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 131139a53e0cSJaegeuk Kim 13129850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 13139850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 13149850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 131539a53e0cSJaegeuk Kim 1316ef86d709SGu Zheng inode->i_blocks--; 1317ef86d709SGu Zheng sbi->total_valid_node_count--; 1318ef86d709SGu Zheng sbi->total_valid_block_count--; 131939a53e0cSJaegeuk Kim 132039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 132139a53e0cSJaegeuk Kim } 132239a53e0cSJaegeuk Kim 132339a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 132439a53e0cSJaegeuk Kim { 13258b8343faSJaegeuk Kim return sbi->total_valid_node_count; 132639a53e0cSJaegeuk Kim } 132739a53e0cSJaegeuk Kim 132839a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 132939a53e0cSJaegeuk Kim { 1330513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 133139a53e0cSJaegeuk Kim } 133239a53e0cSJaegeuk Kim 13330e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 133439a53e0cSJaegeuk Kim { 1335513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 133639a53e0cSJaegeuk Kim } 133739a53e0cSJaegeuk Kim 1338513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 133939a53e0cSJaegeuk Kim { 1340513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 134139a53e0cSJaegeuk Kim } 134239a53e0cSJaegeuk Kim 1343a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1344a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1345a56c7c6fSJaegeuk Kim { 1346c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1347c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1348c41f3cc3SJaegeuk Kim if (page) 1349c41f3cc3SJaegeuk Kim return page; 1350c41f3cc3SJaegeuk Kim 1351c41f3cc3SJaegeuk Kim if (time_to_inject(FAULT_PAGE_ALLOC)) 1352c41f3cc3SJaegeuk Kim return NULL; 1353c41f3cc3SJaegeuk Kim #endif 1354a56c7c6fSJaegeuk Kim if (!for_write) 1355a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1356a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1357a56c7c6fSJaegeuk Kim } 1358a56c7c6fSJaegeuk Kim 13596e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 13606e2c64adSJaegeuk Kim { 13616e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 13626e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 13636e2c64adSJaegeuk Kim 13646e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 13656e2c64adSJaegeuk Kim kunmap(dst); 13666e2c64adSJaegeuk Kim kunmap(src); 13676e2c64adSJaegeuk Kim } 13686e2c64adSJaegeuk Kim 136939a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 137039a53e0cSJaegeuk Kim { 1371031fa8ccSJaegeuk Kim if (!page) 137239a53e0cSJaegeuk Kim return; 137339a53e0cSJaegeuk Kim 137439a53e0cSJaegeuk Kim if (unlock) { 13759850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 137639a53e0cSJaegeuk Kim unlock_page(page); 137739a53e0cSJaegeuk Kim } 137809cbfeafSKirill A. Shutemov put_page(page); 137939a53e0cSJaegeuk Kim } 138039a53e0cSJaegeuk Kim 138139a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 138239a53e0cSJaegeuk Kim { 138339a53e0cSJaegeuk Kim if (dn->node_page) 138439a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 138539a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 138639a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 138739a53e0cSJaegeuk Kim dn->node_page = NULL; 138839a53e0cSJaegeuk Kim dn->inode_page = NULL; 138939a53e0cSJaegeuk Kim } 139039a53e0cSJaegeuk Kim 139139a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1392e8512d2eSGu Zheng size_t size) 139339a53e0cSJaegeuk Kim { 1394e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 139539a53e0cSJaegeuk Kim } 139639a53e0cSJaegeuk Kim 13977bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 13987bd59381SGu Zheng gfp_t flags) 13997bd59381SGu Zheng { 14007bd59381SGu Zheng void *entry; 14017bd59381SGu Zheng 140280c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 140380c54505SJaegeuk Kim if (!entry) 140480c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 14057bd59381SGu Zheng return entry; 14067bd59381SGu Zheng } 14077bd59381SGu Zheng 1408740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1409740432f8SJaegeuk Kim { 1410740432f8SJaegeuk Kim struct bio *bio; 1411740432f8SJaegeuk Kim 1412740432f8SJaegeuk Kim /* No failure on bio allocation */ 1413740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 141480c54505SJaegeuk Kim if (!bio) 141580c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1416740432f8SJaegeuk Kim return bio; 1417740432f8SJaegeuk Kim } 1418740432f8SJaegeuk Kim 14199be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 14209be32d72SJaegeuk Kim unsigned long index, void *item) 14219be32d72SJaegeuk Kim { 14229be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 14239be32d72SJaegeuk Kim cond_resched(); 14249be32d72SJaegeuk Kim } 14259be32d72SJaegeuk Kim 142639a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 142739a53e0cSJaegeuk Kim 142839a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 142939a53e0cSJaegeuk Kim { 143045590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 143139a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 143239a53e0cSJaegeuk Kim } 143339a53e0cSJaegeuk Kim 143439a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 143539a53e0cSJaegeuk Kim { 143639a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 143739a53e0cSJaegeuk Kim } 143839a53e0cSJaegeuk Kim 143939a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 144039a53e0cSJaegeuk Kim unsigned int offset) 144139a53e0cSJaegeuk Kim { 144239a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 144339a53e0cSJaegeuk Kim __le32 *addr_array; 144445590710SGu Zheng raw_node = F2FS_NODE(node_page); 144539a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 144639a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 144739a53e0cSJaegeuk Kim } 144839a53e0cSJaegeuk Kim 144939a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 145039a53e0cSJaegeuk Kim { 145139a53e0cSJaegeuk Kim int mask; 145239a53e0cSJaegeuk Kim 145339a53e0cSJaegeuk Kim addr += (nr >> 3); 145439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 145539a53e0cSJaegeuk Kim return mask & *addr; 145639a53e0cSJaegeuk Kim } 145739a53e0cSJaegeuk Kim 1458a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1459a66cdd98SJaegeuk Kim { 1460a66cdd98SJaegeuk Kim int mask; 1461a66cdd98SJaegeuk Kim 1462a66cdd98SJaegeuk Kim addr += (nr >> 3); 1463a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1464a66cdd98SJaegeuk Kim *addr |= mask; 1465a66cdd98SJaegeuk Kim } 1466a66cdd98SJaegeuk Kim 1467a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1468a66cdd98SJaegeuk Kim { 1469a66cdd98SJaegeuk Kim int mask; 1470a66cdd98SJaegeuk Kim 1471a66cdd98SJaegeuk Kim addr += (nr >> 3); 1472a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1473a66cdd98SJaegeuk Kim *addr &= ~mask; 1474a66cdd98SJaegeuk Kim } 1475a66cdd98SJaegeuk Kim 147652aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 147739a53e0cSJaegeuk Kim { 147839a53e0cSJaegeuk Kim int mask; 147939a53e0cSJaegeuk Kim int ret; 148039a53e0cSJaegeuk Kim 148139a53e0cSJaegeuk Kim addr += (nr >> 3); 148239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 148339a53e0cSJaegeuk Kim ret = mask & *addr; 148439a53e0cSJaegeuk Kim *addr |= mask; 148539a53e0cSJaegeuk Kim return ret; 148639a53e0cSJaegeuk Kim } 148739a53e0cSJaegeuk Kim 148852aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 148939a53e0cSJaegeuk Kim { 149039a53e0cSJaegeuk Kim int mask; 149139a53e0cSJaegeuk Kim int ret; 149239a53e0cSJaegeuk Kim 149339a53e0cSJaegeuk Kim addr += (nr >> 3); 149439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 149539a53e0cSJaegeuk Kim ret = mask & *addr; 149639a53e0cSJaegeuk Kim *addr &= ~mask; 149739a53e0cSJaegeuk Kim return ret; 149839a53e0cSJaegeuk Kim } 149939a53e0cSJaegeuk Kim 1500c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1501c6ac4c0eSGu Zheng { 1502c6ac4c0eSGu Zheng int mask; 1503c6ac4c0eSGu Zheng 1504c6ac4c0eSGu Zheng addr += (nr >> 3); 1505c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1506c6ac4c0eSGu Zheng *addr ^= mask; 1507c6ac4c0eSGu Zheng } 1508c6ac4c0eSGu Zheng 150939a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 151039a53e0cSJaegeuk Kim enum { 151139a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1512b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1513ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 151439a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 151539a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 151639a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1517c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1518699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 1519c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1520444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 15211001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 152234d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1523fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1524fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 152588b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 152688b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 152702a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 15283c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 15291e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1530b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1531510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1532d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1533c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 153439a53e0cSJaegeuk Kim }; 153539a53e0cSJaegeuk Kim 1536*91942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 153739a53e0cSJaegeuk Kim { 1538*91942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 1539*91942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 154039a53e0cSJaegeuk Kim } 154139a53e0cSJaegeuk Kim 1542*91942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 154339a53e0cSJaegeuk Kim { 1544*91942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 154539a53e0cSJaegeuk Kim } 154639a53e0cSJaegeuk Kim 1547*91942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 154839a53e0cSJaegeuk Kim { 1549*91942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 1550*91942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 155139a53e0cSJaegeuk Kim } 155239a53e0cSJaegeuk Kim 1553*91942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 155439a53e0cSJaegeuk Kim { 1555*91942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 1556*91942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 155739a53e0cSJaegeuk Kim } 155839a53e0cSJaegeuk Kim 1559*91942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 1560444c580fSJaegeuk Kim { 1561444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1562*91942321SJaegeuk Kim set_inode_flag(inode, FI_INLINE_XATTR); 15631001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 1564*91942321SJaegeuk Kim set_inode_flag(inode, FI_INLINE_DATA); 156534d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1566*91942321SJaegeuk Kim set_inode_flag(inode, FI_INLINE_DENTRY); 1567b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1568*91942321SJaegeuk Kim set_inode_flag(inode, FI_DATA_EXIST); 1569510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1570*91942321SJaegeuk Kim set_inode_flag(inode, FI_INLINE_DOTS); 1571444c580fSJaegeuk Kim } 1572444c580fSJaegeuk Kim 1573*91942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 1574444c580fSJaegeuk Kim { 1575444c580fSJaegeuk Kim ri->i_inline = 0; 1576444c580fSJaegeuk Kim 1577*91942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 1578444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 1579*91942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 15801001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 1581*91942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 158234d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1583*91942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 1584b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1585*91942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 1586510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1587444c580fSJaegeuk Kim } 1588444c580fSJaegeuk Kim 1589987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1590987c7c31SChao Yu { 1591*91942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 1592987c7c31SChao Yu } 1593987c7c31SChao Yu 159481ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1595de93653fSJaegeuk Kim { 159681ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1597de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1598de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1599de93653fSJaegeuk Kim } 1600de93653fSJaegeuk Kim 160165985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 160265985d93SJaegeuk Kim { 1603695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 160465985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 160565985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 160665985d93SJaegeuk Kim } 160765985d93SJaegeuk Kim 160865985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 160965985d93SJaegeuk Kim { 1610987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 161165985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 161265985d93SJaegeuk Kim else 161365985d93SJaegeuk Kim return 0; 161465985d93SJaegeuk Kim } 161565985d93SJaegeuk Kim 16160dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 16170dbdc2aeSJaegeuk Kim { 1618*91942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 16190dbdc2aeSJaegeuk Kim } 16200dbdc2aeSJaegeuk Kim 1621b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1622b3d208f9SJaegeuk Kim { 1623*91942321SJaegeuk Kim clear_inode_flag(inode, FI_INLINE_DATA); 1624*91942321SJaegeuk Kim clear_inode_flag(inode, FI_DATA_EXIST); 1625b3d208f9SJaegeuk Kim } 1626b3d208f9SJaegeuk Kim 1627b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1628b3d208f9SJaegeuk Kim { 1629*91942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 1630b3d208f9SJaegeuk Kim } 1631b3d208f9SJaegeuk Kim 1632510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1633510022a8SJaegeuk Kim { 1634*91942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 1635510022a8SJaegeuk Kim } 1636510022a8SJaegeuk Kim 163788b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 163888b88a66SJaegeuk Kim { 1639*91942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 164088b88a66SJaegeuk Kim } 164188b88a66SJaegeuk Kim 164202a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 164302a1335fSJaegeuk Kim { 1644*91942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 164502a1335fSJaegeuk Kim } 164602a1335fSJaegeuk Kim 16473c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 16483c6c2bebSJaegeuk Kim { 1649*91942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 16503c6c2bebSJaegeuk Kim } 16513c6c2bebSJaegeuk Kim 16521e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 16531e84371fSJaegeuk Kim { 1654*91942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 16551e84371fSJaegeuk Kim } 16561e84371fSJaegeuk Kim 16571001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 16581001b347SHuajun Li { 1659695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 16601001b347SHuajun Li return (void *)&(ri->i_addr[1]); 16611001b347SHuajun Li } 16621001b347SHuajun Li 166334d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 166434d67debSChao Yu { 1665*91942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 166634d67debSChao Yu } 166734d67debSChao Yu 16689486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 16699486ba44SJaegeuk Kim { 16709486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 16719486ba44SJaegeuk Kim kunmap(page); 16729486ba44SJaegeuk Kim } 16739486ba44SJaegeuk Kim 1674b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1675b5492af7SJaegeuk Kim { 1676b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1677b5492af7SJaegeuk Kim } 1678b5492af7SJaegeuk Kim 1679b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1680b5492af7SJaegeuk Kim { 1681b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1682b5492af7SJaegeuk Kim } 1683b5492af7SJaegeuk Kim 1684b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1685b5492af7SJaegeuk Kim { 1686b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1687b5492af7SJaegeuk Kim } 1688b5492af7SJaegeuk Kim 168977888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 169077888c1eSJaegeuk Kim { 169177888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 169277888c1eSJaegeuk Kim } 169377888c1eSJaegeuk Kim 16941e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 16951e968fdfSJaegeuk Kim { 16961e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 16971e968fdfSJaegeuk Kim } 16981e968fdfSJaegeuk Kim 1699eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1700eaa693f4SJaegeuk Kim { 1701eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1702eaa693f4SJaegeuk Kim return true; 1703eaa693f4SJaegeuk Kim 1704eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1705eaa693f4SJaegeuk Kim return true; 1706eaa693f4SJaegeuk Kim 1707eaa693f4SJaegeuk Kim return false; 1708eaa693f4SJaegeuk Kim } 1709eaa693f4SJaegeuk Kim 17103e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 17113e72f721SJaegeuk Kim { 17123e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 1713*91942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 17143e72f721SJaegeuk Kim return false; 17153e72f721SJaegeuk Kim 1716886f56f9SAl Viro return S_ISREG(inode->i_mode); 17173e72f721SJaegeuk Kim } 17183e72f721SJaegeuk Kim 17190414b004SJaegeuk Kim static inline void *f2fs_kmalloc(size_t size, gfp_t flags) 17200414b004SJaegeuk Kim { 17212c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 17222c63feadSJaegeuk Kim if (time_to_inject(FAULT_KMALLOC)) 17232c63feadSJaegeuk Kim return NULL; 17242c63feadSJaegeuk Kim #endif 17250414b004SJaegeuk Kim return kmalloc(size, flags); 17260414b004SJaegeuk Kim } 17270414b004SJaegeuk Kim 172839307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 172939307a8eSJaegeuk Kim { 173039307a8eSJaegeuk Kim void *ret; 173139307a8eSJaegeuk Kim 173239307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 173339307a8eSJaegeuk Kim if (!ret) 173439307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 173539307a8eSJaegeuk Kim return ret; 173639307a8eSJaegeuk Kim } 173739307a8eSJaegeuk Kim 173839307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 173939307a8eSJaegeuk Kim { 174039307a8eSJaegeuk Kim void *ret; 174139307a8eSJaegeuk Kim 174239307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 174339307a8eSJaegeuk Kim if (!ret) 174439307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 174539307a8eSJaegeuk Kim return ret; 174639307a8eSJaegeuk Kim } 174739307a8eSJaegeuk Kim 1748a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1749*91942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 1750a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1751a6dda0e6SChristoph Hellwig 1752267378d4SChao Yu /* get offset of first page in next direct node */ 175381ca7350SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, inode) \ 175481ca7350SChao Yu ((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) : \ 175581ca7350SChao Yu (pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) / \ 175681ca7350SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode)) 1757267378d4SChao Yu 175839a53e0cSJaegeuk Kim /* 175939a53e0cSJaegeuk Kim * file.c 176039a53e0cSJaegeuk Kim */ 176139a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 176239a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1763764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 1764b0154891SChao Yu int f2fs_truncate(struct inode *, bool); 17652d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 176639a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 176739a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1768b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 176939a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1770e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 177139a53e0cSJaegeuk Kim 177239a53e0cSJaegeuk Kim /* 177339a53e0cSJaegeuk Kim * inode.c 177439a53e0cSJaegeuk Kim */ 177539a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 177639a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 17774660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 177812719ae1SJaegeuk Kim int update_inode(struct inode *, struct page *); 177912719ae1SJaegeuk Kim int update_inode_page(struct inode *); 178039a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 178139a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 178244c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 178339a53e0cSJaegeuk Kim 178439a53e0cSJaegeuk Kim /* 178539a53e0cSJaegeuk Kim * namei.c 178639a53e0cSJaegeuk Kim */ 178739a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 178839a53e0cSJaegeuk Kim 178939a53e0cSJaegeuk Kim /* 179039a53e0cSJaegeuk Kim * dir.c 179139a53e0cSJaegeuk Kim */ 1792dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1793510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 1794675f10bdSChao Yu unsigned char get_de_type(struct f2fs_dir_entry *); 17950b81d077SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *, 17966e22c691SJaegeuk Kim f2fs_hash_t, int *, struct f2fs_dentry_ptr *); 17977b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 17980b81d077SJaegeuk Kim unsigned int, struct fscrypt_str *); 1799062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1800062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1801dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1802bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1803dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1804a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1805dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 180639a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 180739a53e0cSJaegeuk Kim struct page **); 180839a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 180939a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 181039a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 181139a53e0cSJaegeuk Kim struct page *, struct inode *); 1812e7d55452SJaegeuk Kim int update_dent_inode(struct inode *, struct inode *, const struct qstr *); 1813510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 18143b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1815675f10bdSChao Yu int f2fs_add_regular_entry(struct inode *, const struct qstr *, 1816675f10bdSChao Yu struct inode *, nid_t, umode_t); 1817510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1818510022a8SJaegeuk Kim umode_t); 1819dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1820dbeacf02SChao Yu struct inode *); 1821b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 182239a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 182339a53e0cSJaegeuk Kim 1824b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1825b7f7a5e0SAl Viro { 18262b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1827510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1828b7f7a5e0SAl Viro } 1829b7f7a5e0SAl Viro 183039a53e0cSJaegeuk Kim /* 183139a53e0cSJaegeuk Kim * super.c 183239a53e0cSJaegeuk Kim */ 1833c5bda1c8SChao Yu int f2fs_commit_super(struct f2fs_sb_info *, bool); 183439a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1835a07ef784SNamjae Jeon extern __printf(3, 4) 1836a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 1837984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 183839a53e0cSJaegeuk Kim 183939a53e0cSJaegeuk Kim /* 184039a53e0cSJaegeuk Kim * hash.c 184139a53e0cSJaegeuk Kim */ 1842eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 184339a53e0cSJaegeuk Kim 184439a53e0cSJaegeuk Kim /* 184539a53e0cSJaegeuk Kim * node.c 184639a53e0cSJaegeuk Kim */ 184739a53e0cSJaegeuk Kim struct dnode_of_data; 184839a53e0cSJaegeuk Kim struct node_info; 184939a53e0cSJaegeuk Kim 18506fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 18512dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t); 185288bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 185388bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 185439a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 18553cf45747SChao Yu pgoff_t get_next_page_offset(struct dnode_of_data *, pgoff_t); 185639a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 185739a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 18584f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1859cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 186013ec7297SChao Yu int remove_inode_page(struct inode *); 1861a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 18628ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 186339a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 186439a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 186539a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 186639a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 1867da011cc0SChao Yu void move_node_page(struct page *, int); 1868608514deSJaegeuk Kim int fsync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *, 1869608514deSJaegeuk Kim bool); 187052681375SJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, struct writeback_control *); 187139a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 187239a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 187339a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 187431696580SChao Yu int try_to_free_nids(struct f2fs_sb_info *, int); 187570cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 18761c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 187739a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 187839a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 187939a53e0cSJaegeuk Kim struct f2fs_summary_block *); 188039a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 188139a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 188239a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 18836e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 188439a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 188539a53e0cSJaegeuk Kim 188639a53e0cSJaegeuk Kim /* 188739a53e0cSJaegeuk Kim * segment.c 188839a53e0cSJaegeuk Kim */ 188988b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 189029b96b54SChao Yu void drop_inmem_pages(struct inode *); 189129b96b54SChao Yu int commit_inmem_pages(struct inode *); 18922c4db1a6SJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *, bool); 18934660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 18946b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 18952163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 18962163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 189739a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 18986e2c64adSJaegeuk Kim bool is_checkpointed_data(struct f2fs_sb_info *, block_t); 18995e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 1900836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 19014b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1902e90c2d28SChao Yu bool discard_next_dnode(struct f2fs_sb_info *, block_t); 19033fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 190439a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 19054b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 190639a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1907381722d2SChao Yu void update_meta_page(struct f2fs_sb_info *, void *, block_t); 1908577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 190905ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 191005ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 191105ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 19124356e48eSChao Yu void __f2fs_replace_block(struct f2fs_sb_info *, struct f2fs_summary *, 19134356e48eSChao Yu block_t, block_t, bool, bool); 1914528e3459SChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *, 191528bc106bSChao Yu block_t, block_t, unsigned char, bool, bool); 1916bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1917bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 1918fec1d657SJaegeuk Kim void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool); 191908b39fbdSChao Yu void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t); 192039a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 192139a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 1922dfc08a12SChao Yu int lookup_journal_in_cursum(struct f2fs_journal *, int, unsigned int, int); 19234b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 192439a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 192539a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 19267fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 19277fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 192839a53e0cSJaegeuk Kim 192939a53e0cSJaegeuk Kim /* 193039a53e0cSJaegeuk Kim * checkpoint.c 193139a53e0cSJaegeuk Kim */ 193238f91ca8SJaegeuk Kim void f2fs_stop_checkpoint(struct f2fs_sb_info *, bool); 193339a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 193439a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 19352b947003SChao Yu struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t); 1936f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 193726879fb1SChao Yu int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool); 1938635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 193939a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1940a49324f1SChao Yu void add_ino_entry(struct f2fs_sb_info *, nid_t, int type); 1941a49324f1SChao Yu void remove_ino_entry(struct f2fs_sb_info *, nid_t, int type); 194274ef9241SJaegeuk Kim void release_ino_entry(struct f2fs_sb_info *, bool); 1943fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1944cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1945cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 194639a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 194739a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 19488c14bfadSChao Yu int recover_orphan_inodes(struct f2fs_sb_info *); 194939a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1950a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 1951c227f912SChao Yu void remove_dirty_inode(struct inode *); 19526d5a1495SChao Yu int sync_dirty_inodes(struct f2fs_sb_info *, enum inode_type); 1953c34f42e2SChao Yu int write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 19546451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 19556e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 195639a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 195739a53e0cSJaegeuk Kim 195839a53e0cSJaegeuk Kim /* 195939a53e0cSJaegeuk Kim * data.c 196039a53e0cSJaegeuk Kim */ 1961458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 19620c3a5797SChao Yu void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *, struct inode *, 19630c3a5797SChao Yu struct page *, nid_t, enum page_type, int); 1964406657ddSChao Yu void f2fs_flush_merged_bios(struct f2fs_sb_info *); 196505ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 196605ca3632SJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_io_info *); 1967216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 1968f28b3434SChao Yu void f2fs_update_data_blkaddr(struct dnode_of_data *, block_t); 196946008c6dSChao Yu int reserve_new_blocks(struct dnode_of_data *, blkcnt_t); 197039a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1971759af1c9SFan Li int f2fs_get_block(struct dnode_of_data *, pgoff_t); 1972b439b103SJaegeuk Kim ssize_t f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *); 1973b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 1974a56c7c6fSJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int, bool); 197543f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t); 1976a56c7c6fSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t, bool); 197764aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 197805ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 1979d323d005SChao Yu int f2fs_map_blocks(struct inode *, struct f2fs_map_blocks *, int, int); 19809ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1981487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1982487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 198339a53e0cSJaegeuk Kim 198439a53e0cSJaegeuk Kim /* 198539a53e0cSJaegeuk Kim * gc.c 198639a53e0cSJaegeuk Kim */ 198739a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 198839a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 198981ca7350SChao Yu block_t start_bidx_of_node(unsigned int, struct inode *); 1990d530d4d8SChao Yu int f2fs_gc(struct f2fs_sb_info *, bool); 199139a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 199239a53e0cSJaegeuk Kim 199339a53e0cSJaegeuk Kim /* 199439a53e0cSJaegeuk Kim * recovery.c 199539a53e0cSJaegeuk Kim */ 19966781eabbSJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *, bool); 199739a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 199839a53e0cSJaegeuk Kim 199939a53e0cSJaegeuk Kim /* 200039a53e0cSJaegeuk Kim * debug.c 200139a53e0cSJaegeuk Kim */ 200239a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 200339a53e0cSJaegeuk Kim struct f2fs_stat_info { 200439a53e0cSJaegeuk Kim struct list_head stat_list; 200539a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 200639a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 200739a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 20085b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 20095b7ee374SChao Yu unsigned long long hit_total, total_ext; 2010c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 2011523be8a6SJaegeuk Kim s64 ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, inmem_pages; 2012523be8a6SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files; 2013dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 201439a53e0cSJaegeuk Kim int total_count, utilization; 2015523be8a6SJaegeuk Kim int bg_gc, wb_bios; 2016652be551SJaegeuk Kim int inline_xattr, inline_inode, inline_dir, orphans; 201739a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 201839a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 201939a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 202039a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 202139a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 202242190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 202339a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2024e1235983SChangman Lee int bg_node_segs, bg_data_segs; 202539a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2026e1235983SChangman Lee int bg_data_blks, bg_node_blks; 202739a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 202839a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 202939a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 203039a53e0cSJaegeuk Kim 203139a53e0cSJaegeuk Kim unsigned int segment_count[2]; 203239a53e0cSJaegeuk Kim unsigned int block_count[2]; 2033b9a2c252SChangman Lee unsigned int inplace_count; 20349edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 203539a53e0cSJaegeuk Kim }; 203639a53e0cSJaegeuk Kim 2037963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2038963d4f7dSGu Zheng { 2039963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2040963d4f7dSGu Zheng } 2041963d4f7dSGu Zheng 2042942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 204342190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 204439a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2045dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 204633fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 204733fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 20485b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 20495b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 20505b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 20515b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2052d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2053d5e8f6c9SChao Yu do { \ 2054d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2055d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2056d5e8f6c9SChao Yu } while (0) 2057d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2058d5e8f6c9SChao Yu do { \ 2059d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2060d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2061d5e8f6c9SChao Yu } while (0) 20620dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 20630dbdc2aeSJaegeuk Kim do { \ 20640dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 206503e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 20660dbdc2aeSJaegeuk Kim } while (0) 20670dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 20680dbdc2aeSJaegeuk Kim do { \ 20690dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 207003e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 20710dbdc2aeSJaegeuk Kim } while (0) 20723289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 20733289c061SJaegeuk Kim do { \ 20743289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 207503e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 20763289c061SJaegeuk Kim } while (0) 20773289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 20783289c061SJaegeuk Kim do { \ 20793289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 208003e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 20813289c061SJaegeuk Kim } while (0) 2082dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2083dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2084dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2085dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2086b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2087b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 2088e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 208939a53e0cSJaegeuk Kim do { \ 2090963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 209139a53e0cSJaegeuk Kim (si)->tot_segs++; \ 2092e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 209339a53e0cSJaegeuk Kim si->data_segs++; \ 2094e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2095e1235983SChangman Lee } else { \ 209639a53e0cSJaegeuk Kim si->node_segs++; \ 2097e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2098e1235983SChangman Lee } \ 209939a53e0cSJaegeuk Kim } while (0) 210039a53e0cSJaegeuk Kim 210139a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 210239a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 210339a53e0cSJaegeuk Kim 2104e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 210539a53e0cSJaegeuk Kim do { \ 2106963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 210739a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 210839a53e0cSJaegeuk Kim si->data_blks += (blks); \ 2109e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 211039a53e0cSJaegeuk Kim } while (0) 211139a53e0cSJaegeuk Kim 2112e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 211339a53e0cSJaegeuk Kim do { \ 2114963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 211539a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 211639a53e0cSJaegeuk Kim si->node_blks += (blks); \ 2117e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 211839a53e0cSJaegeuk Kim } while (0) 211939a53e0cSJaegeuk Kim 212039a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 212139a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 2122787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 21234589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 212439a53e0cSJaegeuk Kim #else 2125942e0be6SChangman Lee #define stat_inc_cp_count(si) 212642190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) 212739a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 2128dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 212933fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) 213033fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) 2131dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 2132029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 213391c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 213491c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 2135d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 2136d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 21370dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 21380dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 21393289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 21403289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 2141dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 2142dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 2143b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 2144e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 214539a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 2146e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 2147e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 214839a53e0cSJaegeuk Kim 214939a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 215039a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2151787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 21524589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 215339a53e0cSJaegeuk Kim #endif 215439a53e0cSJaegeuk Kim 215539a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 215639a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 215739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 215839a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 215939a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 216039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 216139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 216239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2163cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 216439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 216529e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 21661001b347SHuajun Li 2167e18c65b2SHuajun Li /* 2168e18c65b2SHuajun Li * inline.c 2169e18c65b2SHuajun Li */ 217001b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 217101b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 2172b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 21730bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 2174e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 2175b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 2176b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 2177b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 21780342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 21796e22c691SJaegeuk Kim struct f2fs_dir_entry *find_in_inline_dir(struct inode *, 21800b81d077SJaegeuk Kim struct fscrypt_name *, struct page **); 2181201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 2182201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 2183510022a8SJaegeuk Kim int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 2184510022a8SJaegeuk Kim nid_t, umode_t); 2185201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 2186201a05beSChao Yu struct inode *, struct inode *); 2187201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 2188d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *, struct dir_context *, 21890b81d077SJaegeuk Kim struct fscrypt_str *); 219067f8cf3cSJaegeuk Kim int f2fs_inline_data_fiemap(struct inode *, 219167f8cf3cSJaegeuk Kim struct fiemap_extent_info *, __u64, __u64); 2192cde4de12SJaegeuk Kim 2193cde4de12SJaegeuk Kim /* 21942658e50dSJaegeuk Kim * shrinker.c 21952658e50dSJaegeuk Kim */ 21962658e50dSJaegeuk Kim unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *); 21972658e50dSJaegeuk Kim unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *); 21982658e50dSJaegeuk Kim void f2fs_join_shrinker(struct f2fs_sb_info *); 21992658e50dSJaegeuk Kim void f2fs_leave_shrinker(struct f2fs_sb_info *); 22002658e50dSJaegeuk Kim 22012658e50dSJaegeuk Kim /* 2202a28ef1f5SChao Yu * extent_cache.c 2203a28ef1f5SChao Yu */ 2204a28ef1f5SChao Yu unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 2205ed3d1256SJaegeuk Kim bool f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 2206a28ef1f5SChao Yu unsigned int f2fs_destroy_extent_node(struct inode *); 2207a28ef1f5SChao Yu void f2fs_destroy_extent_tree(struct inode *); 2208a28ef1f5SChao Yu bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *); 2209a28ef1f5SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 221019b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 221119b2c30dSChao Yu pgoff_t, block_t, unsigned int); 2212a28ef1f5SChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 2213a28ef1f5SChao Yu int __init create_extent_cache(void); 2214a28ef1f5SChao Yu void destroy_extent_cache(void); 2215a28ef1f5SChao Yu 2216a28ef1f5SChao Yu /* 2217cde4de12SJaegeuk Kim * crypto support 2218cde4de12SJaegeuk Kim */ 22190b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2220cde4de12SJaegeuk Kim { 2221cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2222cde4de12SJaegeuk Kim } 2223cde4de12SJaegeuk Kim 2224cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2225cde4de12SJaegeuk Kim { 2226cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2227cde4de12SJaegeuk Kim file_set_encrypt(inode); 2228cde4de12SJaegeuk Kim #endif 2229cde4de12SJaegeuk Kim } 2230cde4de12SJaegeuk Kim 2231cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2232cde4de12SJaegeuk Kim { 22330b81d077SJaegeuk Kim return bio->bi_private != NULL; 2234cde4de12SJaegeuk Kim } 2235cde4de12SJaegeuk Kim 2236cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2237cde4de12SJaegeuk Kim { 2238cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2239cde4de12SJaegeuk Kim } 2240f424f664SJaegeuk Kim 2241fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2242fcc85a4dSJaegeuk Kim { 2243fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2244886f56f9SAl Viro umode_t mode = inode->i_mode; 2245fcc85a4dSJaegeuk Kim 2246fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2247fcc85a4dSJaegeuk Kim #else 2248fcc85a4dSJaegeuk Kim return 0; 2249fcc85a4dSJaegeuk Kim #endif 2250fcc85a4dSJaegeuk Kim } 2251fcc85a4dSJaegeuk Kim 22520b81d077SJaegeuk Kim #ifndef CONFIG_F2FS_FS_ENCRYPTION 22530b81d077SJaegeuk Kim #define fscrypt_set_d_op(i) 22540b81d077SJaegeuk Kim #define fscrypt_get_ctx fscrypt_notsupp_get_ctx 22550b81d077SJaegeuk Kim #define fscrypt_release_ctx fscrypt_notsupp_release_ctx 22560b81d077SJaegeuk Kim #define fscrypt_encrypt_page fscrypt_notsupp_encrypt_page 22570b81d077SJaegeuk Kim #define fscrypt_decrypt_page fscrypt_notsupp_decrypt_page 22580b81d077SJaegeuk Kim #define fscrypt_decrypt_bio_pages fscrypt_notsupp_decrypt_bio_pages 22590b81d077SJaegeuk Kim #define fscrypt_pullback_bio_page fscrypt_notsupp_pullback_bio_page 22600b81d077SJaegeuk Kim #define fscrypt_restore_control_page fscrypt_notsupp_restore_control_page 22610b81d077SJaegeuk Kim #define fscrypt_zeroout_range fscrypt_notsupp_zeroout_range 22620b81d077SJaegeuk Kim #define fscrypt_process_policy fscrypt_notsupp_process_policy 22630b81d077SJaegeuk Kim #define fscrypt_get_policy fscrypt_notsupp_get_policy 22640b81d077SJaegeuk Kim #define fscrypt_has_permitted_context fscrypt_notsupp_has_permitted_context 22650b81d077SJaegeuk Kim #define fscrypt_inherit_context fscrypt_notsupp_inherit_context 22660b81d077SJaegeuk Kim #define fscrypt_get_encryption_info fscrypt_notsupp_get_encryption_info 22670b81d077SJaegeuk Kim #define fscrypt_put_encryption_info fscrypt_notsupp_put_encryption_info 22680b81d077SJaegeuk Kim #define fscrypt_setup_filename fscrypt_notsupp_setup_filename 22690b81d077SJaegeuk Kim #define fscrypt_free_filename fscrypt_notsupp_free_filename 22700b81d077SJaegeuk Kim #define fscrypt_fname_encrypted_size fscrypt_notsupp_fname_encrypted_size 22710b81d077SJaegeuk Kim #define fscrypt_fname_alloc_buffer fscrypt_notsupp_fname_alloc_buffer 22720b81d077SJaegeuk Kim #define fscrypt_fname_free_buffer fscrypt_notsupp_fname_free_buffer 22730b81d077SJaegeuk Kim #define fscrypt_fname_disk_to_usr fscrypt_notsupp_fname_disk_to_usr 22740b81d077SJaegeuk Kim #define fscrypt_fname_usr_to_disk fscrypt_notsupp_fname_usr_to_disk 227557e5055bSJaegeuk Kim #endif 227639a53e0cSJaegeuk Kim #endif 2277