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> 2239a53e0cSJaegeuk Kim 235d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 249850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 250daaad97SJaegeuk Kim #define f2fs_down_write(x, y) down_write_nest_lock(x, y) 265d56b671SJaegeuk Kim #else 279850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 289850cf4aSJaegeuk Kim do { \ 299850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 309850cf4aSJaegeuk Kim WARN_ON(1); \ 31caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 329850cf4aSJaegeuk Kim } \ 339850cf4aSJaegeuk Kim } while (0) 340daaad97SJaegeuk Kim #define f2fs_down_write(x, y) down_write(x) 355d56b671SJaegeuk Kim #endif 365d56b671SJaegeuk Kim 3739a53e0cSJaegeuk Kim /* 3839a53e0cSJaegeuk Kim * For mount options 3939a53e0cSJaegeuk Kim */ 4039a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 4139a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 4239a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 4339a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 4439a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 4539a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 4639a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 47444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 481001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 4934d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 5034d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 5134d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 52d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 5389672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 5439a53e0cSJaegeuk Kim 5539a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 5639a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 5739a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 5839a53e0cSJaegeuk Kim 5939a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 6039a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 6139a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 6239a53e0cSJaegeuk Kim 63a9841c4dSJaegeuk Kim typedef u32 block_t; /* 64a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 65a9841c4dSJaegeuk Kim * address format, __le32. 66a9841c4dSJaegeuk Kim */ 6739a53e0cSJaegeuk Kim typedef u32 nid_t; 6839a53e0cSJaegeuk Kim 6939a53e0cSJaegeuk Kim struct f2fs_mount_info { 7039a53e0cSJaegeuk Kim unsigned int opt; 7139a53e0cSJaegeuk Kim }; 7239a53e0cSJaegeuk Kim 7376f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 7476f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 7576f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 7676f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) 7776f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 7876f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) 7976f105a2SJaegeuk Kim 807e586fa0SJaegeuk Kim #define CRCPOLY_LE 0xedb88320 817e586fa0SJaegeuk Kim 827e586fa0SJaegeuk Kim static inline __u32 f2fs_crc32(void *buf, size_t len) 8339a53e0cSJaegeuk Kim { 847e586fa0SJaegeuk Kim unsigned char *p = (unsigned char *)buf; 857e586fa0SJaegeuk Kim __u32 crc = F2FS_SUPER_MAGIC; 867e586fa0SJaegeuk Kim int i; 877e586fa0SJaegeuk Kim 887e586fa0SJaegeuk Kim while (len--) { 897e586fa0SJaegeuk Kim crc ^= *p++; 907e586fa0SJaegeuk Kim for (i = 0; i < 8; i++) 917e586fa0SJaegeuk Kim crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); 927e586fa0SJaegeuk Kim } 937e586fa0SJaegeuk Kim return crc; 9439a53e0cSJaegeuk Kim } 9539a53e0cSJaegeuk Kim 967e586fa0SJaegeuk Kim static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size) 9739a53e0cSJaegeuk Kim { 987e586fa0SJaegeuk Kim return f2fs_crc32(buf, buf_size) == blk_crc; 9939a53e0cSJaegeuk Kim } 10039a53e0cSJaegeuk Kim 10139a53e0cSJaegeuk Kim /* 10239a53e0cSJaegeuk Kim * For checkpoint manager 10339a53e0cSJaegeuk Kim */ 10439a53e0cSJaegeuk Kim enum { 10539a53e0cSJaegeuk Kim NAT_BITMAP, 10639a53e0cSJaegeuk Kim SIT_BITMAP 10739a53e0cSJaegeuk Kim }; 10839a53e0cSJaegeuk Kim 10975ab4cb8SJaegeuk Kim enum { 11075ab4cb8SJaegeuk Kim CP_UMOUNT, 111119ee914SJaegeuk Kim CP_FASTBOOT, 11275ab4cb8SJaegeuk Kim CP_SYNC, 11310027551SJaegeuk Kim CP_RECOVERY, 1144b2fecc8SJaegeuk Kim CP_DISCARD, 11575ab4cb8SJaegeuk Kim }; 11675ab4cb8SJaegeuk Kim 117bba681cbSJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 32 118bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 119bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 120bba681cbSJaegeuk Kim 12175ab4cb8SJaegeuk Kim struct cp_control { 12275ab4cb8SJaegeuk Kim int reason; 1234b2fecc8SJaegeuk Kim __u64 trim_start; 1244b2fecc8SJaegeuk Kim __u64 trim_end; 1254b2fecc8SJaegeuk Kim __u64 trim_minlen; 1264b2fecc8SJaegeuk Kim __u64 trimmed; 12775ab4cb8SJaegeuk Kim }; 12875ab4cb8SJaegeuk Kim 129662befdaSChao Yu /* 13081c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 131662befdaSChao Yu */ 132662befdaSChao Yu enum { 133662befdaSChao Yu META_CP, 134662befdaSChao Yu META_NAT, 13581c1a0f1SChao Yu META_SIT, 1364c521f49SJaegeuk Kim META_SSA, 1374c521f49SJaegeuk Kim META_POR, 138662befdaSChao Yu }; 139662befdaSChao Yu 1406451e041SJaegeuk Kim /* for the list of ino */ 1416451e041SJaegeuk Kim enum { 1426451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 143fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 144fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1456451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1466451e041SJaegeuk Kim }; 1476451e041SJaegeuk Kim 1486451e041SJaegeuk Kim struct ino_entry { 14939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 15039a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 15139a53e0cSJaegeuk Kim }; 15239a53e0cSJaegeuk Kim 15306292073SChao Yu /* 15406292073SChao Yu * for the list of directory inodes or gc inodes. 15506292073SChao Yu * NOTE: there are two slab users for this structure, if we add/modify/delete 15606292073SChao Yu * fields in structure for one of slab users, it may affect fields or size of 15706292073SChao Yu * other one, in this condition, it's better to split both of slab and related 15806292073SChao Yu * data structure. 15906292073SChao Yu */ 16006292073SChao Yu struct inode_entry { 16139a53e0cSJaegeuk Kim struct list_head list; /* list head */ 16239a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 16339a53e0cSJaegeuk Kim }; 16439a53e0cSJaegeuk Kim 1657fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1667fd9e544SJaegeuk Kim struct discard_entry { 1677fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1687fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1697fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1707fd9e544SJaegeuk Kim }; 1717fd9e544SJaegeuk Kim 17239a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 17339a53e0cSJaegeuk Kim struct fsync_inode_entry { 17439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17539a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 176c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 177c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 178c52e1b10SJaegeuk Kim block_t last_inode; /* block address locating the last inode */ 17939a53e0cSJaegeuk Kim }; 18039a53e0cSJaegeuk Kim 18139a53e0cSJaegeuk Kim #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats)) 18239a53e0cSJaegeuk Kim #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits)) 18339a53e0cSJaegeuk Kim 18439a53e0cSJaegeuk Kim #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne) 18539a53e0cSJaegeuk Kim #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid) 18639a53e0cSJaegeuk Kim #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se) 18739a53e0cSJaegeuk Kim #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno) 18839a53e0cSJaegeuk Kim 189309cc2b6SJaegeuk Kim #define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum)) 190309cc2b6SJaegeuk Kim #define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum)) 191309cc2b6SJaegeuk Kim 19239a53e0cSJaegeuk Kim static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i) 19339a53e0cSJaegeuk Kim { 19439a53e0cSJaegeuk Kim int before = nats_in_cursum(rs); 19539a53e0cSJaegeuk Kim rs->n_nats = cpu_to_le16(before + i); 19639a53e0cSJaegeuk Kim return before; 19739a53e0cSJaegeuk Kim } 19839a53e0cSJaegeuk Kim 19939a53e0cSJaegeuk Kim static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i) 20039a53e0cSJaegeuk Kim { 20139a53e0cSJaegeuk Kim int before = sits_in_cursum(rs); 20239a53e0cSJaegeuk Kim rs->n_sits = cpu_to_le16(before + i); 20339a53e0cSJaegeuk Kim return before; 20439a53e0cSJaegeuk Kim } 20539a53e0cSJaegeuk Kim 206184a5cd2SChao Yu static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size, 207184a5cd2SChao Yu int type) 208184a5cd2SChao Yu { 209184a5cd2SChao Yu if (type == NAT_JOURNAL) 210309cc2b6SJaegeuk Kim return size <= MAX_NAT_JENTRIES(sum); 211309cc2b6SJaegeuk Kim return size <= MAX_SIT_JENTRIES(sum); 212184a5cd2SChao Yu } 213184a5cd2SChao Yu 21439a53e0cSJaegeuk Kim /* 215e9750824SNamjae Jeon * ioctl commands 216e9750824SNamjae Jeon */ 217e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 218e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 219d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 220e9750824SNamjae Jeon 22188b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 22288b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 22388b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 22402a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2251e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2261e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 22788b88a66SJaegeuk Kim 2281abff93dSJaegeuk Kim /* 2291abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2301abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2311abff93dSJaegeuk Kim */ 2321abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2331abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2341abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2351abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 2361abff93dSJaegeuk Kim 237e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 238e9750824SNamjae Jeon /* 239e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 240e9750824SNamjae Jeon */ 241e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 242e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 243e9750824SNamjae Jeon #endif 244e9750824SNamjae Jeon 245e9750824SNamjae Jeon /* 24639a53e0cSJaegeuk Kim * For INODE and NODE manager 24739a53e0cSJaegeuk Kim */ 2487b3cd7d6SJaegeuk Kim /* for directory operations */ 2497b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 2507b3cd7d6SJaegeuk Kim const void *bitmap; 2517b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 2527b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 2537b3cd7d6SJaegeuk Kim int max; 2547b3cd7d6SJaegeuk Kim }; 2557b3cd7d6SJaegeuk Kim 2567b3cd7d6SJaegeuk Kim static inline void make_dentry_ptr(struct f2fs_dentry_ptr *d, 2577b3cd7d6SJaegeuk Kim void *src, int type) 2587b3cd7d6SJaegeuk Kim { 2597b3cd7d6SJaegeuk Kim if (type == 1) { 2607b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 2617b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 2627b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2637b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 2647b3cd7d6SJaegeuk Kim d->filename = t->filename; 2657b3cd7d6SJaegeuk Kim } else { 2667b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 2677b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 2687b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2697b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 2707b3cd7d6SJaegeuk Kim d->filename = t->filename; 2717b3cd7d6SJaegeuk Kim } 2727b3cd7d6SJaegeuk Kim } 2737b3cd7d6SJaegeuk Kim 274dbe6a5ffSJaegeuk Kim /* 275dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 276dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 277dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 27839a53e0cSJaegeuk Kim */ 279dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 280dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 281266e97a8SJaegeuk Kim enum { 282266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 283266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 284266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 285266e97a8SJaegeuk Kim * look up a node with readahead called 2864f4124d0SChao Yu * by get_data_block. 28739a53e0cSJaegeuk Kim */ 288266e97a8SJaegeuk Kim }; 289266e97a8SJaegeuk Kim 29039a53e0cSJaegeuk Kim #define F2FS_LINK_MAX 32000 /* maximum link count per file */ 29139a53e0cSJaegeuk Kim 292817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 293817202d9SChao Yu 29413054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 29513054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 29613054c54SChao Yu 29739a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 29813054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 29913054c54SChao Yu 30013054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 30113054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 302c11abd1aSJaegeuk Kim 30339a53e0cSJaegeuk Kim struct extent_info { 30439a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3054d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 306111d2495SMasanari Iida unsigned int len; /* length of the extent */ 30739a53e0cSJaegeuk Kim }; 30839a53e0cSJaegeuk Kim 30913054c54SChao Yu struct extent_node { 31013054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 31113054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 31213054c54SChao Yu struct extent_info ei; /* extent info */ 31313054c54SChao Yu }; 31413054c54SChao Yu 31513054c54SChao Yu struct extent_tree { 31613054c54SChao Yu nid_t ino; /* inode number */ 31713054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 31862c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 31913054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 32013054c54SChao Yu atomic_t refcount; /* reference count of rb-tree */ 32113054c54SChao Yu unsigned int count; /* # of extent node in rb-tree*/ 32213054c54SChao Yu }; 32313054c54SChao Yu 32439a53e0cSJaegeuk Kim /* 325003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 326003a3e1dSJaegeuk Kim * 327003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 328003a3e1dSJaegeuk Kim */ 329003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 330003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 331003a3e1dSJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED) 332003a3e1dSJaegeuk Kim 333003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 334003a3e1dSJaegeuk Kim block_t m_pblk; 335003a3e1dSJaegeuk Kim block_t m_lblk; 336003a3e1dSJaegeuk Kim unsigned int m_len; 337003a3e1dSJaegeuk Kim unsigned int m_flags; 338003a3e1dSJaegeuk Kim }; 339003a3e1dSJaegeuk Kim 340003a3e1dSJaegeuk Kim /* 34139a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 34239a53e0cSJaegeuk Kim */ 34339a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 344354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 34539a53e0cSJaegeuk Kim 346b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 347b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 348b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 349b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 350b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 351b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 352b5492af7SJaegeuk Kim 353ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 354ab9fa662SJaegeuk Kim 35539a53e0cSJaegeuk Kim struct f2fs_inode_info { 35639a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 35739a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 35839a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 35938431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 36039a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 3616666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 36239a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 36339a53e0cSJaegeuk Kim 36439a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 36539a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 366d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 367a7ffdbe2SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 36839a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 36939a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 37039a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 371e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 37239a53e0cSJaegeuk Kim struct extent_info ext; /* in-memory extent cache entry */ 3730c872e2dSChao Yu rwlock_t ext_lock; /* rwlock for single extent cache */ 37406292073SChao Yu struct inode_entry *dirty_dir; /* the pointer of dirty dir */ 37588b88a66SJaegeuk Kim 37634ba94baSJaegeuk Kim struct radix_tree_root inmem_root; /* radix tree for inmem pages */ 37788b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 37888b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 37939a53e0cSJaegeuk Kim }; 38039a53e0cSJaegeuk Kim 38139a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 38239a53e0cSJaegeuk Kim struct f2fs_extent i_ext) 38339a53e0cSJaegeuk Kim { 38439a53e0cSJaegeuk Kim ext->fofs = le32_to_cpu(i_ext.fofs); 3854d0b0bd4SChao Yu ext->blk = le32_to_cpu(i_ext.blk); 38639a53e0cSJaegeuk Kim ext->len = le32_to_cpu(i_ext.len); 38739a53e0cSJaegeuk Kim } 38839a53e0cSJaegeuk Kim 38939a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 39039a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 39139a53e0cSJaegeuk Kim { 39239a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 3934d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 39439a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 39539a53e0cSJaegeuk Kim } 39639a53e0cSJaegeuk Kim 397429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 398429511cdSChao Yu u32 blk, unsigned int len) 399429511cdSChao Yu { 400429511cdSChao Yu ei->fofs = fofs; 401429511cdSChao Yu ei->blk = blk; 402429511cdSChao Yu ei->len = len; 403429511cdSChao Yu } 404429511cdSChao Yu 4050bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1, 4060bdee482SChao Yu struct extent_info *ei2) 4070bdee482SChao Yu { 4080bdee482SChao Yu return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 4090bdee482SChao Yu ei1->len == ei2->len); 4100bdee482SChao Yu } 4110bdee482SChao Yu 412429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 413429511cdSChao Yu struct extent_info *front) 414429511cdSChao Yu { 415429511cdSChao Yu return (back->fofs + back->len == front->fofs && 416429511cdSChao Yu back->blk + back->len == front->blk); 417429511cdSChao Yu } 418429511cdSChao Yu 419429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 420429511cdSChao Yu struct extent_info *back) 421429511cdSChao Yu { 422429511cdSChao Yu return __is_extent_mergeable(back, cur); 423429511cdSChao Yu } 424429511cdSChao Yu 425429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 426429511cdSChao Yu struct extent_info *front) 427429511cdSChao Yu { 428429511cdSChao Yu return __is_extent_mergeable(cur, front); 429429511cdSChao Yu } 430429511cdSChao Yu 43139a53e0cSJaegeuk Kim struct f2fs_nm_info { 43239a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 43339a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 4347ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 43539a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 436cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 43739a53e0cSJaegeuk Kim 43839a53e0cSJaegeuk Kim /* NAT cache management */ 43939a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 440309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 4418b26ef98SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 44239a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 443309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 444aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 44539a53e0cSJaegeuk Kim 44639a53e0cSJaegeuk Kim /* free node ids management */ 4478a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 44839a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 44939a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 45039a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 45139a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 45239a53e0cSJaegeuk Kim 45339a53e0cSJaegeuk Kim /* for checkpoint */ 45439a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 45539a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 45639a53e0cSJaegeuk Kim }; 45739a53e0cSJaegeuk Kim 45839a53e0cSJaegeuk Kim /* 45939a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 46039a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 46139a53e0cSJaegeuk Kim * by the data offset in a file. 46239a53e0cSJaegeuk Kim */ 46339a53e0cSJaegeuk Kim struct dnode_of_data { 46439a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 46539a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 46639a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 46739a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 46839a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 46939a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 47039a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 47139a53e0cSJaegeuk Kim }; 47239a53e0cSJaegeuk Kim 47339a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 47439a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 47539a53e0cSJaegeuk Kim { 476d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 47739a53e0cSJaegeuk Kim dn->inode = inode; 47839a53e0cSJaegeuk Kim dn->inode_page = ipage; 47939a53e0cSJaegeuk Kim dn->node_page = npage; 48039a53e0cSJaegeuk Kim dn->nid = nid; 48139a53e0cSJaegeuk Kim } 48239a53e0cSJaegeuk Kim 48339a53e0cSJaegeuk Kim /* 48439a53e0cSJaegeuk Kim * For SIT manager 48539a53e0cSJaegeuk Kim * 48639a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 48739a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 48839a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 48939a53e0cSJaegeuk Kim * respectively. 49039a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 49139a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 49239a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 49339a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 49439a53e0cSJaegeuk Kim * data and 8 for node logs. 49539a53e0cSJaegeuk Kim */ 49639a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 49739a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 49839a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 49939a53e0cSJaegeuk Kim 50039a53e0cSJaegeuk Kim enum { 50139a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 50239a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 50339a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 50439a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 50539a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 50639a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 50738aa0889SJaegeuk Kim NO_CHECK_TYPE, 50838aa0889SJaegeuk Kim CURSEG_DIRECT_IO, /* to use for the direct IO path */ 50939a53e0cSJaegeuk Kim }; 51039a53e0cSJaegeuk Kim 5116b4afdd7SJaegeuk Kim struct flush_cmd { 5126b4afdd7SJaegeuk Kim struct completion wait; 513721bd4d5SGu Zheng struct llist_node llnode; 5146b4afdd7SJaegeuk Kim int ret; 5156b4afdd7SJaegeuk Kim }; 5166b4afdd7SJaegeuk Kim 517a688b9d9SGu Zheng struct flush_cmd_control { 518a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 519a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 520721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 521721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 522a688b9d9SGu Zheng }; 523a688b9d9SGu Zheng 52439a53e0cSJaegeuk Kim struct f2fs_sm_info { 52539a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 52639a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 52739a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 52839a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 52939a53e0cSJaegeuk Kim 53039a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 53139a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 53239a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 53339a53e0cSJaegeuk Kim 53439a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 53539a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 53639a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 53739a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 53881eb8d6eSJaegeuk Kim 53981eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 54081eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 5417fd9e544SJaegeuk Kim 5427fd9e544SJaegeuk Kim /* for small discard management */ 5437fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 5447fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 5457fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 546216fbd64SJaegeuk Kim 547bba681cbSJaegeuk Kim /* for batched trimming */ 548bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 549bba681cbSJaegeuk Kim 550184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 551184a5cd2SChao Yu 552216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 553216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 554c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 5556b4afdd7SJaegeuk Kim 5566b4afdd7SJaegeuk Kim /* for flush command control */ 557a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 558a688b9d9SGu Zheng 55939a53e0cSJaegeuk Kim }; 56039a53e0cSJaegeuk Kim 56139a53e0cSJaegeuk Kim /* 56239a53e0cSJaegeuk Kim * For superblock 56339a53e0cSJaegeuk Kim */ 56439a53e0cSJaegeuk Kim /* 56539a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 56639a53e0cSJaegeuk Kim * 56739a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 56839a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 56939a53e0cSJaegeuk Kim */ 57039a53e0cSJaegeuk Kim enum count_type { 57139a53e0cSJaegeuk Kim F2FS_WRITEBACK, 57239a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 57339a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 57439a53e0cSJaegeuk Kim F2FS_DIRTY_META, 5758dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 57639a53e0cSJaegeuk Kim NR_COUNT_TYPE, 57739a53e0cSJaegeuk Kim }; 57839a53e0cSJaegeuk Kim 57939a53e0cSJaegeuk Kim /* 580e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 58139a53e0cSJaegeuk Kim * The available types are: 58239a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 58339a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 58439a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 58539a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 58639a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 58739a53e0cSJaegeuk Kim * with waiting the bio's completion 58839a53e0cSJaegeuk Kim * ... Only can be used with META. 58939a53e0cSJaegeuk Kim */ 5907d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 59139a53e0cSJaegeuk Kim enum page_type { 59239a53e0cSJaegeuk Kim DATA, 59339a53e0cSJaegeuk Kim NODE, 59439a53e0cSJaegeuk Kim META, 59539a53e0cSJaegeuk Kim NR_PAGE_TYPE, 59639a53e0cSJaegeuk Kim META_FLUSH, 5978ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 5988ce67cb0SJaegeuk Kim INMEM_DROP, 5998ce67cb0SJaegeuk Kim IPU, 6008ce67cb0SJaegeuk Kim OPU, 60139a53e0cSJaegeuk Kim }; 60239a53e0cSJaegeuk Kim 603458e6197SJaegeuk Kim struct f2fs_io_info { 604*05ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 605458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 6067e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 607cf04e8ebSJaegeuk Kim block_t blk_addr; /* block address to be written */ 608*05ca3632SJaegeuk Kim struct page *page; /* page to be written */ 609458e6197SJaegeuk Kim }; 610458e6197SJaegeuk Kim 61193dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 6121ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 613458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 6141ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 6151ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 616458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 617df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 6181ff7bd3bSJaegeuk Kim }; 6191ff7bd3bSJaegeuk Kim 62067298804SChao Yu /* for inner inode cache management */ 62167298804SChao Yu struct inode_management { 62267298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 62367298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 62467298804SChao Yu struct list_head ino_list; /* inode list head */ 62567298804SChao Yu unsigned long ino_num; /* number of entries */ 62667298804SChao Yu }; 62767298804SChao Yu 628caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 629caf0047eSChao Yu enum { 630caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 631caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 632caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 633caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 634caf0047eSChao Yu }; 635caf0047eSChao Yu 63639a53e0cSJaegeuk Kim struct f2fs_sb_info { 63739a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 6385e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 63939a53e0cSJaegeuk Kim struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 64039a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 641caf0047eSChao Yu int s_flag; /* flags for sbi */ 64239a53e0cSJaegeuk Kim 64339a53e0cSJaegeuk Kim /* for node-related operations */ 64439a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 64539a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 64639a53e0cSJaegeuk Kim 64739a53e0cSJaegeuk Kim /* for segment-related operations */ 64839a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 6491ff7bd3bSJaegeuk Kim 6501ff7bd3bSJaegeuk Kim /* for bio operations */ 651924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 6521ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 65339a53e0cSJaegeuk Kim 65439a53e0cSJaegeuk Kim /* for checkpoint */ 65539a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 65639a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 65739936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 658e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 659b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 6605463e7c1SJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 661fb51b5efSChangman Lee wait_queue_head_t cp_wait; 66239a53e0cSJaegeuk Kim 66367298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 6646451e041SJaegeuk Kim 6656451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 6660d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 66739a53e0cSJaegeuk Kim 66839a53e0cSJaegeuk Kim /* for directory inode management */ 66939a53e0cSJaegeuk Kim struct list_head dir_inode_list; /* dir inode list */ 67039a53e0cSJaegeuk Kim spinlock_t dir_inode_lock; /* for dir inode list lock */ 67139a53e0cSJaegeuk Kim 67213054c54SChao Yu /* for extent tree cache */ 67313054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 67413054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 67513054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 67613054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 67713054c54SChao Yu int total_ext_tree; /* extent tree count */ 67813054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 67913054c54SChao Yu 68039a53e0cSJaegeuk Kim /* basic filesystem units */ 68139a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 68239a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 68339a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 68439a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 68539a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 68639a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 68739a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 68839a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 68939a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 69039a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 69139a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 69239a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 69339a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 69439a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 69539a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 696ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 69739a53e0cSJaegeuk Kim 69839a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 69939a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 70039a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 70139a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 70239a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 70339a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 70439a53e0cSJaegeuk Kim 70539a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 70639a53e0cSJaegeuk Kim 70739a53e0cSJaegeuk Kim /* for cleaning operations */ 70839a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 70939a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 7105ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 71139a53e0cSJaegeuk Kim 712b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 713b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 714b1c57c1cSJaegeuk Kim 71539a53e0cSJaegeuk Kim /* 71639a53e0cSJaegeuk Kim * for stat information. 71739a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 71839a53e0cSJaegeuk Kim */ 71935b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 72039a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 72139a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 72239a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 723b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 72439a53e0cSJaegeuk Kim int total_hit_ext, read_hit_ext; /* extent cache hit ratio */ 72503e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 72603e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 72739a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 72835b09d82SNamjae Jeon unsigned int n_dirty_dirs; /* # of dir inodes */ 72935b09d82SNamjae Jeon #endif 73035b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 73139a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 732b59d0baeSNamjae Jeon 733b59d0baeSNamjae Jeon /* For sysfs suppport */ 734b59d0baeSNamjae Jeon struct kobject s_kobj; 735b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 73639a53e0cSJaegeuk Kim }; 73739a53e0cSJaegeuk Kim 73839a53e0cSJaegeuk Kim /* 73939a53e0cSJaegeuk Kim * Inline functions 74039a53e0cSJaegeuk Kim */ 74139a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 74239a53e0cSJaegeuk Kim { 74339a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 74439a53e0cSJaegeuk Kim } 74539a53e0cSJaegeuk Kim 74639a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 74739a53e0cSJaegeuk Kim { 74839a53e0cSJaegeuk Kim return sb->s_fs_info; 74939a53e0cSJaegeuk Kim } 75039a53e0cSJaegeuk Kim 7514081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 7524081363fSJaegeuk Kim { 7534081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 7544081363fSJaegeuk Kim } 7554081363fSJaegeuk Kim 7564081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 7574081363fSJaegeuk Kim { 7584081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 7594081363fSJaegeuk Kim } 7604081363fSJaegeuk Kim 7614081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 7624081363fSJaegeuk Kim { 7634081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 7644081363fSJaegeuk Kim } 7654081363fSJaegeuk Kim 76639a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 76739a53e0cSJaegeuk Kim { 76839a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 76939a53e0cSJaegeuk Kim } 77039a53e0cSJaegeuk Kim 77139a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 77239a53e0cSJaegeuk Kim { 77339a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 77439a53e0cSJaegeuk Kim } 77539a53e0cSJaegeuk Kim 77645590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 77745590710SGu Zheng { 77845590710SGu Zheng return (struct f2fs_node *)page_address(page); 77945590710SGu Zheng } 78045590710SGu Zheng 78158bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 78258bfaf44SJaegeuk Kim { 78358bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 78458bfaf44SJaegeuk Kim } 78558bfaf44SJaegeuk Kim 78639a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 78739a53e0cSJaegeuk Kim { 78839a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 78939a53e0cSJaegeuk Kim } 79039a53e0cSJaegeuk Kim 79139a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 79239a53e0cSJaegeuk Kim { 79339a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 79439a53e0cSJaegeuk Kim } 79539a53e0cSJaegeuk Kim 79639a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 79739a53e0cSJaegeuk Kim { 79839a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 79939a53e0cSJaegeuk Kim } 80039a53e0cSJaegeuk Kim 80139a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 80239a53e0cSJaegeuk Kim { 80339a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 80439a53e0cSJaegeuk Kim } 80539a53e0cSJaegeuk Kim 80639a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 80739a53e0cSJaegeuk Kim { 80839a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 80939a53e0cSJaegeuk Kim } 81039a53e0cSJaegeuk Kim 8119df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 8129df27d98SGu Zheng { 8139df27d98SGu Zheng return sbi->meta_inode->i_mapping; 8149df27d98SGu Zheng } 8159df27d98SGu Zheng 8164ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 8174ef51a8fSJaegeuk Kim { 8184ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 8194ef51a8fSJaegeuk Kim } 8204ef51a8fSJaegeuk Kim 821caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 82239a53e0cSJaegeuk Kim { 823caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 82439a53e0cSJaegeuk Kim } 82539a53e0cSJaegeuk Kim 826caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 82739a53e0cSJaegeuk Kim { 828caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 829caf0047eSChao Yu } 830caf0047eSChao Yu 831caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 832caf0047eSChao Yu { 833caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 83439a53e0cSJaegeuk Kim } 83539a53e0cSJaegeuk Kim 836d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 837d71b5564SJaegeuk Kim { 838d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 839d71b5564SJaegeuk Kim } 840d71b5564SJaegeuk Kim 84125ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 84225ca923bSJaegeuk Kim { 84325ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 84425ca923bSJaegeuk Kim return ckpt_flags & f; 84525ca923bSJaegeuk Kim } 84625ca923bSJaegeuk Kim 84725ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 84825ca923bSJaegeuk Kim { 84925ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 85025ca923bSJaegeuk Kim ckpt_flags |= f; 85125ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 85225ca923bSJaegeuk Kim } 85325ca923bSJaegeuk Kim 85425ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 85525ca923bSJaegeuk Kim { 85625ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 85725ca923bSJaegeuk Kim ckpt_flags &= (~f); 85825ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 85925ca923bSJaegeuk Kim } 86025ca923bSJaegeuk Kim 861e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 86239a53e0cSJaegeuk Kim { 863e479556bSGu Zheng down_read(&sbi->cp_rwsem); 86439a53e0cSJaegeuk Kim } 86539a53e0cSJaegeuk Kim 866e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 86739a53e0cSJaegeuk Kim { 868e479556bSGu Zheng up_read(&sbi->cp_rwsem); 86939936837SJaegeuk Kim } 87039936837SJaegeuk Kim 871e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 87239936837SJaegeuk Kim { 8730daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 87439936837SJaegeuk Kim } 87539936837SJaegeuk Kim 876e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 87739936837SJaegeuk Kim { 878e479556bSGu Zheng up_write(&sbi->cp_rwsem); 87939a53e0cSJaegeuk Kim } 88039a53e0cSJaegeuk Kim 881119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 882119ee914SJaegeuk Kim { 883119ee914SJaegeuk Kim int reason = CP_SYNC; 884119ee914SJaegeuk Kim 885119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 886119ee914SJaegeuk Kim reason = CP_FASTBOOT; 887119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 888119ee914SJaegeuk Kim reason = CP_UMOUNT; 889119ee914SJaegeuk Kim return reason; 890119ee914SJaegeuk Kim } 891119ee914SJaegeuk Kim 892119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 893119ee914SJaegeuk Kim { 894119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 895119ee914SJaegeuk Kim } 896119ee914SJaegeuk Kim 897119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 898119ee914SJaegeuk Kim { 899119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 900119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 901119ee914SJaegeuk Kim } 902119ee914SJaegeuk Kim 90339a53e0cSJaegeuk Kim /* 90439a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 90539a53e0cSJaegeuk Kim */ 906064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 90739a53e0cSJaegeuk Kim { 908d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 909d6b7d4b3SChao Yu return -EINVAL; 910cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 911064e0823SNamjae Jeon return -EINVAL; 912064e0823SNamjae Jeon return 0; 91339a53e0cSJaegeuk Kim } 91439a53e0cSJaegeuk Kim 91539a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 91639a53e0cSJaegeuk Kim 91739a53e0cSJaegeuk Kim /* 91839a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 91939a53e0cSJaegeuk Kim */ 92039a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 92139a53e0cSJaegeuk Kim { 92239a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 9236c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 92439a53e0cSJaegeuk Kim else 9256c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 92639a53e0cSJaegeuk Kim } 92739a53e0cSJaegeuk Kim 9284bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 9294bc8e9bcSChao Yu { 9304bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 9314bc8e9bcSChao Yu } 9324bc8e9bcSChao Yu 93339a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 93439a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 93539a53e0cSJaegeuk Kim { 93639a53e0cSJaegeuk Kim block_t valid_block_count; 93739a53e0cSJaegeuk Kim 93839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 93939a53e0cSJaegeuk Kim valid_block_count = 94039a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 941cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 94239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 94339a53e0cSJaegeuk Kim return false; 94439a53e0cSJaegeuk Kim } 94539a53e0cSJaegeuk Kim inode->i_blocks += count; 94639a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 94739a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 94839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 94939a53e0cSJaegeuk Kim return true; 95039a53e0cSJaegeuk Kim } 95139a53e0cSJaegeuk Kim 952da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 95339a53e0cSJaegeuk Kim struct inode *inode, 95439a53e0cSJaegeuk Kim blkcnt_t count) 95539a53e0cSJaegeuk Kim { 95639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 9579850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 9589850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 95939a53e0cSJaegeuk Kim inode->i_blocks -= count; 96039a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 96139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 96239a53e0cSJaegeuk Kim } 96339a53e0cSJaegeuk Kim 96439a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 96539a53e0cSJaegeuk Kim { 96639a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 967caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 96839a53e0cSJaegeuk Kim } 96939a53e0cSJaegeuk Kim 970a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 97139a53e0cSJaegeuk Kim { 972a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 973a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 9744081363fSJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 97539a53e0cSJaegeuk Kim } 97639a53e0cSJaegeuk Kim 97739a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 97839a53e0cSJaegeuk Kim { 97939a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 98039a53e0cSJaegeuk Kim } 98139a53e0cSJaegeuk Kim 982a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 98339a53e0cSJaegeuk Kim { 984a7ffdbe2SJaegeuk Kim if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)) 9851fe54f9dSJaegeuk Kim return; 9861fe54f9dSJaegeuk Kim 987a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 988a7ffdbe2SJaegeuk Kim 989a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 9904081363fSJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 99139a53e0cSJaegeuk Kim } 99239a53e0cSJaegeuk Kim 99339a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 99439a53e0cSJaegeuk Kim { 99539a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 99639a53e0cSJaegeuk Kim } 99739a53e0cSJaegeuk Kim 998a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 999f8b2c1f9SJaegeuk Kim { 1000a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1001f8b2c1f9SJaegeuk Kim } 1002f8b2c1f9SJaegeuk Kim 10035ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 10045ac206cfSNamjae Jeon { 10055ac206cfSNamjae Jeon unsigned int pages_per_sec = sbi->segs_per_sec * 10065ac206cfSNamjae Jeon (1 << sbi->log_blocks_per_seg); 10075ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 10085ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 10095ac206cfSNamjae Jeon } 10105ac206cfSNamjae Jeon 101139a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 101239a53e0cSJaegeuk Kim { 10138b8343faSJaegeuk Kim return sbi->total_valid_block_count; 101439a53e0cSJaegeuk Kim } 101539a53e0cSJaegeuk Kim 101639a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 101739a53e0cSJaegeuk Kim { 101839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 101939a53e0cSJaegeuk Kim 102039a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 102139a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 102239a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 102339a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 102439a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 102539a53e0cSJaegeuk Kim 102639a53e0cSJaegeuk Kim return 0; 102739a53e0cSJaegeuk Kim } 102839a53e0cSJaegeuk Kim 102955141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 103055141486SWanpeng Li { 103155141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 103255141486SWanpeng Li } 103355141486SWanpeng Li 103439a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 103539a53e0cSJaegeuk Kim { 103639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 10371dbe4152SChangman Lee int offset; 10381dbe4152SChangman Lee 103955141486SWanpeng Li if (__cp_payload(sbi) > 0) { 10401dbe4152SChangman Lee if (flag == NAT_BITMAP) 10411dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 10421dbe4152SChangman Lee else 104365b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 10441dbe4152SChangman Lee } else { 10451dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 104625ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 104739a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 104839a53e0cSJaegeuk Kim } 10491dbe4152SChangman Lee } 105039a53e0cSJaegeuk Kim 105139a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 105239a53e0cSJaegeuk Kim { 105339a53e0cSJaegeuk Kim block_t start_addr; 105439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1055d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 105639a53e0cSJaegeuk Kim 105725ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 105839a53e0cSJaegeuk Kim 105939a53e0cSJaegeuk Kim /* 106039a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1061e1c42045Sarter97 * and even segment must be at cp segment 1 106239a53e0cSJaegeuk Kim */ 106339a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 106439a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 106539a53e0cSJaegeuk Kim 106639a53e0cSJaegeuk Kim return start_addr; 106739a53e0cSJaegeuk Kim } 106839a53e0cSJaegeuk Kim 106939a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 107039a53e0cSJaegeuk Kim { 107139a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 107239a53e0cSJaegeuk Kim } 107339a53e0cSJaegeuk Kim 107439a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1075ef86d709SGu Zheng struct inode *inode) 107639a53e0cSJaegeuk Kim { 107739a53e0cSJaegeuk Kim block_t valid_block_count; 107839a53e0cSJaegeuk Kim unsigned int valid_node_count; 107939a53e0cSJaegeuk Kim 108039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 108139a53e0cSJaegeuk Kim 1082ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1083cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 108439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 108539a53e0cSJaegeuk Kim return false; 108639a53e0cSJaegeuk Kim } 108739a53e0cSJaegeuk Kim 1088ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1089cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 109039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 109139a53e0cSJaegeuk Kim return false; 109239a53e0cSJaegeuk Kim } 109339a53e0cSJaegeuk Kim 109439a53e0cSJaegeuk Kim if (inode) 1095ef86d709SGu Zheng inode->i_blocks++; 1096ef86d709SGu Zheng 1097ef86d709SGu Zheng sbi->alloc_valid_block_count++; 1098ef86d709SGu Zheng sbi->total_valid_node_count++; 1099ef86d709SGu Zheng sbi->total_valid_block_count++; 110039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 110139a53e0cSJaegeuk Kim 110239a53e0cSJaegeuk Kim return true; 110339a53e0cSJaegeuk Kim } 110439a53e0cSJaegeuk Kim 110539a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1106ef86d709SGu Zheng struct inode *inode) 110739a53e0cSJaegeuk Kim { 110839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 110939a53e0cSJaegeuk Kim 11109850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 11119850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 11129850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 111339a53e0cSJaegeuk Kim 1114ef86d709SGu Zheng inode->i_blocks--; 1115ef86d709SGu Zheng sbi->total_valid_node_count--; 1116ef86d709SGu Zheng sbi->total_valid_block_count--; 111739a53e0cSJaegeuk Kim 111839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 111939a53e0cSJaegeuk Kim } 112039a53e0cSJaegeuk Kim 112139a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 112239a53e0cSJaegeuk Kim { 11238b8343faSJaegeuk Kim return sbi->total_valid_node_count; 112439a53e0cSJaegeuk Kim } 112539a53e0cSJaegeuk Kim 112639a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 112739a53e0cSJaegeuk Kim { 112839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 11299850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 113039a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 113139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 113239a53e0cSJaegeuk Kim } 113339a53e0cSJaegeuk Kim 11340e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 113539a53e0cSJaegeuk Kim { 113639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 11379850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 113839a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 113939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 114039a53e0cSJaegeuk Kim } 114139a53e0cSJaegeuk Kim 114239a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 114339a53e0cSJaegeuk Kim { 11448b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 114539a53e0cSJaegeuk Kim } 114639a53e0cSJaegeuk Kim 114739a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 114839a53e0cSJaegeuk Kim { 1149031fa8ccSJaegeuk Kim if (!page) 115039a53e0cSJaegeuk Kim return; 115139a53e0cSJaegeuk Kim 115239a53e0cSJaegeuk Kim if (unlock) { 11539850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 115439a53e0cSJaegeuk Kim unlock_page(page); 115539a53e0cSJaegeuk Kim } 115639a53e0cSJaegeuk Kim page_cache_release(page); 115739a53e0cSJaegeuk Kim } 115839a53e0cSJaegeuk Kim 115939a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 116039a53e0cSJaegeuk Kim { 116139a53e0cSJaegeuk Kim if (dn->node_page) 116239a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 116339a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 116439a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 116539a53e0cSJaegeuk Kim dn->node_page = NULL; 116639a53e0cSJaegeuk Kim dn->inode_page = NULL; 116739a53e0cSJaegeuk Kim } 116839a53e0cSJaegeuk Kim 116939a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1170e8512d2eSGu Zheng size_t size) 117139a53e0cSJaegeuk Kim { 1172e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 117339a53e0cSJaegeuk Kim } 117439a53e0cSJaegeuk Kim 11757bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 11767bd59381SGu Zheng gfp_t flags) 11777bd59381SGu Zheng { 11787bd59381SGu Zheng void *entry; 11797bd59381SGu Zheng retry: 11807bd59381SGu Zheng entry = kmem_cache_alloc(cachep, flags); 11817bd59381SGu Zheng if (!entry) { 11827bd59381SGu Zheng cond_resched(); 11837bd59381SGu Zheng goto retry; 11847bd59381SGu Zheng } 11857bd59381SGu Zheng 11867bd59381SGu Zheng return entry; 11877bd59381SGu Zheng } 11887bd59381SGu Zheng 11899be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 11909be32d72SJaegeuk Kim unsigned long index, void *item) 11919be32d72SJaegeuk Kim { 11929be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 11939be32d72SJaegeuk Kim cond_resched(); 11949be32d72SJaegeuk Kim } 11959be32d72SJaegeuk Kim 119639a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 119739a53e0cSJaegeuk Kim 119839a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 119939a53e0cSJaegeuk Kim { 120045590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 120139a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 120239a53e0cSJaegeuk Kim } 120339a53e0cSJaegeuk Kim 120439a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 120539a53e0cSJaegeuk Kim { 120639a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 120739a53e0cSJaegeuk Kim } 120839a53e0cSJaegeuk Kim 120939a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 121039a53e0cSJaegeuk Kim unsigned int offset) 121139a53e0cSJaegeuk Kim { 121239a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 121339a53e0cSJaegeuk Kim __le32 *addr_array; 121445590710SGu Zheng raw_node = F2FS_NODE(node_page); 121539a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 121639a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 121739a53e0cSJaegeuk Kim } 121839a53e0cSJaegeuk Kim 121939a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 122039a53e0cSJaegeuk Kim { 122139a53e0cSJaegeuk Kim int mask; 122239a53e0cSJaegeuk Kim 122339a53e0cSJaegeuk Kim addr += (nr >> 3); 122439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 122539a53e0cSJaegeuk Kim return mask & *addr; 122639a53e0cSJaegeuk Kim } 122739a53e0cSJaegeuk Kim 122852aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 122939a53e0cSJaegeuk Kim { 123039a53e0cSJaegeuk Kim int mask; 123139a53e0cSJaegeuk Kim int ret; 123239a53e0cSJaegeuk Kim 123339a53e0cSJaegeuk Kim addr += (nr >> 3); 123439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 123539a53e0cSJaegeuk Kim ret = mask & *addr; 123639a53e0cSJaegeuk Kim *addr |= mask; 123739a53e0cSJaegeuk Kim return ret; 123839a53e0cSJaegeuk Kim } 123939a53e0cSJaegeuk Kim 124052aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 124139a53e0cSJaegeuk Kim { 124239a53e0cSJaegeuk Kim int mask; 124339a53e0cSJaegeuk Kim int ret; 124439a53e0cSJaegeuk Kim 124539a53e0cSJaegeuk Kim addr += (nr >> 3); 124639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 124739a53e0cSJaegeuk Kim ret = mask & *addr; 124839a53e0cSJaegeuk Kim *addr &= ~mask; 124939a53e0cSJaegeuk Kim return ret; 125039a53e0cSJaegeuk Kim } 125139a53e0cSJaegeuk Kim 1252c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1253c6ac4c0eSGu Zheng { 1254c6ac4c0eSGu Zheng int mask; 1255c6ac4c0eSGu Zheng 1256c6ac4c0eSGu Zheng addr += (nr >> 3); 1257c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1258c6ac4c0eSGu Zheng *addr ^= mask; 1259c6ac4c0eSGu Zheng } 1260c6ac4c0eSGu Zheng 126139a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 126239a53e0cSJaegeuk Kim enum { 126339a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1264b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1265ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 126639a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 126739a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 126839a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1269699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 127074d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1271c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1272444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 12731001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 127434d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1275fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1276fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 127788b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 127888b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 127902a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 12803c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 12811e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1282b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1283510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 128439a53e0cSJaegeuk Kim }; 128539a53e0cSJaegeuk Kim 128639a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 128739a53e0cSJaegeuk Kim { 128861e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 128939a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 129039a53e0cSJaegeuk Kim } 129139a53e0cSJaegeuk Kim 129239a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 129339a53e0cSJaegeuk Kim { 129439a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 129539a53e0cSJaegeuk Kim } 129639a53e0cSJaegeuk Kim 129739a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 129839a53e0cSJaegeuk Kim { 129961e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 130039a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 130139a53e0cSJaegeuk Kim } 130239a53e0cSJaegeuk Kim 130339a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 130439a53e0cSJaegeuk Kim { 130539a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 130639a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 130739a53e0cSJaegeuk Kim } 130839a53e0cSJaegeuk Kim 1309444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1310444c580fSJaegeuk Kim struct f2fs_inode *ri) 1311444c580fSJaegeuk Kim { 1312444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1313444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 13141001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 13151001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 131634d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 131734d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1318b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1319b3d208f9SJaegeuk Kim set_inode_flag(fi, FI_DATA_EXIST); 1320510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1321510022a8SJaegeuk Kim set_inode_flag(fi, FI_INLINE_DOTS); 1322444c580fSJaegeuk Kim } 1323444c580fSJaegeuk Kim 1324444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1325444c580fSJaegeuk Kim struct f2fs_inode *ri) 1326444c580fSJaegeuk Kim { 1327444c580fSJaegeuk Kim ri->i_inline = 0; 1328444c580fSJaegeuk Kim 1329444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1330444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 13311001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 13321001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 133334d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 133434d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1335b3d208f9SJaegeuk Kim if (is_inode_flag_set(fi, FI_DATA_EXIST)) 1336b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1337510022a8SJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_DOTS)) 1338510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1339444c580fSJaegeuk Kim } 1340444c580fSJaegeuk Kim 1341987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1342987c7c31SChao Yu { 1343987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1344987c7c31SChao Yu } 1345987c7c31SChao Yu 1346de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1347de93653fSJaegeuk Kim { 1348987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1349de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1350de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1351de93653fSJaegeuk Kim } 1352de93653fSJaegeuk Kim 135365985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 135465985d93SJaegeuk Kim { 1355695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 135665985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 135765985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 135865985d93SJaegeuk Kim } 135965985d93SJaegeuk Kim 136065985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 136165985d93SJaegeuk Kim { 1362987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 136365985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 136465985d93SJaegeuk Kim else 136565985d93SJaegeuk Kim return 0; 136665985d93SJaegeuk Kim } 136765985d93SJaegeuk Kim 13680dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 13690dbdc2aeSJaegeuk Kim { 13700dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 13710dbdc2aeSJaegeuk Kim } 13720dbdc2aeSJaegeuk Kim 1373b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1374b3d208f9SJaegeuk Kim { 1375b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 1376b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1377b3d208f9SJaegeuk Kim } 1378b3d208f9SJaegeuk Kim 1379b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1380b3d208f9SJaegeuk Kim { 1381b3d208f9SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST); 1382b3d208f9SJaegeuk Kim } 1383b3d208f9SJaegeuk Kim 1384510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1385510022a8SJaegeuk Kim { 1386510022a8SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS); 1387510022a8SJaegeuk Kim } 1388510022a8SJaegeuk Kim 138988b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 139088b88a66SJaegeuk Kim { 139188b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 139288b88a66SJaegeuk Kim } 139388b88a66SJaegeuk Kim 139402a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 139502a1335fSJaegeuk Kim { 139602a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 139702a1335fSJaegeuk Kim } 139802a1335fSJaegeuk Kim 13993c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 14003c6c2bebSJaegeuk Kim { 14013c6c2bebSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); 14023c6c2bebSJaegeuk Kim } 14033c6c2bebSJaegeuk Kim 14041e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 14051e84371fSJaegeuk Kim { 14061e84371fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE); 14071e84371fSJaegeuk Kim } 14081e84371fSJaegeuk Kim 14091001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 14101001b347SHuajun Li { 1411695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 14121001b347SHuajun Li return (void *)&(ri->i_addr[1]); 14131001b347SHuajun Li } 14141001b347SHuajun Li 141534d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 141634d67debSChao Yu { 141734d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 141834d67debSChao Yu } 141934d67debSChao Yu 14209486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 14219486ba44SJaegeuk Kim { 14229486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 14239486ba44SJaegeuk Kim kunmap(page); 14249486ba44SJaegeuk Kim } 14259486ba44SJaegeuk Kim 1426b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1427b5492af7SJaegeuk Kim { 1428b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1429b5492af7SJaegeuk Kim } 1430b5492af7SJaegeuk Kim 1431b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1432b5492af7SJaegeuk Kim { 1433b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1434b5492af7SJaegeuk Kim } 1435b5492af7SJaegeuk Kim 1436b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1437b5492af7SJaegeuk Kim { 1438b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1439b5492af7SJaegeuk Kim } 1440b5492af7SJaegeuk Kim 144177888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 144277888c1eSJaegeuk Kim { 144377888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 144477888c1eSJaegeuk Kim } 144577888c1eSJaegeuk Kim 14461e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 14471e968fdfSJaegeuk Kim { 14481e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 14491e968fdfSJaegeuk Kim } 14501e968fdfSJaegeuk Kim 1451744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1452744602cfSJaegeuk Kim { 1453744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1454744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1455744602cfSJaegeuk Kim } 1456744602cfSJaegeuk Kim 1457a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1458a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1459a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1460a6dda0e6SChristoph Hellwig 1461267378d4SChao Yu /* get offset of first page in next direct node */ 1462267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1463267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1464267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1465267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1466267378d4SChao Yu 146739a53e0cSJaegeuk Kim /* 146839a53e0cSJaegeuk Kim * file.c 146939a53e0cSJaegeuk Kim */ 147039a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 147139a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1472764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 147339a53e0cSJaegeuk Kim void f2fs_truncate(struct inode *); 14742d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 147539a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 147639a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1477b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 147839a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1479e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 148039a53e0cSJaegeuk Kim 148139a53e0cSJaegeuk Kim /* 148239a53e0cSJaegeuk Kim * inode.c 148339a53e0cSJaegeuk Kim */ 148439a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 148539a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 14864660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 148739a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *); 1488744602cfSJaegeuk Kim void update_inode_page(struct inode *); 148939a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 149039a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 149144c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 149239a53e0cSJaegeuk Kim 149339a53e0cSJaegeuk Kim /* 149439a53e0cSJaegeuk Kim * namei.c 149539a53e0cSJaegeuk Kim */ 149639a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 149739a53e0cSJaegeuk Kim 149839a53e0cSJaegeuk Kim /* 149939a53e0cSJaegeuk Kim * dir.c 150039a53e0cSJaegeuk Kim */ 1501dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1502510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 15037b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct qstr *, int *, 15047b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr *); 15057b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 15067b3cd7d6SJaegeuk Kim unsigned int); 1507062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1508062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1509dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1510bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1511dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1512a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1513dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 151439a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 151539a53e0cSJaegeuk Kim struct page **); 151639a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 151739a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 151839a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 151939a53e0cSJaegeuk Kim struct page *, struct inode *); 15201cd14cafSJaegeuk Kim int update_dent_inode(struct inode *, const struct qstr *); 1521510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 15223b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1523510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1524510022a8SJaegeuk Kim umode_t); 1525dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1526dbeacf02SChao Yu struct inode *); 1527b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 152839a53e0cSJaegeuk Kim int f2fs_make_empty(struct inode *, struct inode *); 152939a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 153039a53e0cSJaegeuk Kim 1531b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1532b7f7a5e0SAl Viro { 15332b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1534510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1535b7f7a5e0SAl Viro } 1536b7f7a5e0SAl Viro 153739a53e0cSJaegeuk Kim /* 153839a53e0cSJaegeuk Kim * super.c 153939a53e0cSJaegeuk Kim */ 154026d815adSJaegeuk Kim int f2fs_commit_super(struct f2fs_sb_info *); 154139a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1542a07ef784SNamjae Jeon extern __printf(3, 4) 1543a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 154439a53e0cSJaegeuk Kim 154539a53e0cSJaegeuk Kim /* 154639a53e0cSJaegeuk Kim * hash.c 154739a53e0cSJaegeuk Kim */ 1548eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 154939a53e0cSJaegeuk Kim 155039a53e0cSJaegeuk Kim /* 155139a53e0cSJaegeuk Kim * node.c 155239a53e0cSJaegeuk Kim */ 155339a53e0cSJaegeuk Kim struct dnode_of_data; 155439a53e0cSJaegeuk Kim struct node_info; 155539a53e0cSJaegeuk Kim 15566fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 155788bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 155888bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 155939a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 156039a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 156139a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 15624f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1563cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 156458e674d6SGu Zheng void remove_inode_page(struct inode *); 1565a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 15668ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 156739a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 156839a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 156939a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 157039a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 157139a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 157239a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 157339a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 157439a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 157570cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 15761c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 157739a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 157839a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 157939a53e0cSJaegeuk Kim struct f2fs_summary_block *); 158039a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 158139a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 158239a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 15836e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 158439a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 158539a53e0cSJaegeuk Kim 158639a53e0cSJaegeuk Kim /* 158739a53e0cSJaegeuk Kim * segment.c 158839a53e0cSJaegeuk Kim */ 158988b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 159088b88a66SJaegeuk Kim void commit_inmem_pages(struct inode *, bool); 159139a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *); 15924660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 15936b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 15942163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 15952163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 159639a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 15975e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 159839a53e0cSJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *); 15994b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1600cf2271e7SJaegeuk Kim void discard_next_dnode(struct f2fs_sb_info *, block_t); 16013fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 160239a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 16034b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 160439a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1605577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 1606*05ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 1607*05ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 1608*05ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 160939a53e0cSJaegeuk Kim void recover_data_page(struct f2fs_sb_info *, struct page *, 161039a53e0cSJaegeuk Kim struct f2fs_summary *, block_t, block_t); 1611bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1612bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 16135514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 161439a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 161539a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 161639a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 161739a53e0cSJaegeuk Kim int, unsigned int, int); 16184b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 161939a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 162039a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 16217fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 16227fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 162339a53e0cSJaegeuk Kim 162439a53e0cSJaegeuk Kim /* 162539a53e0cSJaegeuk Kim * checkpoint.c 162639a53e0cSJaegeuk Kim */ 162739a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 162839a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 1629f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 16304c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int); 1631635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 163239a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1633fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1634fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 16356f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *); 1636fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1637cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1638cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 163939a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 164039a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 16418f99a946SChao Yu void recover_orphan_inodes(struct f2fs_sb_info *); 164239a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1643a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 16445deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 164539a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *); 164639a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *); 164775ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 16486451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 16496e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 165039a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 165139a53e0cSJaegeuk Kim 165239a53e0cSJaegeuk Kim /* 165339a53e0cSJaegeuk Kim * data.c 165439a53e0cSJaegeuk Kim */ 1655458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 1656*05ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 1657*05ca3632SJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_io_info *); 1658216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 165939a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1660b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 1661429511cdSChao Yu void f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 1662429511cdSChao Yu void f2fs_destroy_extent_tree(struct inode *); 1663028a41e8SChao Yu void f2fs_init_extent_cache(struct inode *, struct f2fs_extent *); 16647e4dde79SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 16650bdee482SChao Yu void f2fs_preserve_extent_tree(struct inode *); 1666c718379bSJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t, bool); 166739a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t); 166864aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 1669*05ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 16709ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1671429511cdSChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 1672429511cdSChao Yu int __init create_extent_cache(void); 1673429511cdSChao Yu void destroy_extent_cache(void); 1674487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1675487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 167639a53e0cSJaegeuk Kim 167739a53e0cSJaegeuk Kim /* 167839a53e0cSJaegeuk Kim * gc.c 167939a53e0cSJaegeuk Kim */ 168039a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 168139a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1682de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1683408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *); 168439a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 168539a53e0cSJaegeuk Kim 168639a53e0cSJaegeuk Kim /* 168739a53e0cSJaegeuk Kim * recovery.c 168839a53e0cSJaegeuk Kim */ 16896ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 169039a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 169139a53e0cSJaegeuk Kim 169239a53e0cSJaegeuk Kim /* 169339a53e0cSJaegeuk Kim * debug.c 169439a53e0cSJaegeuk Kim */ 169539a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 169639a53e0cSJaegeuk Kim struct f2fs_stat_info { 169739a53e0cSJaegeuk Kim struct list_head stat_list; 169839a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 169939a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 170039a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 17014bf6fd9fSChao Yu int hit_ext, total_ext, ext_tree, ext_node; 170239a53e0cSJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 1703dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 170439a53e0cSJaegeuk Kim int total_count, utilization; 1705d24bdcbfSJaegeuk Kim int bg_gc, inline_inode, inline_dir, inmem_pages, wb_pages; 170639a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 170739a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 170839a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 170939a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 171039a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1711942e0be6SChangman Lee int prefree_count, call_count, cp_count; 171239a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 1713e1235983SChangman Lee int bg_node_segs, bg_data_segs; 171439a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 1715e1235983SChangman Lee int bg_data_blks, bg_node_blks; 171639a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 171739a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 171839a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 171939a53e0cSJaegeuk Kim 172039a53e0cSJaegeuk Kim unsigned int segment_count[2]; 172139a53e0cSJaegeuk Kim unsigned int block_count[2]; 1722b9a2c252SChangman Lee unsigned int inplace_count; 17236f0aacbcSJaegeuk Kim unsigned base_mem, cache_mem, page_mem; 172439a53e0cSJaegeuk Kim }; 172539a53e0cSJaegeuk Kim 1726963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1727963d4f7dSGu Zheng { 1728963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1729963d4f7dSGu Zheng } 1730963d4f7dSGu Zheng 1731942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 173239a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1733dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1734dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1735dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 1736dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++) 1737dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++) 17380dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 17390dbdc2aeSJaegeuk Kim do { \ 17400dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 174103e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 17420dbdc2aeSJaegeuk Kim } while (0) 17430dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 17440dbdc2aeSJaegeuk Kim do { \ 17450dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 174603e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 17470dbdc2aeSJaegeuk Kim } while (0) 17483289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 17493289c061SJaegeuk Kim do { \ 17503289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 175103e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 17523289c061SJaegeuk Kim } while (0) 17533289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 17543289c061SJaegeuk Kim do { \ 17553289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 175603e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 17573289c061SJaegeuk Kim } while (0) 1758dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1759dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1760dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1761dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 1762b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 1763b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 1764e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 176539a53e0cSJaegeuk Kim do { \ 1766963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 176739a53e0cSJaegeuk Kim (si)->tot_segs++; \ 1768e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 176939a53e0cSJaegeuk Kim si->data_segs++; \ 1770e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 1771e1235983SChangman Lee } else { \ 177239a53e0cSJaegeuk Kim si->node_segs++; \ 1773e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 1774e1235983SChangman Lee } \ 177539a53e0cSJaegeuk Kim } while (0) 177639a53e0cSJaegeuk Kim 177739a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 177839a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 177939a53e0cSJaegeuk Kim 1780e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 178139a53e0cSJaegeuk Kim do { \ 1782963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 178339a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 178439a53e0cSJaegeuk Kim si->data_blks += (blks); \ 1785e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 178639a53e0cSJaegeuk Kim } while (0) 178739a53e0cSJaegeuk Kim 1788e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 178939a53e0cSJaegeuk Kim do { \ 1790963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 179139a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 179239a53e0cSJaegeuk Kim si->node_blks += (blks); \ 1793e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 179439a53e0cSJaegeuk Kim } while (0) 179539a53e0cSJaegeuk Kim 179639a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 179739a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 17986e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void); 17994589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 180039a53e0cSJaegeuk Kim #else 1801942e0be6SChangman Lee #define stat_inc_cp_count(si) 180239a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 1803dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 1804dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) 1805dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) 1806dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 1807dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) 18080dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 18090dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 18103289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 18113289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 1812dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 1813dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 1814b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 1815e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 181639a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 1817e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 1818e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 181939a53e0cSJaegeuk Kim 182039a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 182139a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 18226e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { } 18234589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 182439a53e0cSJaegeuk Kim #endif 182539a53e0cSJaegeuk Kim 182639a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 182739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 182839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 182939a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 183039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 183139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 183239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 183339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 183439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 183529e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 18361001b347SHuajun Li 1837e18c65b2SHuajun Li /* 1838e18c65b2SHuajun Li * inline.c 1839e18c65b2SHuajun Li */ 184001b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 184101b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 1842b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 18430bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 1844e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 1845b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 1846b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 1847b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 18480342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 1849201a05beSChao Yu struct f2fs_dir_entry *find_in_inline_dir(struct inode *, struct qstr *, 1850201a05beSChao Yu struct page **); 1851201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 1852201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 1853510022a8SJaegeuk Kim int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 1854510022a8SJaegeuk Kim nid_t, umode_t); 1855201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 1856201a05beSChao Yu struct inode *, struct inode *); 1857201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 1858201a05beSChao Yu int f2fs_read_inline_dir(struct file *, struct dir_context *); 185939a53e0cSJaegeuk Kim #endif 1860