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 4039a53e0cSJaegeuk Kim /* 4139a53e0cSJaegeuk Kim * For mount options 4239a53e0cSJaegeuk Kim */ 4339a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 4439a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 4539a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 4639a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 4739a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 4839a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 4939a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 50444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 511001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 5234d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 5334d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 5434d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 55d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 5689672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 576aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 58343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 59*73faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 6039a53e0cSJaegeuk Kim 6139a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 6239a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 6339a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 6439a53e0cSJaegeuk Kim 6539a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 6639a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 6739a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 6839a53e0cSJaegeuk Kim 69a9841c4dSJaegeuk Kim typedef u32 block_t; /* 70a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 71a9841c4dSJaegeuk Kim * address format, __le32. 72a9841c4dSJaegeuk Kim */ 7339a53e0cSJaegeuk Kim typedef u32 nid_t; 7439a53e0cSJaegeuk Kim 7539a53e0cSJaegeuk Kim struct f2fs_mount_info { 7639a53e0cSJaegeuk Kim unsigned int opt; 7739a53e0cSJaegeuk Kim }; 7839a53e0cSJaegeuk Kim 79cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 80cde4de12SJaegeuk Kim 8176f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 8276f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 8376f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 8476f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) 8576f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 8676f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) 8776f105a2SJaegeuk Kim 8839a53e0cSJaegeuk Kim /* 8939a53e0cSJaegeuk Kim * For checkpoint manager 9039a53e0cSJaegeuk Kim */ 9139a53e0cSJaegeuk Kim enum { 9239a53e0cSJaegeuk Kim NAT_BITMAP, 9339a53e0cSJaegeuk Kim SIT_BITMAP 9439a53e0cSJaegeuk Kim }; 9539a53e0cSJaegeuk Kim 9675ab4cb8SJaegeuk Kim enum { 9775ab4cb8SJaegeuk Kim CP_UMOUNT, 98119ee914SJaegeuk Kim CP_FASTBOOT, 9975ab4cb8SJaegeuk Kim CP_SYNC, 10010027551SJaegeuk Kim CP_RECOVERY, 1014b2fecc8SJaegeuk Kim CP_DISCARD, 10275ab4cb8SJaegeuk Kim }; 10375ab4cb8SJaegeuk Kim 104bba681cbSJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 32 105bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 106bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 107a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 108a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 10960b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 110d0239e1bSJaegeuk Kim #define DEF_IDLE_INTERVAL 120 /* 2 mins */ 111bba681cbSJaegeuk Kim 11275ab4cb8SJaegeuk Kim struct cp_control { 11375ab4cb8SJaegeuk Kim int reason; 1144b2fecc8SJaegeuk Kim __u64 trim_start; 1154b2fecc8SJaegeuk Kim __u64 trim_end; 1164b2fecc8SJaegeuk Kim __u64 trim_minlen; 1174b2fecc8SJaegeuk Kim __u64 trimmed; 11875ab4cb8SJaegeuk Kim }; 11975ab4cb8SJaegeuk Kim 120662befdaSChao Yu /* 12181c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 122662befdaSChao Yu */ 123662befdaSChao Yu enum { 124662befdaSChao Yu META_CP, 125662befdaSChao Yu META_NAT, 12681c1a0f1SChao Yu META_SIT, 1274c521f49SJaegeuk Kim META_SSA, 1284c521f49SJaegeuk Kim META_POR, 129662befdaSChao Yu }; 130662befdaSChao Yu 1316451e041SJaegeuk Kim /* for the list of ino */ 1326451e041SJaegeuk Kim enum { 1336451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 134fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 135fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1366451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1376451e041SJaegeuk Kim }; 1386451e041SJaegeuk Kim 1396451e041SJaegeuk Kim struct ino_entry { 14039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 14139a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 14239a53e0cSJaegeuk Kim }; 14339a53e0cSJaegeuk Kim 1442710fd7eSChao Yu /* for the list of inodes to be GCed */ 14506292073SChao Yu struct inode_entry { 14639a53e0cSJaegeuk Kim struct list_head list; /* list head */ 14739a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 14839a53e0cSJaegeuk Kim }; 14939a53e0cSJaegeuk Kim 1507fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1517fd9e544SJaegeuk Kim struct discard_entry { 1527fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1537fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1547fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1557fd9e544SJaegeuk Kim }; 1567fd9e544SJaegeuk Kim 15739a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 15839a53e0cSJaegeuk Kim struct fsync_inode_entry { 15939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 16039a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 161c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 162c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 16339a53e0cSJaegeuk Kim }; 16439a53e0cSJaegeuk Kim 165dfc08a12SChao Yu #define nats_in_cursum(jnl) (le16_to_cpu(jnl->n_nats)) 166dfc08a12SChao Yu #define sits_in_cursum(jnl) (le16_to_cpu(jnl->n_sits)) 16739a53e0cSJaegeuk Kim 168dfc08a12SChao Yu #define nat_in_journal(jnl, i) (jnl->nat_j.entries[i].ne) 169dfc08a12SChao Yu #define nid_in_journal(jnl, i) (jnl->nat_j.entries[i].nid) 170dfc08a12SChao Yu #define sit_in_journal(jnl, i) (jnl->sit_j.entries[i].se) 171dfc08a12SChao Yu #define segno_in_journal(jnl, i) (jnl->sit_j.entries[i].segno) 17239a53e0cSJaegeuk Kim 173dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 174dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 175309cc2b6SJaegeuk Kim 176dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 17739a53e0cSJaegeuk Kim { 178dfc08a12SChao Yu int before = nats_in_cursum(journal); 179dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 18039a53e0cSJaegeuk Kim return before; 18139a53e0cSJaegeuk Kim } 18239a53e0cSJaegeuk Kim 183dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 18439a53e0cSJaegeuk Kim { 185dfc08a12SChao Yu int before = sits_in_cursum(journal); 186dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 18739a53e0cSJaegeuk Kim return before; 18839a53e0cSJaegeuk Kim } 18939a53e0cSJaegeuk Kim 190dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 191dfc08a12SChao Yu int size, int type) 192184a5cd2SChao Yu { 193184a5cd2SChao Yu if (type == NAT_JOURNAL) 194dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 195dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 196184a5cd2SChao Yu } 197184a5cd2SChao Yu 19839a53e0cSJaegeuk Kim /* 199e9750824SNamjae Jeon * ioctl commands 200e9750824SNamjae Jeon */ 201e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 202e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 203d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 204e9750824SNamjae Jeon 20588b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 20688b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 20788b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 20802a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2091e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2101e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 211c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 212456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 213d323d005SChao Yu #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) 21488b88a66SJaegeuk Kim 2150b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 2160b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 2170b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 218f424f664SJaegeuk Kim 2191abff93dSJaegeuk Kim /* 2201abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2211abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2221abff93dSJaegeuk Kim */ 2231abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2241abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2251abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2261abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 227c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 2281abff93dSJaegeuk Kim 229e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 230e9750824SNamjae Jeon /* 231e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 232e9750824SNamjae Jeon */ 233e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 234e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 23504ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 236e9750824SNamjae Jeon #endif 237e9750824SNamjae Jeon 238d323d005SChao Yu struct f2fs_defragment { 239d323d005SChao Yu u64 start; 240d323d005SChao Yu u64 len; 241d323d005SChao Yu }; 242d323d005SChao Yu 243e9750824SNamjae Jeon /* 24439a53e0cSJaegeuk Kim * For INODE and NODE manager 24539a53e0cSJaegeuk Kim */ 2467b3cd7d6SJaegeuk Kim /* for directory operations */ 2477b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 248d8c6822aSJaegeuk Kim struct inode *inode; 2497b3cd7d6SJaegeuk Kim const void *bitmap; 2507b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 2517b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 2527b3cd7d6SJaegeuk Kim int max; 2537b3cd7d6SJaegeuk Kim }; 2547b3cd7d6SJaegeuk Kim 255d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode, 256d8c6822aSJaegeuk Kim struct f2fs_dentry_ptr *d, void *src, int type) 2577b3cd7d6SJaegeuk Kim { 258d8c6822aSJaegeuk Kim d->inode = inode; 259d8c6822aSJaegeuk Kim 2607b3cd7d6SJaegeuk Kim if (type == 1) { 2617b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 2627b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 2637b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2647b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 2657b3cd7d6SJaegeuk Kim d->filename = t->filename; 2667b3cd7d6SJaegeuk Kim } else { 2677b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 2687b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 2697b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2707b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 2717b3cd7d6SJaegeuk Kim d->filename = t->filename; 2727b3cd7d6SJaegeuk Kim } 2737b3cd7d6SJaegeuk Kim } 2747b3cd7d6SJaegeuk Kim 275dbe6a5ffSJaegeuk Kim /* 276dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 277dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 278dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 27939a53e0cSJaegeuk Kim */ 280dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 281dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 282266e97a8SJaegeuk Kim enum { 283266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 284266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 285266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 286266e97a8SJaegeuk Kim * look up a node with readahead called 2874f4124d0SChao Yu * by get_data_block. 28839a53e0cSJaegeuk Kim */ 289266e97a8SJaegeuk Kim }; 290266e97a8SJaegeuk Kim 291a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 29239a53e0cSJaegeuk Kim 293817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 294817202d9SChao Yu 29513054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 29613054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 29713054c54SChao Yu 29839a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 29913054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 30013054c54SChao Yu 30113054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 30213054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 303c11abd1aSJaegeuk Kim 30439a53e0cSJaegeuk Kim struct extent_info { 30539a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3064d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 307111d2495SMasanari Iida unsigned int len; /* length of the extent */ 30839a53e0cSJaegeuk Kim }; 30939a53e0cSJaegeuk Kim 31013054c54SChao Yu struct extent_node { 31113054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 31213054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 31313054c54SChao Yu struct extent_info ei; /* extent info */ 314201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 31513054c54SChao Yu }; 31613054c54SChao Yu 31713054c54SChao Yu struct extent_tree { 31813054c54SChao Yu nid_t ino; /* inode number */ 31913054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 32062c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 3213e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 322137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 32313054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 32468e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 32513054c54SChao Yu }; 32613054c54SChao Yu 32739a53e0cSJaegeuk Kim /* 328003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 329003a3e1dSJaegeuk Kim * 330003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 331003a3e1dSJaegeuk Kim */ 332003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 333003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 3347f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 3357f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 3367f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 337003a3e1dSJaegeuk Kim 338003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 339003a3e1dSJaegeuk Kim block_t m_pblk; 340003a3e1dSJaegeuk Kim block_t m_lblk; 341003a3e1dSJaegeuk Kim unsigned int m_len; 342003a3e1dSJaegeuk Kim unsigned int m_flags; 343da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 344003a3e1dSJaegeuk Kim }; 345003a3e1dSJaegeuk Kim 346e2b4e2bcSChao Yu /* for flag in get_data_block */ 347e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 348e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 349e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 350e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 351b439b103SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_DIO 4 35224b84912SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_AIO 5 353e2b4e2bcSChao Yu 354003a3e1dSJaegeuk Kim /* 35539a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 35639a53e0cSJaegeuk Kim */ 35739a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 358354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 359cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 360e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 36139a53e0cSJaegeuk Kim 362b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 363b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 364b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 365b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 366b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 367b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 368cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 369cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 370cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 371e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 372e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 373cde4de12SJaegeuk Kim 374ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 375ab9fa662SJaegeuk Kim 37639a53e0cSJaegeuk Kim struct f2fs_inode_info { 37739a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 37839a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 37939a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 38038431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 38139a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 3826666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 38339a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 38439a53e0cSJaegeuk Kim 38539a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 38639a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 387d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 388a7ffdbe2SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 38939a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 39039a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 39139a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 392e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 39388b88a66SJaegeuk Kim 3942710fd7eSChao Yu struct list_head dirty_list; /* linked in global dirty list */ 39588b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 39688b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 3973e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 39839a53e0cSJaegeuk Kim }; 39939a53e0cSJaegeuk Kim 40039a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 40139a53e0cSJaegeuk Kim struct f2fs_extent i_ext) 40239a53e0cSJaegeuk Kim { 40339a53e0cSJaegeuk Kim ext->fofs = le32_to_cpu(i_ext.fofs); 4044d0b0bd4SChao Yu ext->blk = le32_to_cpu(i_ext.blk); 40539a53e0cSJaegeuk Kim ext->len = le32_to_cpu(i_ext.len); 40639a53e0cSJaegeuk Kim } 40739a53e0cSJaegeuk Kim 40839a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 40939a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 41039a53e0cSJaegeuk Kim { 41139a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4124d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 41339a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 41439a53e0cSJaegeuk Kim } 41539a53e0cSJaegeuk Kim 416429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 417429511cdSChao Yu u32 blk, unsigned int len) 418429511cdSChao Yu { 419429511cdSChao Yu ei->fofs = fofs; 420429511cdSChao Yu ei->blk = blk; 421429511cdSChao Yu ei->len = len; 422429511cdSChao Yu } 423429511cdSChao Yu 4240bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1, 4250bdee482SChao Yu struct extent_info *ei2) 4260bdee482SChao Yu { 4270bdee482SChao Yu return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 4280bdee482SChao Yu ei1->len == ei2->len); 4290bdee482SChao Yu } 4300bdee482SChao Yu 431429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 432429511cdSChao Yu struct extent_info *front) 433429511cdSChao Yu { 434429511cdSChao Yu return (back->fofs + back->len == front->fofs && 435429511cdSChao Yu back->blk + back->len == front->blk); 436429511cdSChao Yu } 437429511cdSChao Yu 438429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 439429511cdSChao Yu struct extent_info *back) 440429511cdSChao Yu { 441429511cdSChao Yu return __is_extent_mergeable(back, cur); 442429511cdSChao Yu } 443429511cdSChao Yu 444429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 445429511cdSChao Yu struct extent_info *front) 446429511cdSChao Yu { 447429511cdSChao Yu return __is_extent_mergeable(cur, front); 448429511cdSChao Yu } 449429511cdSChao Yu 4504abd3f5aSChao Yu static inline void __try_update_largest_extent(struct extent_tree *et, 4514abd3f5aSChao Yu struct extent_node *en) 4524abd3f5aSChao Yu { 4534abd3f5aSChao Yu if (en->ei.len > et->largest.len) 4544abd3f5aSChao Yu et->largest = en->ei; 4554abd3f5aSChao Yu } 4564abd3f5aSChao Yu 45739a53e0cSJaegeuk Kim struct f2fs_nm_info { 45839a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 45939a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 4607ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 46139a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 462cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 463ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 4642304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 46539a53e0cSJaegeuk Kim 46639a53e0cSJaegeuk Kim /* NAT cache management */ 46739a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 468309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 4698b26ef98SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 47039a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 471309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 472aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 47339a53e0cSJaegeuk Kim 47439a53e0cSJaegeuk Kim /* free node ids management */ 4758a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 47639a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 47739a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 47839a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 47939a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 48039a53e0cSJaegeuk Kim 48139a53e0cSJaegeuk Kim /* for checkpoint */ 48239a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 48339a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 48439a53e0cSJaegeuk Kim }; 48539a53e0cSJaegeuk Kim 48639a53e0cSJaegeuk Kim /* 48739a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 48839a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 48939a53e0cSJaegeuk Kim * by the data offset in a file. 49039a53e0cSJaegeuk Kim */ 49139a53e0cSJaegeuk Kim struct dnode_of_data { 49239a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 49339a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 49439a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 49539a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 49639a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 49739a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 49893bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 4993cf45747SChao Yu char cur_level; /* level of hole node page */ 5003cf45747SChao Yu char max_level; /* level of current page located */ 50139a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 50239a53e0cSJaegeuk Kim }; 50339a53e0cSJaegeuk Kim 50439a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 50539a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 50639a53e0cSJaegeuk Kim { 507d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 50839a53e0cSJaegeuk Kim dn->inode = inode; 50939a53e0cSJaegeuk Kim dn->inode_page = ipage; 51039a53e0cSJaegeuk Kim dn->node_page = npage; 51139a53e0cSJaegeuk Kim dn->nid = nid; 51239a53e0cSJaegeuk Kim } 51339a53e0cSJaegeuk Kim 51439a53e0cSJaegeuk Kim /* 51539a53e0cSJaegeuk Kim * For SIT manager 51639a53e0cSJaegeuk Kim * 51739a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 51839a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 51939a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 52039a53e0cSJaegeuk Kim * respectively. 52139a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 52239a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 52339a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 52439a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 52539a53e0cSJaegeuk Kim * data and 8 for node logs. 52639a53e0cSJaegeuk Kim */ 52739a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 52839a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 52939a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 53039a53e0cSJaegeuk Kim 53139a53e0cSJaegeuk Kim enum { 53239a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 53339a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 53439a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 53539a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 53639a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 53739a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 53838aa0889SJaegeuk Kim NO_CHECK_TYPE, 53938aa0889SJaegeuk Kim CURSEG_DIRECT_IO, /* to use for the direct IO path */ 54039a53e0cSJaegeuk Kim }; 54139a53e0cSJaegeuk Kim 5426b4afdd7SJaegeuk Kim struct flush_cmd { 5436b4afdd7SJaegeuk Kim struct completion wait; 544721bd4d5SGu Zheng struct llist_node llnode; 5456b4afdd7SJaegeuk Kim int ret; 5466b4afdd7SJaegeuk Kim }; 5476b4afdd7SJaegeuk Kim 548a688b9d9SGu Zheng struct flush_cmd_control { 549a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 550a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 551721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 552721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 553a688b9d9SGu Zheng }; 554a688b9d9SGu Zheng 55539a53e0cSJaegeuk Kim struct f2fs_sm_info { 55639a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 55739a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 55839a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 55939a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 56039a53e0cSJaegeuk Kim 56139a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 56239a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 56339a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 56439a53e0cSJaegeuk Kim 56539a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 56639a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 56739a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 56839a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 56981eb8d6eSJaegeuk Kim 57081eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 57181eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 5727fd9e544SJaegeuk Kim 5737fd9e544SJaegeuk Kim /* for small discard management */ 5747fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 5757fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 5767fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 577216fbd64SJaegeuk Kim 578bba681cbSJaegeuk Kim /* for batched trimming */ 579bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 580bba681cbSJaegeuk Kim 581184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 582184a5cd2SChao Yu 583216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 584216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 585c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 5866b4afdd7SJaegeuk Kim 5876b4afdd7SJaegeuk Kim /* for flush command control */ 588a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 589a688b9d9SGu Zheng 59039a53e0cSJaegeuk Kim }; 59139a53e0cSJaegeuk Kim 59239a53e0cSJaegeuk Kim /* 59339a53e0cSJaegeuk Kim * For superblock 59439a53e0cSJaegeuk Kim */ 59539a53e0cSJaegeuk Kim /* 59639a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 59739a53e0cSJaegeuk Kim * 59839a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 59939a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 60039a53e0cSJaegeuk Kim */ 60139a53e0cSJaegeuk Kim enum count_type { 60239a53e0cSJaegeuk Kim F2FS_WRITEBACK, 60339a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 604c227f912SChao Yu F2FS_DIRTY_DATA, 60539a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 60639a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6078dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 60839a53e0cSJaegeuk Kim NR_COUNT_TYPE, 60939a53e0cSJaegeuk Kim }; 61039a53e0cSJaegeuk Kim 61139a53e0cSJaegeuk Kim /* 612e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 61339a53e0cSJaegeuk Kim * The available types are: 61439a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 61539a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 61639a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 61739a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 61839a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 61939a53e0cSJaegeuk Kim * with waiting the bio's completion 62039a53e0cSJaegeuk Kim * ... Only can be used with META. 62139a53e0cSJaegeuk Kim */ 6227d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 62339a53e0cSJaegeuk Kim enum page_type { 62439a53e0cSJaegeuk Kim DATA, 62539a53e0cSJaegeuk Kim NODE, 62639a53e0cSJaegeuk Kim META, 62739a53e0cSJaegeuk Kim NR_PAGE_TYPE, 62839a53e0cSJaegeuk Kim META_FLUSH, 6298ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 6308ce67cb0SJaegeuk Kim INMEM_DROP, 63128bc106bSChao Yu INMEM_REVOKE, 6328ce67cb0SJaegeuk Kim IPU, 6338ce67cb0SJaegeuk Kim OPU, 63439a53e0cSJaegeuk Kim }; 63539a53e0cSJaegeuk Kim 636458e6197SJaegeuk Kim struct f2fs_io_info { 63705ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 638458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 6397e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 6407a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 64128bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 64205ca3632SJaegeuk Kim struct page *page; /* page to be written */ 6434375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 644458e6197SJaegeuk Kim }; 645458e6197SJaegeuk Kim 64693dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 6471ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 648458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 6491ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 6501ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 651458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 652df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 6531ff7bd3bSJaegeuk Kim }; 6541ff7bd3bSJaegeuk Kim 655c227f912SChao Yu enum inode_type { 656c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 657c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 658c227f912SChao Yu NR_INODE_TYPE, 659c227f912SChao Yu }; 660c227f912SChao Yu 66167298804SChao Yu /* for inner inode cache management */ 66267298804SChao Yu struct inode_management { 66367298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 66467298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 66567298804SChao Yu struct list_head ino_list; /* inode list head */ 66667298804SChao Yu unsigned long ino_num; /* number of entries */ 66767298804SChao Yu }; 66867298804SChao Yu 669caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 670caf0047eSChao Yu enum { 671caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 672caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 673caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 674caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 675df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 676caf0047eSChao Yu }; 677caf0047eSChao Yu 6786beceb54SJaegeuk Kim enum { 6796beceb54SJaegeuk Kim CP_TIME, 680d0239e1bSJaegeuk Kim REQ_TIME, 6816beceb54SJaegeuk Kim MAX_TIME, 6826beceb54SJaegeuk Kim }; 6836beceb54SJaegeuk Kim 68439a53e0cSJaegeuk Kim struct f2fs_sb_info { 68539a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 6865e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 68739a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 688e8240f65SChao Yu int valid_super_block; /* valid super block no */ 689caf0047eSChao Yu int s_flag; /* flags for sbi */ 69039a53e0cSJaegeuk Kim 69139a53e0cSJaegeuk Kim /* for node-related operations */ 69239a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 69339a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 69439a53e0cSJaegeuk Kim 69539a53e0cSJaegeuk Kim /* for segment-related operations */ 69639a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 6971ff7bd3bSJaegeuk Kim 6981ff7bd3bSJaegeuk Kim /* for bio operations */ 699924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 7001ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 70139a53e0cSJaegeuk Kim 70239a53e0cSJaegeuk Kim /* for checkpoint */ 70339a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 70439a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 70539936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 706e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 707b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 7085463e7c1SJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 709fb51b5efSChangman Lee wait_queue_head_t cp_wait; 7106beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 7116beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 71239a53e0cSJaegeuk Kim 71367298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 7146451e041SJaegeuk Kim 7156451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 7160d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 71739a53e0cSJaegeuk Kim 718c227f912SChao Yu /* for inode management */ 719c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 720c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 72139a53e0cSJaegeuk Kim 72213054c54SChao Yu /* for extent tree cache */ 72313054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 72413054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 72513054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 72613054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 7277441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 728137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 72974fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 73013054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 73113054c54SChao Yu 73239a53e0cSJaegeuk Kim /* basic filesystem units */ 73339a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 73439a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 73539a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 73639a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 73739a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 73839a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 73939a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 74039a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 74139a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 74239a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 74339a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 74439a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 74539a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 74639a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 747e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 74839a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 749ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 75039a53e0cSJaegeuk Kim 75139a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 75239a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 75339a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 754a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 75539a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 75639a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 75739a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 75839a53e0cSJaegeuk Kim 75939a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 76039a53e0cSJaegeuk Kim 76139a53e0cSJaegeuk Kim /* for cleaning operations */ 76239a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 76339a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 7645ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 76539a53e0cSJaegeuk Kim 766b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 767b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 768b1c57c1cSJaegeuk Kim 76939a53e0cSJaegeuk Kim /* 77039a53e0cSJaegeuk Kim * for stat information. 77139a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 77239a53e0cSJaegeuk Kim */ 77335b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 77439a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 77539a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 77639a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 777b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 7785b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 7795b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 7805b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 7815b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 782d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 78303e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 78403e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 78539a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 78633fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 78735b09d82SNamjae Jeon #endif 78835b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 78939a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 790b59d0baeSNamjae Jeon 791b59d0baeSNamjae Jeon /* For sysfs suppport */ 792b59d0baeSNamjae Jeon struct kobject s_kobj; 793b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 7942658e50dSJaegeuk Kim 7952658e50dSJaegeuk Kim /* For shrinker support */ 7962658e50dSJaegeuk Kim struct list_head s_list; 7972658e50dSJaegeuk Kim struct mutex umount_mutex; 7982658e50dSJaegeuk Kim unsigned int shrinker_run_no; 7998f1dbbbbSShuoran Liu 8008f1dbbbbSShuoran Liu /* For write statistics */ 8018f1dbbbbSShuoran Liu u64 sectors_written_start; 8028f1dbbbbSShuoran Liu u64 kbytes_written; 80343b6573bSKeith Mok 80443b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 80543b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 80639a53e0cSJaegeuk Kim }; 80739a53e0cSJaegeuk Kim 8088f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 8098f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 8108f1dbbbbSShuoran Liu */ 8118f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 8128f1dbbbbSShuoran Liu (((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) - \ 8138f1dbbbbSShuoran Liu s->sectors_written_start) >> 1) 8148f1dbbbbSShuoran Liu 8156beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 8166beceb54SJaegeuk Kim { 8176beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 8186beceb54SJaegeuk Kim } 8196beceb54SJaegeuk Kim 8206beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 8216beceb54SJaegeuk Kim { 8226beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 8236beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 8246beceb54SJaegeuk Kim 8256beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 8266beceb54SJaegeuk Kim } 8276beceb54SJaegeuk Kim 828d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 829d0239e1bSJaegeuk Kim { 830d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 831d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 832d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 833d0239e1bSJaegeuk Kim 834d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 835d0239e1bSJaegeuk Kim return 0; 836d0239e1bSJaegeuk Kim 837d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 838d0239e1bSJaegeuk Kim } 839d0239e1bSJaegeuk Kim 84039a53e0cSJaegeuk Kim /* 84139a53e0cSJaegeuk Kim * Inline functions 84239a53e0cSJaegeuk Kim */ 84343b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 84443b6573bSKeith Mok unsigned int length) 84543b6573bSKeith Mok { 84643b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 84743b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 84843b6573bSKeith Mok int err; 84943b6573bSKeith Mok 85043b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 85143b6573bSKeith Mok shash->flags = 0; 85243b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 85343b6573bSKeith Mok 85443b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 85543b6573bSKeith Mok BUG_ON(err); 85643b6573bSKeith Mok 85743b6573bSKeith Mok return *ctx; 85843b6573bSKeith Mok } 85943b6573bSKeith Mok 86043b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 86143b6573bSKeith Mok void *buf, size_t buf_size) 86243b6573bSKeith Mok { 86343b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 86443b6573bSKeith Mok } 86543b6573bSKeith Mok 86639a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 86739a53e0cSJaegeuk Kim { 86839a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 86939a53e0cSJaegeuk Kim } 87039a53e0cSJaegeuk Kim 87139a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 87239a53e0cSJaegeuk Kim { 87339a53e0cSJaegeuk Kim return sb->s_fs_info; 87439a53e0cSJaegeuk Kim } 87539a53e0cSJaegeuk Kim 8764081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 8774081363fSJaegeuk Kim { 8784081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 8794081363fSJaegeuk Kim } 8804081363fSJaegeuk Kim 8814081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 8824081363fSJaegeuk Kim { 8834081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 8844081363fSJaegeuk Kim } 8854081363fSJaegeuk Kim 8864081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 8874081363fSJaegeuk Kim { 8884081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 8894081363fSJaegeuk Kim } 8904081363fSJaegeuk Kim 89139a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 89239a53e0cSJaegeuk Kim { 89339a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 89439a53e0cSJaegeuk Kim } 89539a53e0cSJaegeuk Kim 89639a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 89739a53e0cSJaegeuk Kim { 89839a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 89939a53e0cSJaegeuk Kim } 90039a53e0cSJaegeuk Kim 90145590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 90245590710SGu Zheng { 90345590710SGu Zheng return (struct f2fs_node *)page_address(page); 90445590710SGu Zheng } 90545590710SGu Zheng 90658bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 90758bfaf44SJaegeuk Kim { 90858bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 90958bfaf44SJaegeuk Kim } 91058bfaf44SJaegeuk Kim 91139a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 91239a53e0cSJaegeuk Kim { 91339a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 91439a53e0cSJaegeuk Kim } 91539a53e0cSJaegeuk Kim 91639a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 91739a53e0cSJaegeuk Kim { 91839a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 91939a53e0cSJaegeuk Kim } 92039a53e0cSJaegeuk Kim 92139a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 92239a53e0cSJaegeuk Kim { 92339a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 92439a53e0cSJaegeuk Kim } 92539a53e0cSJaegeuk Kim 92639a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 92739a53e0cSJaegeuk Kim { 92839a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 92939a53e0cSJaegeuk Kim } 93039a53e0cSJaegeuk Kim 93139a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 93239a53e0cSJaegeuk Kim { 93339a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 93439a53e0cSJaegeuk Kim } 93539a53e0cSJaegeuk Kim 9369df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 9379df27d98SGu Zheng { 9389df27d98SGu Zheng return sbi->meta_inode->i_mapping; 9399df27d98SGu Zheng } 9409df27d98SGu Zheng 9414ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 9424ef51a8fSJaegeuk Kim { 9434ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 9444ef51a8fSJaegeuk Kim } 9454ef51a8fSJaegeuk Kim 946caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 94739a53e0cSJaegeuk Kim { 948caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 94939a53e0cSJaegeuk Kim } 95039a53e0cSJaegeuk Kim 951caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 95239a53e0cSJaegeuk Kim { 953caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 954caf0047eSChao Yu } 955caf0047eSChao Yu 956caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 957caf0047eSChao Yu { 958caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 95939a53e0cSJaegeuk Kim } 96039a53e0cSJaegeuk Kim 961d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 962d71b5564SJaegeuk Kim { 963d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 964d71b5564SJaegeuk Kim } 965d71b5564SJaegeuk Kim 96625ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 96725ca923bSJaegeuk Kim { 96825ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 96925ca923bSJaegeuk Kim return ckpt_flags & f; 97025ca923bSJaegeuk Kim } 97125ca923bSJaegeuk Kim 97225ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 97325ca923bSJaegeuk Kim { 97425ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 97525ca923bSJaegeuk Kim ckpt_flags |= f; 97625ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 97725ca923bSJaegeuk Kim } 97825ca923bSJaegeuk Kim 97925ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 98025ca923bSJaegeuk Kim { 98125ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 98225ca923bSJaegeuk Kim ckpt_flags &= (~f); 98325ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 98425ca923bSJaegeuk Kim } 98525ca923bSJaegeuk Kim 986e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 98739a53e0cSJaegeuk Kim { 988e479556bSGu Zheng down_read(&sbi->cp_rwsem); 98939a53e0cSJaegeuk Kim } 99039a53e0cSJaegeuk Kim 991e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 99239a53e0cSJaegeuk Kim { 993e479556bSGu Zheng up_read(&sbi->cp_rwsem); 99439936837SJaegeuk Kim } 99539936837SJaegeuk Kim 996e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 99739936837SJaegeuk Kim { 99859692b7cSYang Shi down_write(&sbi->cp_rwsem); 99939936837SJaegeuk Kim } 100039936837SJaegeuk Kim 1001e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 100239936837SJaegeuk Kim { 1003e479556bSGu Zheng up_write(&sbi->cp_rwsem); 100439a53e0cSJaegeuk Kim } 100539a53e0cSJaegeuk Kim 1006119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1007119ee914SJaegeuk Kim { 1008119ee914SJaegeuk Kim int reason = CP_SYNC; 1009119ee914SJaegeuk Kim 1010119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1011119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1012119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1013119ee914SJaegeuk Kim reason = CP_UMOUNT; 1014119ee914SJaegeuk Kim return reason; 1015119ee914SJaegeuk Kim } 1016119ee914SJaegeuk Kim 1017119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1018119ee914SJaegeuk Kim { 1019119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 1020119ee914SJaegeuk Kim } 1021119ee914SJaegeuk Kim 1022119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1023119ee914SJaegeuk Kim { 1024119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 1025119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 1026119ee914SJaegeuk Kim } 1027119ee914SJaegeuk Kim 102839a53e0cSJaegeuk Kim /* 102939a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 103039a53e0cSJaegeuk Kim */ 1031064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 103239a53e0cSJaegeuk Kim { 1033d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1034d6b7d4b3SChao Yu return -EINVAL; 1035cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1036064e0823SNamjae Jeon return -EINVAL; 1037064e0823SNamjae Jeon return 0; 103839a53e0cSJaegeuk Kim } 103939a53e0cSJaegeuk Kim 104039a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 104139a53e0cSJaegeuk Kim 104239a53e0cSJaegeuk Kim /* 104339a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 104439a53e0cSJaegeuk Kim */ 104539a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 104639a53e0cSJaegeuk Kim { 104739a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 10486c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 104939a53e0cSJaegeuk Kim else 10506c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 105139a53e0cSJaegeuk Kim } 105239a53e0cSJaegeuk Kim 10534bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 10544bc8e9bcSChao Yu { 10554bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 10564bc8e9bcSChao Yu } 10574bc8e9bcSChao Yu 105839a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 105939a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 106039a53e0cSJaegeuk Kim { 106139a53e0cSJaegeuk Kim block_t valid_block_count; 106239a53e0cSJaegeuk Kim 106339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 106439a53e0cSJaegeuk Kim valid_block_count = 106539a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 1066cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 106739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 106839a53e0cSJaegeuk Kim return false; 106939a53e0cSJaegeuk Kim } 107039a53e0cSJaegeuk Kim inode->i_blocks += count; 107139a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 107239a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 107339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 107439a53e0cSJaegeuk Kim return true; 107539a53e0cSJaegeuk Kim } 107639a53e0cSJaegeuk Kim 1077da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 107839a53e0cSJaegeuk Kim struct inode *inode, 107939a53e0cSJaegeuk Kim blkcnt_t count) 108039a53e0cSJaegeuk Kim { 108139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 10829850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 10839850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 108439a53e0cSJaegeuk Kim inode->i_blocks -= count; 108539a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 108639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 108739a53e0cSJaegeuk Kim } 108839a53e0cSJaegeuk Kim 108939a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 109039a53e0cSJaegeuk Kim { 109139a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 1092caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 109339a53e0cSJaegeuk Kim } 109439a53e0cSJaegeuk Kim 1095a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 109639a53e0cSJaegeuk Kim { 1097a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1098c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1099c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 110039a53e0cSJaegeuk Kim } 110139a53e0cSJaegeuk Kim 110239a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 110339a53e0cSJaegeuk Kim { 110439a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 110539a53e0cSJaegeuk Kim } 110639a53e0cSJaegeuk Kim 1107a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 110839a53e0cSJaegeuk Kim { 11095ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 11105ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 11111fe54f9dSJaegeuk Kim return; 11121fe54f9dSJaegeuk Kim 1113a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1114c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1115c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 111639a53e0cSJaegeuk Kim } 111739a53e0cSJaegeuk Kim 111839a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 111939a53e0cSJaegeuk Kim { 112039a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 112139a53e0cSJaegeuk Kim } 112239a53e0cSJaegeuk Kim 1123a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1124f8b2c1f9SJaegeuk Kim { 1125a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1126f8b2c1f9SJaegeuk Kim } 1127f8b2c1f9SJaegeuk Kim 11285ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 11295ac206cfSNamjae Jeon { 11303519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 11315ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 11325ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 11335ac206cfSNamjae Jeon } 11345ac206cfSNamjae Jeon 113539a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 113639a53e0cSJaegeuk Kim { 11378b8343faSJaegeuk Kim return sbi->total_valid_block_count; 113839a53e0cSJaegeuk Kim } 113939a53e0cSJaegeuk Kim 114039a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 114139a53e0cSJaegeuk Kim { 114239a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 114339a53e0cSJaegeuk Kim 114439a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 114539a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 114639a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 114739a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 114839a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 114939a53e0cSJaegeuk Kim 115039a53e0cSJaegeuk Kim return 0; 115139a53e0cSJaegeuk Kim } 115239a53e0cSJaegeuk Kim 115355141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 115455141486SWanpeng Li { 115555141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 115655141486SWanpeng Li } 115755141486SWanpeng Li 115839a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 115939a53e0cSJaegeuk Kim { 116039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 11611dbe4152SChangman Lee int offset; 11621dbe4152SChangman Lee 116355141486SWanpeng Li if (__cp_payload(sbi) > 0) { 11641dbe4152SChangman Lee if (flag == NAT_BITMAP) 11651dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 11661dbe4152SChangman Lee else 116765b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 11681dbe4152SChangman Lee } else { 11691dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 117025ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 117139a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 117239a53e0cSJaegeuk Kim } 11731dbe4152SChangman Lee } 117439a53e0cSJaegeuk Kim 117539a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 117639a53e0cSJaegeuk Kim { 117739a53e0cSJaegeuk Kim block_t start_addr; 117839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1179d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 118039a53e0cSJaegeuk Kim 118125ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 118239a53e0cSJaegeuk Kim 118339a53e0cSJaegeuk Kim /* 118439a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1185e1c42045Sarter97 * and even segment must be at cp segment 1 118639a53e0cSJaegeuk Kim */ 118739a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 118839a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 118939a53e0cSJaegeuk Kim 119039a53e0cSJaegeuk Kim return start_addr; 119139a53e0cSJaegeuk Kim } 119239a53e0cSJaegeuk Kim 119339a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 119439a53e0cSJaegeuk Kim { 119539a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 119639a53e0cSJaegeuk Kim } 119739a53e0cSJaegeuk Kim 119839a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1199ef86d709SGu Zheng struct inode *inode) 120039a53e0cSJaegeuk Kim { 120139a53e0cSJaegeuk Kim block_t valid_block_count; 120239a53e0cSJaegeuk Kim unsigned int valid_node_count; 120339a53e0cSJaegeuk Kim 120439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 120539a53e0cSJaegeuk Kim 1206ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1207cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 120839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 120939a53e0cSJaegeuk Kim return false; 121039a53e0cSJaegeuk Kim } 121139a53e0cSJaegeuk Kim 1212ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1213cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 121439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 121539a53e0cSJaegeuk Kim return false; 121639a53e0cSJaegeuk Kim } 121739a53e0cSJaegeuk Kim 121839a53e0cSJaegeuk Kim if (inode) 1219ef86d709SGu Zheng inode->i_blocks++; 1220ef86d709SGu Zheng 1221ef86d709SGu Zheng sbi->alloc_valid_block_count++; 1222ef86d709SGu Zheng sbi->total_valid_node_count++; 1223ef86d709SGu Zheng sbi->total_valid_block_count++; 122439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 122539a53e0cSJaegeuk Kim 122639a53e0cSJaegeuk Kim return true; 122739a53e0cSJaegeuk Kim } 122839a53e0cSJaegeuk Kim 122939a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1230ef86d709SGu Zheng struct inode *inode) 123139a53e0cSJaegeuk Kim { 123239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 123339a53e0cSJaegeuk Kim 12349850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 12359850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 12369850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 123739a53e0cSJaegeuk Kim 1238ef86d709SGu Zheng inode->i_blocks--; 1239ef86d709SGu Zheng sbi->total_valid_node_count--; 1240ef86d709SGu Zheng sbi->total_valid_block_count--; 124139a53e0cSJaegeuk Kim 124239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 124339a53e0cSJaegeuk Kim } 124439a53e0cSJaegeuk Kim 124539a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 124639a53e0cSJaegeuk Kim { 12478b8343faSJaegeuk Kim return sbi->total_valid_node_count; 124839a53e0cSJaegeuk Kim } 124939a53e0cSJaegeuk Kim 125039a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 125139a53e0cSJaegeuk Kim { 125239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12539850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 125439a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 125539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 125639a53e0cSJaegeuk Kim } 125739a53e0cSJaegeuk Kim 12580e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 125939a53e0cSJaegeuk Kim { 126039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12619850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 126239a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 126339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 126439a53e0cSJaegeuk Kim } 126539a53e0cSJaegeuk Kim 126639a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 126739a53e0cSJaegeuk Kim { 12688b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 126939a53e0cSJaegeuk Kim } 127039a53e0cSJaegeuk Kim 1271a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1272a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1273a56c7c6fSJaegeuk Kim { 1274a56c7c6fSJaegeuk Kim if (!for_write) 1275a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1276a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1277a56c7c6fSJaegeuk Kim } 1278a56c7c6fSJaegeuk Kim 12796e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 12806e2c64adSJaegeuk Kim { 12816e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 12826e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 12836e2c64adSJaegeuk Kim 12846e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 12856e2c64adSJaegeuk Kim kunmap(dst); 12866e2c64adSJaegeuk Kim kunmap(src); 12876e2c64adSJaegeuk Kim } 12886e2c64adSJaegeuk Kim 128939a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 129039a53e0cSJaegeuk Kim { 1291031fa8ccSJaegeuk Kim if (!page) 129239a53e0cSJaegeuk Kim return; 129339a53e0cSJaegeuk Kim 129439a53e0cSJaegeuk Kim if (unlock) { 12959850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 129639a53e0cSJaegeuk Kim unlock_page(page); 129739a53e0cSJaegeuk Kim } 129809cbfeafSKirill A. Shutemov put_page(page); 129939a53e0cSJaegeuk Kim } 130039a53e0cSJaegeuk Kim 130139a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 130239a53e0cSJaegeuk Kim { 130339a53e0cSJaegeuk Kim if (dn->node_page) 130439a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 130539a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 130639a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 130739a53e0cSJaegeuk Kim dn->node_page = NULL; 130839a53e0cSJaegeuk Kim dn->inode_page = NULL; 130939a53e0cSJaegeuk Kim } 131039a53e0cSJaegeuk Kim 131139a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1312e8512d2eSGu Zheng size_t size) 131339a53e0cSJaegeuk Kim { 1314e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 131539a53e0cSJaegeuk Kim } 131639a53e0cSJaegeuk Kim 13177bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 13187bd59381SGu Zheng gfp_t flags) 13197bd59381SGu Zheng { 13207bd59381SGu Zheng void *entry; 13217bd59381SGu Zheng 132280c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 132380c54505SJaegeuk Kim if (!entry) 132480c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 13257bd59381SGu Zheng return entry; 13267bd59381SGu Zheng } 13277bd59381SGu Zheng 1328740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1329740432f8SJaegeuk Kim { 1330740432f8SJaegeuk Kim struct bio *bio; 1331740432f8SJaegeuk Kim 1332740432f8SJaegeuk Kim /* No failure on bio allocation */ 1333740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 133480c54505SJaegeuk Kim if (!bio) 133580c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1336740432f8SJaegeuk Kim return bio; 1337740432f8SJaegeuk Kim } 1338740432f8SJaegeuk Kim 13399be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 13409be32d72SJaegeuk Kim unsigned long index, void *item) 13419be32d72SJaegeuk Kim { 13429be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 13439be32d72SJaegeuk Kim cond_resched(); 13449be32d72SJaegeuk Kim } 13459be32d72SJaegeuk Kim 134639a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 134739a53e0cSJaegeuk Kim 134839a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 134939a53e0cSJaegeuk Kim { 135045590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 135139a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 135239a53e0cSJaegeuk Kim } 135339a53e0cSJaegeuk Kim 135439a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 135539a53e0cSJaegeuk Kim { 135639a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 135739a53e0cSJaegeuk Kim } 135839a53e0cSJaegeuk Kim 135939a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 136039a53e0cSJaegeuk Kim unsigned int offset) 136139a53e0cSJaegeuk Kim { 136239a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 136339a53e0cSJaegeuk Kim __le32 *addr_array; 136445590710SGu Zheng raw_node = F2FS_NODE(node_page); 136539a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 136639a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 136739a53e0cSJaegeuk Kim } 136839a53e0cSJaegeuk Kim 136939a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 137039a53e0cSJaegeuk Kim { 137139a53e0cSJaegeuk Kim int mask; 137239a53e0cSJaegeuk Kim 137339a53e0cSJaegeuk Kim addr += (nr >> 3); 137439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 137539a53e0cSJaegeuk Kim return mask & *addr; 137639a53e0cSJaegeuk Kim } 137739a53e0cSJaegeuk Kim 1378a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1379a66cdd98SJaegeuk Kim { 1380a66cdd98SJaegeuk Kim int mask; 1381a66cdd98SJaegeuk Kim 1382a66cdd98SJaegeuk Kim addr += (nr >> 3); 1383a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1384a66cdd98SJaegeuk Kim *addr |= mask; 1385a66cdd98SJaegeuk Kim } 1386a66cdd98SJaegeuk Kim 1387a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1388a66cdd98SJaegeuk Kim { 1389a66cdd98SJaegeuk Kim int mask; 1390a66cdd98SJaegeuk Kim 1391a66cdd98SJaegeuk Kim addr += (nr >> 3); 1392a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1393a66cdd98SJaegeuk Kim *addr &= ~mask; 1394a66cdd98SJaegeuk Kim } 1395a66cdd98SJaegeuk Kim 139652aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 139739a53e0cSJaegeuk Kim { 139839a53e0cSJaegeuk Kim int mask; 139939a53e0cSJaegeuk Kim int ret; 140039a53e0cSJaegeuk Kim 140139a53e0cSJaegeuk Kim addr += (nr >> 3); 140239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 140339a53e0cSJaegeuk Kim ret = mask & *addr; 140439a53e0cSJaegeuk Kim *addr |= mask; 140539a53e0cSJaegeuk Kim return ret; 140639a53e0cSJaegeuk Kim } 140739a53e0cSJaegeuk Kim 140852aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 140939a53e0cSJaegeuk Kim { 141039a53e0cSJaegeuk Kim int mask; 141139a53e0cSJaegeuk Kim int ret; 141239a53e0cSJaegeuk Kim 141339a53e0cSJaegeuk Kim addr += (nr >> 3); 141439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 141539a53e0cSJaegeuk Kim ret = mask & *addr; 141639a53e0cSJaegeuk Kim *addr &= ~mask; 141739a53e0cSJaegeuk Kim return ret; 141839a53e0cSJaegeuk Kim } 141939a53e0cSJaegeuk Kim 1420c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1421c6ac4c0eSGu Zheng { 1422c6ac4c0eSGu Zheng int mask; 1423c6ac4c0eSGu Zheng 1424c6ac4c0eSGu Zheng addr += (nr >> 3); 1425c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1426c6ac4c0eSGu Zheng *addr ^= mask; 1427c6ac4c0eSGu Zheng } 1428c6ac4c0eSGu Zheng 142939a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 143039a53e0cSJaegeuk Kim enum { 143139a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1432b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1433ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 143439a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 143539a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 143639a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1437c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1438699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 143974d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1440c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1441444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 14421001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 144334d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1444fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1445fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 144688b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 144788b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 144802a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 14493c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 14501e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1451b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1452510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1453d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1454c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 145539a53e0cSJaegeuk Kim }; 145639a53e0cSJaegeuk Kim 145739a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 145839a53e0cSJaegeuk Kim { 145961e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 146039a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 146139a53e0cSJaegeuk Kim } 146239a53e0cSJaegeuk Kim 146339a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 146439a53e0cSJaegeuk Kim { 146539a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 146639a53e0cSJaegeuk Kim } 146739a53e0cSJaegeuk Kim 146839a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 146939a53e0cSJaegeuk Kim { 147061e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 147139a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 147239a53e0cSJaegeuk Kim } 147339a53e0cSJaegeuk Kim 147439a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 147539a53e0cSJaegeuk Kim { 147639a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 147739a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 147839a53e0cSJaegeuk Kim } 147939a53e0cSJaegeuk Kim 1480444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1481444c580fSJaegeuk Kim struct f2fs_inode *ri) 1482444c580fSJaegeuk Kim { 1483444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1484444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 14851001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 14861001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 148734d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 148834d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1489b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1490b3d208f9SJaegeuk Kim set_inode_flag(fi, FI_DATA_EXIST); 1491510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1492510022a8SJaegeuk Kim set_inode_flag(fi, FI_INLINE_DOTS); 1493444c580fSJaegeuk Kim } 1494444c580fSJaegeuk Kim 1495444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1496444c580fSJaegeuk Kim struct f2fs_inode *ri) 1497444c580fSJaegeuk Kim { 1498444c580fSJaegeuk Kim ri->i_inline = 0; 1499444c580fSJaegeuk Kim 1500444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1501444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 15021001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 15031001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 150434d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 150534d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1506b3d208f9SJaegeuk Kim if (is_inode_flag_set(fi, FI_DATA_EXIST)) 1507b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1508510022a8SJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_DOTS)) 1509510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1510444c580fSJaegeuk Kim } 1511444c580fSJaegeuk Kim 1512987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1513987c7c31SChao Yu { 1514987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1515987c7c31SChao Yu } 1516987c7c31SChao Yu 151781ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1518de93653fSJaegeuk Kim { 151981ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1520de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1521de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1522de93653fSJaegeuk Kim } 1523de93653fSJaegeuk Kim 152465985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 152565985d93SJaegeuk Kim { 1526695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 152765985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 152865985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 152965985d93SJaegeuk Kim } 153065985d93SJaegeuk Kim 153165985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 153265985d93SJaegeuk Kim { 1533987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 153465985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 153565985d93SJaegeuk Kim else 153665985d93SJaegeuk Kim return 0; 153765985d93SJaegeuk Kim } 153865985d93SJaegeuk Kim 15390dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 15400dbdc2aeSJaegeuk Kim { 15410dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 15420dbdc2aeSJaegeuk Kim } 15430dbdc2aeSJaegeuk Kim 1544b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1545b3d208f9SJaegeuk Kim { 1546b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 1547b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1548b3d208f9SJaegeuk Kim } 1549b3d208f9SJaegeuk Kim 1550b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1551b3d208f9SJaegeuk Kim { 1552b3d208f9SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST); 1553b3d208f9SJaegeuk Kim } 1554b3d208f9SJaegeuk Kim 1555510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1556510022a8SJaegeuk Kim { 1557510022a8SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS); 1558510022a8SJaegeuk Kim } 1559510022a8SJaegeuk Kim 156088b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 156188b88a66SJaegeuk Kim { 156288b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 156388b88a66SJaegeuk Kim } 156488b88a66SJaegeuk Kim 156502a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 156602a1335fSJaegeuk Kim { 156702a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 156802a1335fSJaegeuk Kim } 156902a1335fSJaegeuk Kim 15703c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 15713c6c2bebSJaegeuk Kim { 15723c6c2bebSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); 15733c6c2bebSJaegeuk Kim } 15743c6c2bebSJaegeuk Kim 15751e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 15761e84371fSJaegeuk Kim { 15771e84371fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE); 15781e84371fSJaegeuk Kim } 15791e84371fSJaegeuk Kim 15801001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 15811001b347SHuajun Li { 1582695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 15831001b347SHuajun Li return (void *)&(ri->i_addr[1]); 15841001b347SHuajun Li } 15851001b347SHuajun Li 158634d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 158734d67debSChao Yu { 158834d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 158934d67debSChao Yu } 159034d67debSChao Yu 15919486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 15929486ba44SJaegeuk Kim { 15939486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 15949486ba44SJaegeuk Kim kunmap(page); 15959486ba44SJaegeuk Kim } 15969486ba44SJaegeuk Kim 1597b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1598b5492af7SJaegeuk Kim { 1599b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1600b5492af7SJaegeuk Kim } 1601b5492af7SJaegeuk Kim 1602b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1603b5492af7SJaegeuk Kim { 1604b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1605b5492af7SJaegeuk Kim } 1606b5492af7SJaegeuk Kim 1607b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1608b5492af7SJaegeuk Kim { 1609b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1610b5492af7SJaegeuk Kim } 1611b5492af7SJaegeuk Kim 161277888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 161377888c1eSJaegeuk Kim { 161477888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 161577888c1eSJaegeuk Kim } 161677888c1eSJaegeuk Kim 16171e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 16181e968fdfSJaegeuk Kim { 16191e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 16201e968fdfSJaegeuk Kim } 16211e968fdfSJaegeuk Kim 1622744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1623744602cfSJaegeuk Kim { 1624744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1625744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1626744602cfSJaegeuk Kim } 1627744602cfSJaegeuk Kim 1628eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1629eaa693f4SJaegeuk Kim { 1630eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1631eaa693f4SJaegeuk Kim return true; 1632eaa693f4SJaegeuk Kim 1633eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1634eaa693f4SJaegeuk Kim return true; 1635eaa693f4SJaegeuk Kim 1636eaa693f4SJaegeuk Kim return false; 1637eaa693f4SJaegeuk Kim } 1638eaa693f4SJaegeuk Kim 16393e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 16403e72f721SJaegeuk Kim { 16413e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 16423e72f721SJaegeuk Kim is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT)) 16433e72f721SJaegeuk Kim return false; 16443e72f721SJaegeuk Kim 1645886f56f9SAl Viro return S_ISREG(inode->i_mode); 16463e72f721SJaegeuk Kim } 16473e72f721SJaegeuk Kim 16480414b004SJaegeuk Kim static inline void *f2fs_kmalloc(size_t size, gfp_t flags) 16490414b004SJaegeuk Kim { 16500414b004SJaegeuk Kim return kmalloc(size, flags); 16510414b004SJaegeuk Kim } 16520414b004SJaegeuk Kim 165339307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 165439307a8eSJaegeuk Kim { 165539307a8eSJaegeuk Kim void *ret; 165639307a8eSJaegeuk Kim 165739307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 165839307a8eSJaegeuk Kim if (!ret) 165939307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 166039307a8eSJaegeuk Kim return ret; 166139307a8eSJaegeuk Kim } 166239307a8eSJaegeuk Kim 166339307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 166439307a8eSJaegeuk Kim { 166539307a8eSJaegeuk Kim void *ret; 166639307a8eSJaegeuk Kim 166739307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 166839307a8eSJaegeuk Kim if (!ret) 166939307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 167039307a8eSJaegeuk Kim return ret; 167139307a8eSJaegeuk Kim } 167239307a8eSJaegeuk Kim 1673a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1674a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1675a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1676a6dda0e6SChristoph Hellwig 1677267378d4SChao Yu /* get offset of first page in next direct node */ 167881ca7350SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, inode) \ 167981ca7350SChao Yu ((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) : \ 168081ca7350SChao Yu (pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) / \ 168181ca7350SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode)) 1682267378d4SChao Yu 168339a53e0cSJaegeuk Kim /* 168439a53e0cSJaegeuk Kim * file.c 168539a53e0cSJaegeuk Kim */ 168639a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 168739a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1688764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 1689b0154891SChao Yu int f2fs_truncate(struct inode *, bool); 16902d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 169139a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 169239a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1693b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 169439a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1695e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 169639a53e0cSJaegeuk Kim 169739a53e0cSJaegeuk Kim /* 169839a53e0cSJaegeuk Kim * inode.c 169939a53e0cSJaegeuk Kim */ 170039a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 170139a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 17024660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 170312719ae1SJaegeuk Kim int update_inode(struct inode *, struct page *); 170412719ae1SJaegeuk Kim int update_inode_page(struct inode *); 170539a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 170639a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 170744c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 170839a53e0cSJaegeuk Kim 170939a53e0cSJaegeuk Kim /* 171039a53e0cSJaegeuk Kim * namei.c 171139a53e0cSJaegeuk Kim */ 171239a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 171339a53e0cSJaegeuk Kim 171439a53e0cSJaegeuk Kim /* 171539a53e0cSJaegeuk Kim * dir.c 171639a53e0cSJaegeuk Kim */ 1717dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1718510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 1719675f10bdSChao Yu unsigned char get_de_type(struct f2fs_dir_entry *); 17200b81d077SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *, 17216e22c691SJaegeuk Kim f2fs_hash_t, int *, struct f2fs_dentry_ptr *); 17227b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 17230b81d077SJaegeuk Kim unsigned int, struct fscrypt_str *); 1724062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1725062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1726dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1727bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1728dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1729a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1730dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 173139a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 173239a53e0cSJaegeuk Kim struct page **); 173339a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 173439a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 173539a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 173639a53e0cSJaegeuk Kim struct page *, struct inode *); 1737e7d55452SJaegeuk Kim int update_dent_inode(struct inode *, struct inode *, const struct qstr *); 1738510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 17393b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1740675f10bdSChao Yu int f2fs_add_regular_entry(struct inode *, const struct qstr *, 1741675f10bdSChao Yu struct inode *, nid_t, umode_t); 1742510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1743510022a8SJaegeuk Kim umode_t); 1744dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1745dbeacf02SChao Yu struct inode *); 1746b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 174739a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 174839a53e0cSJaegeuk Kim 1749b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1750b7f7a5e0SAl Viro { 17512b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1752510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1753b7f7a5e0SAl Viro } 1754b7f7a5e0SAl Viro 175539a53e0cSJaegeuk Kim /* 175639a53e0cSJaegeuk Kim * super.c 175739a53e0cSJaegeuk Kim */ 1758c5bda1c8SChao Yu int f2fs_commit_super(struct f2fs_sb_info *, bool); 175939a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1760a07ef784SNamjae Jeon extern __printf(3, 4) 1761a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 1762984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 176339a53e0cSJaegeuk Kim 176439a53e0cSJaegeuk Kim /* 176539a53e0cSJaegeuk Kim * hash.c 176639a53e0cSJaegeuk Kim */ 1767eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 176839a53e0cSJaegeuk Kim 176939a53e0cSJaegeuk Kim /* 177039a53e0cSJaegeuk Kim * node.c 177139a53e0cSJaegeuk Kim */ 177239a53e0cSJaegeuk Kim struct dnode_of_data; 177339a53e0cSJaegeuk Kim struct node_info; 177439a53e0cSJaegeuk Kim 17756fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 17762dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t); 177788bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 177888bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 177939a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 17803cf45747SChao Yu pgoff_t get_next_page_offset(struct dnode_of_data *, pgoff_t); 178139a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 178239a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 17834f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1784cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 178513ec7297SChao Yu int remove_inode_page(struct inode *); 1786a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 17878ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 178839a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 178939a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 179039a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 179139a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 1792da011cc0SChao Yu void move_node_page(struct page *, int); 1793608514deSJaegeuk Kim int fsync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *, 1794608514deSJaegeuk Kim bool); 179552681375SJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, struct writeback_control *); 179639a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 179739a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 179839a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 179931696580SChao Yu int try_to_free_nids(struct f2fs_sb_info *, int); 180070cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 18011c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 180239a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 180339a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 180439a53e0cSJaegeuk Kim struct f2fs_summary_block *); 180539a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 180639a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 180739a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 18086e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 180939a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 181039a53e0cSJaegeuk Kim 181139a53e0cSJaegeuk Kim /* 181239a53e0cSJaegeuk Kim * segment.c 181339a53e0cSJaegeuk Kim */ 181488b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 181529b96b54SChao Yu void drop_inmem_pages(struct inode *); 181629b96b54SChao Yu int commit_inmem_pages(struct inode *); 18172c4db1a6SJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *, bool); 18184660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 18196b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 18202163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 18212163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 182239a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 18236e2c64adSJaegeuk Kim bool is_checkpointed_data(struct f2fs_sb_info *, block_t); 18245e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 1825836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 18264b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1827e90c2d28SChao Yu bool discard_next_dnode(struct f2fs_sb_info *, block_t); 18283fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 182939a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 18304b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 183139a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1832381722d2SChao Yu void update_meta_page(struct f2fs_sb_info *, void *, block_t); 1833577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 183405ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 183505ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 183605ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 18374356e48eSChao Yu void __f2fs_replace_block(struct f2fs_sb_info *, struct f2fs_summary *, 18384356e48eSChao Yu block_t, block_t, bool, bool); 1839528e3459SChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *, 184028bc106bSChao Yu block_t, block_t, unsigned char, bool, bool); 1841bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1842bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 1843fec1d657SJaegeuk Kim void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool); 184408b39fbdSChao Yu void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t); 184539a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 184639a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 1847dfc08a12SChao Yu int lookup_journal_in_cursum(struct f2fs_journal *, int, unsigned int, int); 18484b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 184939a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 185039a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 18517fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 18527fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 185339a53e0cSJaegeuk Kim 185439a53e0cSJaegeuk Kim /* 185539a53e0cSJaegeuk Kim * checkpoint.c 185639a53e0cSJaegeuk Kim */ 185739a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 185839a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 18592b947003SChao Yu struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t); 1860f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 186126879fb1SChao Yu int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool); 1862635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 186339a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1864a49324f1SChao Yu void add_ino_entry(struct f2fs_sb_info *, nid_t, int type); 1865a49324f1SChao Yu void remove_ino_entry(struct f2fs_sb_info *, nid_t, int type); 1866a49324f1SChao Yu void release_ino_entry(struct f2fs_sb_info *); 1867fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1868cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1869cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 187039a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 187139a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 18728c14bfadSChao Yu int recover_orphan_inodes(struct f2fs_sb_info *); 187339a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1874a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 18755deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 1876c227f912SChao Yu void remove_dirty_inode(struct inode *); 18776d5a1495SChao Yu int sync_dirty_inodes(struct f2fs_sb_info *, enum inode_type); 1878c34f42e2SChao Yu int write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 18796451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 18806e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 188139a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 188239a53e0cSJaegeuk Kim 188339a53e0cSJaegeuk Kim /* 188439a53e0cSJaegeuk Kim * data.c 188539a53e0cSJaegeuk Kim */ 1886458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 18870c3a5797SChao Yu void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *, struct inode *, 18880c3a5797SChao Yu struct page *, nid_t, enum page_type, int); 1889406657ddSChao Yu void f2fs_flush_merged_bios(struct f2fs_sb_info *); 189005ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 189105ca3632SJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_io_info *); 1892216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 1893f28b3434SChao Yu void f2fs_update_data_blkaddr(struct dnode_of_data *, block_t); 189439a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1895759af1c9SFan Li int f2fs_get_block(struct dnode_of_data *, pgoff_t); 1896b439b103SJaegeuk Kim ssize_t f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *); 1897b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 1898a56c7c6fSJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int, bool); 189943f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t); 1900a56c7c6fSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t, bool); 190164aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 190205ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 1903d323d005SChao Yu int f2fs_map_blocks(struct inode *, struct f2fs_map_blocks *, int, int); 19049ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1905487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1906487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 190739a53e0cSJaegeuk Kim 190839a53e0cSJaegeuk Kim /* 190939a53e0cSJaegeuk Kim * gc.c 191039a53e0cSJaegeuk Kim */ 191139a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 191239a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 191381ca7350SChao Yu block_t start_bidx_of_node(unsigned int, struct inode *); 1914d530d4d8SChao Yu int f2fs_gc(struct f2fs_sb_info *, bool); 191539a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 191639a53e0cSJaegeuk Kim 191739a53e0cSJaegeuk Kim /* 191839a53e0cSJaegeuk Kim * recovery.c 191939a53e0cSJaegeuk Kim */ 19206781eabbSJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *, bool); 192139a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 192239a53e0cSJaegeuk Kim 192339a53e0cSJaegeuk Kim /* 192439a53e0cSJaegeuk Kim * debug.c 192539a53e0cSJaegeuk Kim */ 192639a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 192739a53e0cSJaegeuk Kim struct f2fs_stat_info { 192839a53e0cSJaegeuk Kim struct list_head stat_list; 192939a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 193039a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 193139a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 19325b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 19335b7ee374SChao Yu unsigned long long hit_total, total_ext; 1934c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 193533fbd510SChao Yu int ndirty_node, ndirty_meta; 193633fbd510SChao Yu int ndirty_dent, ndirty_dirs, ndirty_data, ndirty_files; 1937dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 193839a53e0cSJaegeuk Kim int total_count, utilization; 1939d5e8f6c9SChao Yu int bg_gc, inmem_pages, wb_pages; 1940d5e8f6c9SChao Yu int inline_xattr, inline_inode, inline_dir; 194139a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 194239a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 194339a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 194439a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 194539a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 194642190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 194739a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 1948e1235983SChangman Lee int bg_node_segs, bg_data_segs; 194939a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 1950e1235983SChangman Lee int bg_data_blks, bg_node_blks; 195139a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 195239a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 195339a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 195439a53e0cSJaegeuk Kim 195539a53e0cSJaegeuk Kim unsigned int segment_count[2]; 195639a53e0cSJaegeuk Kim unsigned int block_count[2]; 1957b9a2c252SChangman Lee unsigned int inplace_count; 19589edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 195939a53e0cSJaegeuk Kim }; 196039a53e0cSJaegeuk Kim 1961963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1962963d4f7dSGu Zheng { 1963963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1964963d4f7dSGu Zheng } 1965963d4f7dSGu Zheng 1966942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 196742190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 196839a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1969dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 197033fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 197133fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 19725b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 19735b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 19745b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 19755b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 1976d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 1977d5e8f6c9SChao Yu do { \ 1978d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1979d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 1980d5e8f6c9SChao Yu } while (0) 1981d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 1982d5e8f6c9SChao Yu do { \ 1983d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1984d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 1985d5e8f6c9SChao Yu } while (0) 19860dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 19870dbdc2aeSJaegeuk Kim do { \ 19880dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 198903e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 19900dbdc2aeSJaegeuk Kim } while (0) 19910dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 19920dbdc2aeSJaegeuk Kim do { \ 19930dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 199403e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 19950dbdc2aeSJaegeuk Kim } while (0) 19963289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 19973289c061SJaegeuk Kim do { \ 19983289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 199903e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 20003289c061SJaegeuk Kim } while (0) 20013289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 20023289c061SJaegeuk Kim do { \ 20033289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 200403e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 20053289c061SJaegeuk Kim } while (0) 2006dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2007dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2008dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2009dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2010b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2011b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 2012e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 201339a53e0cSJaegeuk Kim do { \ 2014963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 201539a53e0cSJaegeuk Kim (si)->tot_segs++; \ 2016e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 201739a53e0cSJaegeuk Kim si->data_segs++; \ 2018e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2019e1235983SChangman Lee } else { \ 202039a53e0cSJaegeuk Kim si->node_segs++; \ 2021e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2022e1235983SChangman Lee } \ 202339a53e0cSJaegeuk Kim } while (0) 202439a53e0cSJaegeuk Kim 202539a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 202639a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 202739a53e0cSJaegeuk Kim 2028e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 202939a53e0cSJaegeuk Kim do { \ 2030963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 203139a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 203239a53e0cSJaegeuk Kim si->data_blks += (blks); \ 2033e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 203439a53e0cSJaegeuk Kim } while (0) 203539a53e0cSJaegeuk Kim 2036e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 203739a53e0cSJaegeuk Kim do { \ 2038963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 203939a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 204039a53e0cSJaegeuk Kim si->node_blks += (blks); \ 2041e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 204239a53e0cSJaegeuk Kim } while (0) 204339a53e0cSJaegeuk Kim 204439a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 204539a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 2046787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 20474589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 204839a53e0cSJaegeuk Kim #else 2049942e0be6SChangman Lee #define stat_inc_cp_count(si) 205042190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) 205139a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 2052dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 205333fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) 205433fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) 2055dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 2056029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 205791c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 205891c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 2059d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 2060d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 20610dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 20620dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 20633289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 20643289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 2065dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 2066dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 2067b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 2068e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 206939a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 2070e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 2071e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 207239a53e0cSJaegeuk Kim 207339a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 207439a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2075787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 20764589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 207739a53e0cSJaegeuk Kim #endif 207839a53e0cSJaegeuk Kim 207939a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 208039a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 208139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 208239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 208339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 208439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 208539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 208639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2087cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 208839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 208929e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 20901001b347SHuajun Li 2091e18c65b2SHuajun Li /* 2092e18c65b2SHuajun Li * inline.c 2093e18c65b2SHuajun Li */ 209401b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 209501b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 2096b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 20970bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 2098e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 2099b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 2100b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 2101b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 21020342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 21036e22c691SJaegeuk Kim struct f2fs_dir_entry *find_in_inline_dir(struct inode *, 21040b81d077SJaegeuk Kim struct fscrypt_name *, struct page **); 2105201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 2106201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 2107510022a8SJaegeuk Kim int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 2108510022a8SJaegeuk Kim nid_t, umode_t); 2109201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 2110201a05beSChao Yu struct inode *, struct inode *); 2111201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 2112d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *, struct dir_context *, 21130b81d077SJaegeuk Kim struct fscrypt_str *); 211467f8cf3cSJaegeuk Kim int f2fs_inline_data_fiemap(struct inode *, 211567f8cf3cSJaegeuk Kim struct fiemap_extent_info *, __u64, __u64); 2116cde4de12SJaegeuk Kim 2117cde4de12SJaegeuk Kim /* 21182658e50dSJaegeuk Kim * shrinker.c 21192658e50dSJaegeuk Kim */ 21202658e50dSJaegeuk Kim unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *); 21212658e50dSJaegeuk Kim unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *); 21222658e50dSJaegeuk Kim void f2fs_join_shrinker(struct f2fs_sb_info *); 21232658e50dSJaegeuk Kim void f2fs_leave_shrinker(struct f2fs_sb_info *); 21242658e50dSJaegeuk Kim 21252658e50dSJaegeuk Kim /* 2126a28ef1f5SChao Yu * extent_cache.c 2127a28ef1f5SChao Yu */ 2128a28ef1f5SChao Yu unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 2129ed3d1256SJaegeuk Kim bool f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 2130a28ef1f5SChao Yu unsigned int f2fs_destroy_extent_node(struct inode *); 2131a28ef1f5SChao Yu void f2fs_destroy_extent_tree(struct inode *); 2132a28ef1f5SChao Yu bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *); 2133a28ef1f5SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 213419b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 213519b2c30dSChao Yu pgoff_t, block_t, unsigned int); 2136a28ef1f5SChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 2137a28ef1f5SChao Yu int __init create_extent_cache(void); 2138a28ef1f5SChao Yu void destroy_extent_cache(void); 2139a28ef1f5SChao Yu 2140a28ef1f5SChao Yu /* 2141cde4de12SJaegeuk Kim * crypto support 2142cde4de12SJaegeuk Kim */ 21430b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2144cde4de12SJaegeuk Kim { 2145cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2146cde4de12SJaegeuk Kim } 2147cde4de12SJaegeuk Kim 2148cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2149cde4de12SJaegeuk Kim { 2150cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2151cde4de12SJaegeuk Kim file_set_encrypt(inode); 2152cde4de12SJaegeuk Kim #endif 2153cde4de12SJaegeuk Kim } 2154cde4de12SJaegeuk Kim 2155cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2156cde4de12SJaegeuk Kim { 21570b81d077SJaegeuk Kim return bio->bi_private != NULL; 2158cde4de12SJaegeuk Kim } 2159cde4de12SJaegeuk Kim 2160cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2161cde4de12SJaegeuk Kim { 2162cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2163cde4de12SJaegeuk Kim } 2164f424f664SJaegeuk Kim 2165fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2166fcc85a4dSJaegeuk Kim { 2167fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2168886f56f9SAl Viro umode_t mode = inode->i_mode; 2169fcc85a4dSJaegeuk Kim 2170fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2171fcc85a4dSJaegeuk Kim #else 2172fcc85a4dSJaegeuk Kim return 0; 2173fcc85a4dSJaegeuk Kim #endif 2174fcc85a4dSJaegeuk Kim } 2175fcc85a4dSJaegeuk Kim 21760b81d077SJaegeuk Kim #ifndef CONFIG_F2FS_FS_ENCRYPTION 21770b81d077SJaegeuk Kim #define fscrypt_set_d_op(i) 21780b81d077SJaegeuk Kim #define fscrypt_get_ctx fscrypt_notsupp_get_ctx 21790b81d077SJaegeuk Kim #define fscrypt_release_ctx fscrypt_notsupp_release_ctx 21800b81d077SJaegeuk Kim #define fscrypt_encrypt_page fscrypt_notsupp_encrypt_page 21810b81d077SJaegeuk Kim #define fscrypt_decrypt_page fscrypt_notsupp_decrypt_page 21820b81d077SJaegeuk Kim #define fscrypt_decrypt_bio_pages fscrypt_notsupp_decrypt_bio_pages 21830b81d077SJaegeuk Kim #define fscrypt_pullback_bio_page fscrypt_notsupp_pullback_bio_page 21840b81d077SJaegeuk Kim #define fscrypt_restore_control_page fscrypt_notsupp_restore_control_page 21850b81d077SJaegeuk Kim #define fscrypt_zeroout_range fscrypt_notsupp_zeroout_range 21860b81d077SJaegeuk Kim #define fscrypt_process_policy fscrypt_notsupp_process_policy 21870b81d077SJaegeuk Kim #define fscrypt_get_policy fscrypt_notsupp_get_policy 21880b81d077SJaegeuk Kim #define fscrypt_has_permitted_context fscrypt_notsupp_has_permitted_context 21890b81d077SJaegeuk Kim #define fscrypt_inherit_context fscrypt_notsupp_inherit_context 21900b81d077SJaegeuk Kim #define fscrypt_get_encryption_info fscrypt_notsupp_get_encryption_info 21910b81d077SJaegeuk Kim #define fscrypt_put_encryption_info fscrypt_notsupp_put_encryption_info 21920b81d077SJaegeuk Kim #define fscrypt_setup_filename fscrypt_notsupp_setup_filename 21930b81d077SJaegeuk Kim #define fscrypt_free_filename fscrypt_notsupp_free_filename 21940b81d077SJaegeuk Kim #define fscrypt_fname_encrypted_size fscrypt_notsupp_fname_encrypted_size 21950b81d077SJaegeuk Kim #define fscrypt_fname_alloc_buffer fscrypt_notsupp_fname_alloc_buffer 21960b81d077SJaegeuk Kim #define fscrypt_fname_free_buffer fscrypt_notsupp_fname_free_buffer 21970b81d077SJaegeuk Kim #define fscrypt_fname_disk_to_usr fscrypt_notsupp_fname_disk_to_usr 21980b81d077SJaegeuk Kim #define fscrypt_fname_usr_to_disk fscrypt_notsupp_fname_usr_to_disk 219957e5055bSJaegeuk Kim #endif 220039a53e0cSJaegeuk Kim #endif 2201