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 /* 325*003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 326*003a3e1dSJaegeuk Kim * 327*003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 328*003a3e1dSJaegeuk Kim */ 329*003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 330*003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 331*003a3e1dSJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED) 332*003a3e1dSJaegeuk Kim 333*003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 334*003a3e1dSJaegeuk Kim block_t m_pblk; 335*003a3e1dSJaegeuk Kim block_t m_lblk; 336*003a3e1dSJaegeuk Kim unsigned int m_len; 337*003a3e1dSJaegeuk Kim unsigned int m_flags; 338*003a3e1dSJaegeuk Kim }; 339*003a3e1dSJaegeuk Kim 340*003a3e1dSJaegeuk 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 { 604458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 6057e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 606cf04e8ebSJaegeuk Kim block_t blk_addr; /* block address to be written */ 607458e6197SJaegeuk Kim }; 608458e6197SJaegeuk Kim 60993dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 6101ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 611458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 6121ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 6131ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 614458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 615df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 6161ff7bd3bSJaegeuk Kim }; 6171ff7bd3bSJaegeuk Kim 61867298804SChao Yu /* for inner inode cache management */ 61967298804SChao Yu struct inode_management { 62067298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 62167298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 62267298804SChao Yu struct list_head ino_list; /* inode list head */ 62367298804SChao Yu unsigned long ino_num; /* number of entries */ 62467298804SChao Yu }; 62567298804SChao Yu 626caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 627caf0047eSChao Yu enum { 628caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 629caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 630caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 631caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 632caf0047eSChao Yu }; 633caf0047eSChao Yu 63439a53e0cSJaegeuk Kim struct f2fs_sb_info { 63539a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 6365e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 63739a53e0cSJaegeuk Kim struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 63839a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 639caf0047eSChao Yu int s_flag; /* flags for sbi */ 64039a53e0cSJaegeuk Kim 64139a53e0cSJaegeuk Kim /* for node-related operations */ 64239a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 64339a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 64439a53e0cSJaegeuk Kim 64539a53e0cSJaegeuk Kim /* for segment-related operations */ 64639a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 6471ff7bd3bSJaegeuk Kim 6481ff7bd3bSJaegeuk Kim /* for bio operations */ 649924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 6501ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 65139a53e0cSJaegeuk Kim 65239a53e0cSJaegeuk Kim /* for checkpoint */ 65339a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 65439a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 65539936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 656e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 657b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 6585463e7c1SJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 659fb51b5efSChangman Lee wait_queue_head_t cp_wait; 66039a53e0cSJaegeuk Kim 66167298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 6626451e041SJaegeuk Kim 6636451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 6640d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 66539a53e0cSJaegeuk Kim 66639a53e0cSJaegeuk Kim /* for directory inode management */ 66739a53e0cSJaegeuk Kim struct list_head dir_inode_list; /* dir inode list */ 66839a53e0cSJaegeuk Kim spinlock_t dir_inode_lock; /* for dir inode list lock */ 66939a53e0cSJaegeuk Kim 67013054c54SChao Yu /* for extent tree cache */ 67113054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 67213054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 67313054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 67413054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 67513054c54SChao Yu int total_ext_tree; /* extent tree count */ 67613054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 67713054c54SChao Yu 67839a53e0cSJaegeuk Kim /* basic filesystem units */ 67939a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 68039a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 68139a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 68239a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 68339a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 68439a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 68539a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 68639a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 68739a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 68839a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 68939a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 69039a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 69139a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 69239a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 69339a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 694ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 69539a53e0cSJaegeuk Kim 69639a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 69739a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 69839a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 69939a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 70039a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 70139a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 70239a53e0cSJaegeuk Kim 70339a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 70439a53e0cSJaegeuk Kim 70539a53e0cSJaegeuk Kim /* for cleaning operations */ 70639a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 70739a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 7085ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 70939a53e0cSJaegeuk Kim 710b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 711b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 712b1c57c1cSJaegeuk Kim 71339a53e0cSJaegeuk Kim /* 71439a53e0cSJaegeuk Kim * for stat information. 71539a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 71639a53e0cSJaegeuk Kim */ 71735b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 71839a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 71939a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 72039a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 721b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 72239a53e0cSJaegeuk Kim int total_hit_ext, read_hit_ext; /* extent cache hit ratio */ 72303e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 72403e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 72539a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 72635b09d82SNamjae Jeon unsigned int n_dirty_dirs; /* # of dir inodes */ 72735b09d82SNamjae Jeon #endif 72835b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 72939a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 730b59d0baeSNamjae Jeon 731b59d0baeSNamjae Jeon /* For sysfs suppport */ 732b59d0baeSNamjae Jeon struct kobject s_kobj; 733b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 73439a53e0cSJaegeuk Kim }; 73539a53e0cSJaegeuk Kim 73639a53e0cSJaegeuk Kim /* 73739a53e0cSJaegeuk Kim * Inline functions 73839a53e0cSJaegeuk Kim */ 73939a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 74039a53e0cSJaegeuk Kim { 74139a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 74239a53e0cSJaegeuk Kim } 74339a53e0cSJaegeuk Kim 74439a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 74539a53e0cSJaegeuk Kim { 74639a53e0cSJaegeuk Kim return sb->s_fs_info; 74739a53e0cSJaegeuk Kim } 74839a53e0cSJaegeuk Kim 7494081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 7504081363fSJaegeuk Kim { 7514081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 7524081363fSJaegeuk Kim } 7534081363fSJaegeuk Kim 7544081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 7554081363fSJaegeuk Kim { 7564081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 7574081363fSJaegeuk Kim } 7584081363fSJaegeuk Kim 7594081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 7604081363fSJaegeuk Kim { 7614081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 7624081363fSJaegeuk Kim } 7634081363fSJaegeuk Kim 76439a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 76539a53e0cSJaegeuk Kim { 76639a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 76739a53e0cSJaegeuk Kim } 76839a53e0cSJaegeuk Kim 76939a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 77039a53e0cSJaegeuk Kim { 77139a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 77239a53e0cSJaegeuk Kim } 77339a53e0cSJaegeuk Kim 77445590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 77545590710SGu Zheng { 77645590710SGu Zheng return (struct f2fs_node *)page_address(page); 77745590710SGu Zheng } 77845590710SGu Zheng 77958bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 78058bfaf44SJaegeuk Kim { 78158bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 78258bfaf44SJaegeuk Kim } 78358bfaf44SJaegeuk Kim 78439a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 78539a53e0cSJaegeuk Kim { 78639a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 78739a53e0cSJaegeuk Kim } 78839a53e0cSJaegeuk Kim 78939a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 79039a53e0cSJaegeuk Kim { 79139a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 79239a53e0cSJaegeuk Kim } 79339a53e0cSJaegeuk Kim 79439a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 79539a53e0cSJaegeuk Kim { 79639a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 79739a53e0cSJaegeuk Kim } 79839a53e0cSJaegeuk Kim 79939a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 80039a53e0cSJaegeuk Kim { 80139a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 80239a53e0cSJaegeuk Kim } 80339a53e0cSJaegeuk Kim 80439a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 80539a53e0cSJaegeuk Kim { 80639a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 80739a53e0cSJaegeuk Kim } 80839a53e0cSJaegeuk Kim 8099df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 8109df27d98SGu Zheng { 8119df27d98SGu Zheng return sbi->meta_inode->i_mapping; 8129df27d98SGu Zheng } 8139df27d98SGu Zheng 8144ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 8154ef51a8fSJaegeuk Kim { 8164ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 8174ef51a8fSJaegeuk Kim } 8184ef51a8fSJaegeuk Kim 819caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 82039a53e0cSJaegeuk Kim { 821caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 82239a53e0cSJaegeuk Kim } 82339a53e0cSJaegeuk Kim 824caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 82539a53e0cSJaegeuk Kim { 826caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 827caf0047eSChao Yu } 828caf0047eSChao Yu 829caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 830caf0047eSChao Yu { 831caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 83239a53e0cSJaegeuk Kim } 83339a53e0cSJaegeuk Kim 834d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 835d71b5564SJaegeuk Kim { 836d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 837d71b5564SJaegeuk Kim } 838d71b5564SJaegeuk Kim 83925ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 84025ca923bSJaegeuk Kim { 84125ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 84225ca923bSJaegeuk Kim return ckpt_flags & f; 84325ca923bSJaegeuk Kim } 84425ca923bSJaegeuk Kim 84525ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 84625ca923bSJaegeuk Kim { 84725ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 84825ca923bSJaegeuk Kim ckpt_flags |= f; 84925ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 85025ca923bSJaegeuk Kim } 85125ca923bSJaegeuk Kim 85225ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 85325ca923bSJaegeuk Kim { 85425ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 85525ca923bSJaegeuk Kim ckpt_flags &= (~f); 85625ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 85725ca923bSJaegeuk Kim } 85825ca923bSJaegeuk Kim 859e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 86039a53e0cSJaegeuk Kim { 861e479556bSGu Zheng down_read(&sbi->cp_rwsem); 86239a53e0cSJaegeuk Kim } 86339a53e0cSJaegeuk Kim 864e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 86539a53e0cSJaegeuk Kim { 866e479556bSGu Zheng up_read(&sbi->cp_rwsem); 86739936837SJaegeuk Kim } 86839936837SJaegeuk Kim 869e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 87039936837SJaegeuk Kim { 8710daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 87239936837SJaegeuk Kim } 87339936837SJaegeuk Kim 874e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 87539936837SJaegeuk Kim { 876e479556bSGu Zheng up_write(&sbi->cp_rwsem); 87739a53e0cSJaegeuk Kim } 87839a53e0cSJaegeuk Kim 879119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 880119ee914SJaegeuk Kim { 881119ee914SJaegeuk Kim int reason = CP_SYNC; 882119ee914SJaegeuk Kim 883119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 884119ee914SJaegeuk Kim reason = CP_FASTBOOT; 885119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 886119ee914SJaegeuk Kim reason = CP_UMOUNT; 887119ee914SJaegeuk Kim return reason; 888119ee914SJaegeuk Kim } 889119ee914SJaegeuk Kim 890119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 891119ee914SJaegeuk Kim { 892119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 893119ee914SJaegeuk Kim } 894119ee914SJaegeuk Kim 895119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 896119ee914SJaegeuk Kim { 897119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 898119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 899119ee914SJaegeuk Kim } 900119ee914SJaegeuk Kim 90139a53e0cSJaegeuk Kim /* 90239a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 90339a53e0cSJaegeuk Kim */ 904064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 90539a53e0cSJaegeuk Kim { 906d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 907d6b7d4b3SChao Yu return -EINVAL; 908cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 909064e0823SNamjae Jeon return -EINVAL; 910064e0823SNamjae Jeon return 0; 91139a53e0cSJaegeuk Kim } 91239a53e0cSJaegeuk Kim 91339a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 91439a53e0cSJaegeuk Kim 91539a53e0cSJaegeuk Kim /* 91639a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 91739a53e0cSJaegeuk Kim */ 91839a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 91939a53e0cSJaegeuk Kim { 92039a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 9216c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 92239a53e0cSJaegeuk Kim else 9236c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 92439a53e0cSJaegeuk Kim } 92539a53e0cSJaegeuk Kim 9264bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 9274bc8e9bcSChao Yu { 9284bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 9294bc8e9bcSChao Yu } 9304bc8e9bcSChao Yu 93139a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 93239a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 93339a53e0cSJaegeuk Kim { 93439a53e0cSJaegeuk Kim block_t valid_block_count; 93539a53e0cSJaegeuk Kim 93639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 93739a53e0cSJaegeuk Kim valid_block_count = 93839a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 939cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 94039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 94139a53e0cSJaegeuk Kim return false; 94239a53e0cSJaegeuk Kim } 94339a53e0cSJaegeuk Kim inode->i_blocks += count; 94439a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 94539a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 94639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 94739a53e0cSJaegeuk Kim return true; 94839a53e0cSJaegeuk Kim } 94939a53e0cSJaegeuk Kim 950da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 95139a53e0cSJaegeuk Kim struct inode *inode, 95239a53e0cSJaegeuk Kim blkcnt_t count) 95339a53e0cSJaegeuk Kim { 95439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 9559850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 9569850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 95739a53e0cSJaegeuk Kim inode->i_blocks -= count; 95839a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 95939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 96039a53e0cSJaegeuk Kim } 96139a53e0cSJaegeuk Kim 96239a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 96339a53e0cSJaegeuk Kim { 96439a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 965caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 96639a53e0cSJaegeuk Kim } 96739a53e0cSJaegeuk Kim 968a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 96939a53e0cSJaegeuk Kim { 970a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 971a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 9724081363fSJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 97339a53e0cSJaegeuk Kim } 97439a53e0cSJaegeuk Kim 97539a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 97639a53e0cSJaegeuk Kim { 97739a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 97839a53e0cSJaegeuk Kim } 97939a53e0cSJaegeuk Kim 980a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 98139a53e0cSJaegeuk Kim { 982a7ffdbe2SJaegeuk Kim if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)) 9831fe54f9dSJaegeuk Kim return; 9841fe54f9dSJaegeuk Kim 985a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 986a7ffdbe2SJaegeuk Kim 987a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 9884081363fSJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 98939a53e0cSJaegeuk Kim } 99039a53e0cSJaegeuk Kim 99139a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 99239a53e0cSJaegeuk Kim { 99339a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 99439a53e0cSJaegeuk Kim } 99539a53e0cSJaegeuk Kim 996a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 997f8b2c1f9SJaegeuk Kim { 998a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 999f8b2c1f9SJaegeuk Kim } 1000f8b2c1f9SJaegeuk Kim 10015ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 10025ac206cfSNamjae Jeon { 10035ac206cfSNamjae Jeon unsigned int pages_per_sec = sbi->segs_per_sec * 10045ac206cfSNamjae Jeon (1 << sbi->log_blocks_per_seg); 10055ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 10065ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 10075ac206cfSNamjae Jeon } 10085ac206cfSNamjae Jeon 100939a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 101039a53e0cSJaegeuk Kim { 10118b8343faSJaegeuk Kim return sbi->total_valid_block_count; 101239a53e0cSJaegeuk Kim } 101339a53e0cSJaegeuk Kim 101439a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 101539a53e0cSJaegeuk Kim { 101639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 101739a53e0cSJaegeuk Kim 101839a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 101939a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 102039a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 102139a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 102239a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 102339a53e0cSJaegeuk Kim 102439a53e0cSJaegeuk Kim return 0; 102539a53e0cSJaegeuk Kim } 102639a53e0cSJaegeuk Kim 102755141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 102855141486SWanpeng Li { 102955141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 103055141486SWanpeng Li } 103155141486SWanpeng Li 103239a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 103339a53e0cSJaegeuk Kim { 103439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 10351dbe4152SChangman Lee int offset; 10361dbe4152SChangman Lee 103755141486SWanpeng Li if (__cp_payload(sbi) > 0) { 10381dbe4152SChangman Lee if (flag == NAT_BITMAP) 10391dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 10401dbe4152SChangman Lee else 104165b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 10421dbe4152SChangman Lee } else { 10431dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 104425ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 104539a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 104639a53e0cSJaegeuk Kim } 10471dbe4152SChangman Lee } 104839a53e0cSJaegeuk Kim 104939a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 105039a53e0cSJaegeuk Kim { 105139a53e0cSJaegeuk Kim block_t start_addr; 105239a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1053d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 105439a53e0cSJaegeuk Kim 105525ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 105639a53e0cSJaegeuk Kim 105739a53e0cSJaegeuk Kim /* 105839a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1059e1c42045Sarter97 * and even segment must be at cp segment 1 106039a53e0cSJaegeuk Kim */ 106139a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 106239a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 106339a53e0cSJaegeuk Kim 106439a53e0cSJaegeuk Kim return start_addr; 106539a53e0cSJaegeuk Kim } 106639a53e0cSJaegeuk Kim 106739a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 106839a53e0cSJaegeuk Kim { 106939a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 107039a53e0cSJaegeuk Kim } 107139a53e0cSJaegeuk Kim 107239a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1073ef86d709SGu Zheng struct inode *inode) 107439a53e0cSJaegeuk Kim { 107539a53e0cSJaegeuk Kim block_t valid_block_count; 107639a53e0cSJaegeuk Kim unsigned int valid_node_count; 107739a53e0cSJaegeuk Kim 107839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 107939a53e0cSJaegeuk Kim 1080ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1081cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 108239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 108339a53e0cSJaegeuk Kim return false; 108439a53e0cSJaegeuk Kim } 108539a53e0cSJaegeuk Kim 1086ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1087cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 108839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 108939a53e0cSJaegeuk Kim return false; 109039a53e0cSJaegeuk Kim } 109139a53e0cSJaegeuk Kim 109239a53e0cSJaegeuk Kim if (inode) 1093ef86d709SGu Zheng inode->i_blocks++; 1094ef86d709SGu Zheng 1095ef86d709SGu Zheng sbi->alloc_valid_block_count++; 1096ef86d709SGu Zheng sbi->total_valid_node_count++; 1097ef86d709SGu Zheng sbi->total_valid_block_count++; 109839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 109939a53e0cSJaegeuk Kim 110039a53e0cSJaegeuk Kim return true; 110139a53e0cSJaegeuk Kim } 110239a53e0cSJaegeuk Kim 110339a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1104ef86d709SGu Zheng struct inode *inode) 110539a53e0cSJaegeuk Kim { 110639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 110739a53e0cSJaegeuk Kim 11089850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 11099850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 11109850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 111139a53e0cSJaegeuk Kim 1112ef86d709SGu Zheng inode->i_blocks--; 1113ef86d709SGu Zheng sbi->total_valid_node_count--; 1114ef86d709SGu Zheng sbi->total_valid_block_count--; 111539a53e0cSJaegeuk Kim 111639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 111739a53e0cSJaegeuk Kim } 111839a53e0cSJaegeuk Kim 111939a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 112039a53e0cSJaegeuk Kim { 11218b8343faSJaegeuk Kim return sbi->total_valid_node_count; 112239a53e0cSJaegeuk Kim } 112339a53e0cSJaegeuk Kim 112439a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 112539a53e0cSJaegeuk Kim { 112639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 11279850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 112839a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 112939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 113039a53e0cSJaegeuk Kim } 113139a53e0cSJaegeuk Kim 11320e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 113339a53e0cSJaegeuk Kim { 113439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 11359850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 113639a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 113739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 113839a53e0cSJaegeuk Kim } 113939a53e0cSJaegeuk Kim 114039a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 114139a53e0cSJaegeuk Kim { 11428b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 114339a53e0cSJaegeuk Kim } 114439a53e0cSJaegeuk Kim 114539a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 114639a53e0cSJaegeuk Kim { 1147031fa8ccSJaegeuk Kim if (!page) 114839a53e0cSJaegeuk Kim return; 114939a53e0cSJaegeuk Kim 115039a53e0cSJaegeuk Kim if (unlock) { 11519850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 115239a53e0cSJaegeuk Kim unlock_page(page); 115339a53e0cSJaegeuk Kim } 115439a53e0cSJaegeuk Kim page_cache_release(page); 115539a53e0cSJaegeuk Kim } 115639a53e0cSJaegeuk Kim 115739a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 115839a53e0cSJaegeuk Kim { 115939a53e0cSJaegeuk Kim if (dn->node_page) 116039a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 116139a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 116239a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 116339a53e0cSJaegeuk Kim dn->node_page = NULL; 116439a53e0cSJaegeuk Kim dn->inode_page = NULL; 116539a53e0cSJaegeuk Kim } 116639a53e0cSJaegeuk Kim 116739a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1168e8512d2eSGu Zheng size_t size) 116939a53e0cSJaegeuk Kim { 1170e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 117139a53e0cSJaegeuk Kim } 117239a53e0cSJaegeuk Kim 11737bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 11747bd59381SGu Zheng gfp_t flags) 11757bd59381SGu Zheng { 11767bd59381SGu Zheng void *entry; 11777bd59381SGu Zheng retry: 11787bd59381SGu Zheng entry = kmem_cache_alloc(cachep, flags); 11797bd59381SGu Zheng if (!entry) { 11807bd59381SGu Zheng cond_resched(); 11817bd59381SGu Zheng goto retry; 11827bd59381SGu Zheng } 11837bd59381SGu Zheng 11847bd59381SGu Zheng return entry; 11857bd59381SGu Zheng } 11867bd59381SGu Zheng 11879be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 11889be32d72SJaegeuk Kim unsigned long index, void *item) 11899be32d72SJaegeuk Kim { 11909be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 11919be32d72SJaegeuk Kim cond_resched(); 11929be32d72SJaegeuk Kim } 11939be32d72SJaegeuk Kim 119439a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 119539a53e0cSJaegeuk Kim 119639a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 119739a53e0cSJaegeuk Kim { 119845590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 119939a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 120039a53e0cSJaegeuk Kim } 120139a53e0cSJaegeuk Kim 120239a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 120339a53e0cSJaegeuk Kim { 120439a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 120539a53e0cSJaegeuk Kim } 120639a53e0cSJaegeuk Kim 120739a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 120839a53e0cSJaegeuk Kim unsigned int offset) 120939a53e0cSJaegeuk Kim { 121039a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 121139a53e0cSJaegeuk Kim __le32 *addr_array; 121245590710SGu Zheng raw_node = F2FS_NODE(node_page); 121339a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 121439a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 121539a53e0cSJaegeuk Kim } 121639a53e0cSJaegeuk Kim 121739a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 121839a53e0cSJaegeuk Kim { 121939a53e0cSJaegeuk Kim int mask; 122039a53e0cSJaegeuk Kim 122139a53e0cSJaegeuk Kim addr += (nr >> 3); 122239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 122339a53e0cSJaegeuk Kim return mask & *addr; 122439a53e0cSJaegeuk Kim } 122539a53e0cSJaegeuk Kim 122652aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 122739a53e0cSJaegeuk Kim { 122839a53e0cSJaegeuk Kim int mask; 122939a53e0cSJaegeuk Kim int ret; 123039a53e0cSJaegeuk Kim 123139a53e0cSJaegeuk Kim addr += (nr >> 3); 123239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 123339a53e0cSJaegeuk Kim ret = mask & *addr; 123439a53e0cSJaegeuk Kim *addr |= mask; 123539a53e0cSJaegeuk Kim return ret; 123639a53e0cSJaegeuk Kim } 123739a53e0cSJaegeuk Kim 123852aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 123939a53e0cSJaegeuk Kim { 124039a53e0cSJaegeuk Kim int mask; 124139a53e0cSJaegeuk Kim int ret; 124239a53e0cSJaegeuk Kim 124339a53e0cSJaegeuk Kim addr += (nr >> 3); 124439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 124539a53e0cSJaegeuk Kim ret = mask & *addr; 124639a53e0cSJaegeuk Kim *addr &= ~mask; 124739a53e0cSJaegeuk Kim return ret; 124839a53e0cSJaegeuk Kim } 124939a53e0cSJaegeuk Kim 1250c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1251c6ac4c0eSGu Zheng { 1252c6ac4c0eSGu Zheng int mask; 1253c6ac4c0eSGu Zheng 1254c6ac4c0eSGu Zheng addr += (nr >> 3); 1255c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1256c6ac4c0eSGu Zheng *addr ^= mask; 1257c6ac4c0eSGu Zheng } 1258c6ac4c0eSGu Zheng 125939a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 126039a53e0cSJaegeuk Kim enum { 126139a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1262b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1263ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 126439a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 126539a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 126639a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1267699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 126874d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1269c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1270444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 12711001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 127234d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1273fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1274fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 127588b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 127688b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 127702a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 12783c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 12791e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1280b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1281510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 128239a53e0cSJaegeuk Kim }; 128339a53e0cSJaegeuk Kim 128439a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 128539a53e0cSJaegeuk Kim { 128661e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 128739a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 128839a53e0cSJaegeuk Kim } 128939a53e0cSJaegeuk Kim 129039a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 129139a53e0cSJaegeuk Kim { 129239a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 129339a53e0cSJaegeuk Kim } 129439a53e0cSJaegeuk Kim 129539a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 129639a53e0cSJaegeuk Kim { 129761e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 129839a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 129939a53e0cSJaegeuk Kim } 130039a53e0cSJaegeuk Kim 130139a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 130239a53e0cSJaegeuk Kim { 130339a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 130439a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 130539a53e0cSJaegeuk Kim } 130639a53e0cSJaegeuk Kim 1307444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1308444c580fSJaegeuk Kim struct f2fs_inode *ri) 1309444c580fSJaegeuk Kim { 1310444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1311444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 13121001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 13131001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 131434d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 131534d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1316b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1317b3d208f9SJaegeuk Kim set_inode_flag(fi, FI_DATA_EXIST); 1318510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1319510022a8SJaegeuk Kim set_inode_flag(fi, FI_INLINE_DOTS); 1320444c580fSJaegeuk Kim } 1321444c580fSJaegeuk Kim 1322444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1323444c580fSJaegeuk Kim struct f2fs_inode *ri) 1324444c580fSJaegeuk Kim { 1325444c580fSJaegeuk Kim ri->i_inline = 0; 1326444c580fSJaegeuk Kim 1327444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1328444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 13291001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 13301001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 133134d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 133234d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1333b3d208f9SJaegeuk Kim if (is_inode_flag_set(fi, FI_DATA_EXIST)) 1334b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1335510022a8SJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_DOTS)) 1336510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1337444c580fSJaegeuk Kim } 1338444c580fSJaegeuk Kim 1339987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1340987c7c31SChao Yu { 1341987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1342987c7c31SChao Yu } 1343987c7c31SChao Yu 1344de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1345de93653fSJaegeuk Kim { 1346987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1347de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1348de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1349de93653fSJaegeuk Kim } 1350de93653fSJaegeuk Kim 135165985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 135265985d93SJaegeuk Kim { 1353695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 135465985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 135565985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 135665985d93SJaegeuk Kim } 135765985d93SJaegeuk Kim 135865985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 135965985d93SJaegeuk Kim { 1360987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 136165985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 136265985d93SJaegeuk Kim else 136365985d93SJaegeuk Kim return 0; 136465985d93SJaegeuk Kim } 136565985d93SJaegeuk Kim 13660dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 13670dbdc2aeSJaegeuk Kim { 13680dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 13690dbdc2aeSJaegeuk Kim } 13700dbdc2aeSJaegeuk Kim 1371b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1372b3d208f9SJaegeuk Kim { 1373b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 1374b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1375b3d208f9SJaegeuk Kim } 1376b3d208f9SJaegeuk Kim 1377b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1378b3d208f9SJaegeuk Kim { 1379b3d208f9SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST); 1380b3d208f9SJaegeuk Kim } 1381b3d208f9SJaegeuk Kim 1382510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1383510022a8SJaegeuk Kim { 1384510022a8SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS); 1385510022a8SJaegeuk Kim } 1386510022a8SJaegeuk Kim 138788b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 138888b88a66SJaegeuk Kim { 138988b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 139088b88a66SJaegeuk Kim } 139188b88a66SJaegeuk Kim 139202a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 139302a1335fSJaegeuk Kim { 139402a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 139502a1335fSJaegeuk Kim } 139602a1335fSJaegeuk Kim 13973c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 13983c6c2bebSJaegeuk Kim { 13993c6c2bebSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); 14003c6c2bebSJaegeuk Kim } 14013c6c2bebSJaegeuk Kim 14021e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 14031e84371fSJaegeuk Kim { 14041e84371fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE); 14051e84371fSJaegeuk Kim } 14061e84371fSJaegeuk Kim 14071001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 14081001b347SHuajun Li { 1409695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 14101001b347SHuajun Li return (void *)&(ri->i_addr[1]); 14111001b347SHuajun Li } 14121001b347SHuajun Li 141334d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 141434d67debSChao Yu { 141534d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 141634d67debSChao Yu } 141734d67debSChao Yu 14189486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 14199486ba44SJaegeuk Kim { 14209486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 14219486ba44SJaegeuk Kim kunmap(page); 14229486ba44SJaegeuk Kim } 14239486ba44SJaegeuk Kim 1424b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1425b5492af7SJaegeuk Kim { 1426b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1427b5492af7SJaegeuk Kim } 1428b5492af7SJaegeuk Kim 1429b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1430b5492af7SJaegeuk Kim { 1431b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1432b5492af7SJaegeuk Kim } 1433b5492af7SJaegeuk Kim 1434b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1435b5492af7SJaegeuk Kim { 1436b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1437b5492af7SJaegeuk Kim } 1438b5492af7SJaegeuk Kim 143977888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 144077888c1eSJaegeuk Kim { 144177888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 144277888c1eSJaegeuk Kim } 144377888c1eSJaegeuk Kim 14441e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 14451e968fdfSJaegeuk Kim { 14461e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 14471e968fdfSJaegeuk Kim } 14481e968fdfSJaegeuk Kim 1449744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1450744602cfSJaegeuk Kim { 1451744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1452744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1453744602cfSJaegeuk Kim } 1454744602cfSJaegeuk Kim 1455a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1456a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1457a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1458a6dda0e6SChristoph Hellwig 1459267378d4SChao Yu /* get offset of first page in next direct node */ 1460267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1461267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1462267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1463267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1464267378d4SChao Yu 146539a53e0cSJaegeuk Kim /* 146639a53e0cSJaegeuk Kim * file.c 146739a53e0cSJaegeuk Kim */ 146839a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 146939a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1470764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 147139a53e0cSJaegeuk Kim void f2fs_truncate(struct inode *); 14722d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 147339a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 147439a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1475b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 147639a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1477e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 147839a53e0cSJaegeuk Kim 147939a53e0cSJaegeuk Kim /* 148039a53e0cSJaegeuk Kim * inode.c 148139a53e0cSJaegeuk Kim */ 148239a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 148339a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 14844660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 148539a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *); 1486744602cfSJaegeuk Kim void update_inode_page(struct inode *); 148739a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 148839a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 148944c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 149039a53e0cSJaegeuk Kim 149139a53e0cSJaegeuk Kim /* 149239a53e0cSJaegeuk Kim * namei.c 149339a53e0cSJaegeuk Kim */ 149439a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 149539a53e0cSJaegeuk Kim 149639a53e0cSJaegeuk Kim /* 149739a53e0cSJaegeuk Kim * dir.c 149839a53e0cSJaegeuk Kim */ 1499dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1500510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 15017b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct qstr *, int *, 15027b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr *); 15037b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 15047b3cd7d6SJaegeuk Kim unsigned int); 1505062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1506062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1507dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1508bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1509dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1510a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1511dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 151239a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 151339a53e0cSJaegeuk Kim struct page **); 151439a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 151539a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 151639a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 151739a53e0cSJaegeuk Kim struct page *, struct inode *); 15181cd14cafSJaegeuk Kim int update_dent_inode(struct inode *, const struct qstr *); 1519510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 15203b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1521510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1522510022a8SJaegeuk Kim umode_t); 1523dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1524dbeacf02SChao Yu struct inode *); 1525b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 152639a53e0cSJaegeuk Kim int f2fs_make_empty(struct inode *, struct inode *); 152739a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 152839a53e0cSJaegeuk Kim 1529b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1530b7f7a5e0SAl Viro { 15312b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1532510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1533b7f7a5e0SAl Viro } 1534b7f7a5e0SAl Viro 153539a53e0cSJaegeuk Kim /* 153639a53e0cSJaegeuk Kim * super.c 153739a53e0cSJaegeuk Kim */ 153839a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1539a07ef784SNamjae Jeon extern __printf(3, 4) 1540a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 154139a53e0cSJaegeuk Kim 154239a53e0cSJaegeuk Kim /* 154339a53e0cSJaegeuk Kim * hash.c 154439a53e0cSJaegeuk Kim */ 1545eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 154639a53e0cSJaegeuk Kim 154739a53e0cSJaegeuk Kim /* 154839a53e0cSJaegeuk Kim * node.c 154939a53e0cSJaegeuk Kim */ 155039a53e0cSJaegeuk Kim struct dnode_of_data; 155139a53e0cSJaegeuk Kim struct node_info; 155239a53e0cSJaegeuk Kim 15536fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 155488bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 155588bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 155639a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 155739a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 155839a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 15594f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1560cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 156158e674d6SGu Zheng void remove_inode_page(struct inode *); 1562a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 15638ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 156439a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 156539a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 156639a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 156739a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 156839a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 156939a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 157039a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 157139a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 157270cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 15731c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 157439a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 157539a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 157639a53e0cSJaegeuk Kim struct f2fs_summary_block *); 157739a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 157839a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 157939a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 15806e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 158139a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 158239a53e0cSJaegeuk Kim 158339a53e0cSJaegeuk Kim /* 158439a53e0cSJaegeuk Kim * segment.c 158539a53e0cSJaegeuk Kim */ 158688b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 158788b88a66SJaegeuk Kim void commit_inmem_pages(struct inode *, bool); 158839a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *); 15894660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 15906b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 15912163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 15922163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 159339a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 15945e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 159539a53e0cSJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *); 15964b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1597cf2271e7SJaegeuk Kim void discard_next_dnode(struct f2fs_sb_info *, block_t); 15983fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 159939a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 16004b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 160139a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1602577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 1603fb5566daSJaegeuk Kim void write_node_page(struct f2fs_sb_info *, struct page *, 1604cf04e8ebSJaegeuk Kim unsigned int, struct f2fs_io_info *); 1605cf04e8ebSJaegeuk Kim void write_data_page(struct page *, struct dnode_of_data *, 1606458e6197SJaegeuk Kim struct f2fs_io_info *); 1607cf04e8ebSJaegeuk Kim void rewrite_data_page(struct page *, struct f2fs_io_info *); 160839a53e0cSJaegeuk Kim void recover_data_page(struct f2fs_sb_info *, struct page *, 160939a53e0cSJaegeuk Kim struct f2fs_summary *, block_t, block_t); 1610bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1611bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 16125514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 161339a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 161439a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 161539a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 161639a53e0cSJaegeuk Kim int, unsigned int, int); 16174b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 161839a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 161939a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 16207fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 16217fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 162239a53e0cSJaegeuk Kim 162339a53e0cSJaegeuk Kim /* 162439a53e0cSJaegeuk Kim * checkpoint.c 162539a53e0cSJaegeuk Kim */ 162639a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 162739a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 1628f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 16294c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int); 1630635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 163139a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1632fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1633fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 16346f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *); 1635fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1636cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1637cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 163839a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 163939a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 16408f99a946SChao Yu void recover_orphan_inodes(struct f2fs_sb_info *); 164139a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1642a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 16435deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 164439a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *); 164539a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *); 164675ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 16476451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 16486e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 164939a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 165039a53e0cSJaegeuk Kim 165139a53e0cSJaegeuk Kim /* 165239a53e0cSJaegeuk Kim * data.c 165339a53e0cSJaegeuk Kim */ 1654458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 1655cf04e8ebSJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *, 1656cf04e8ebSJaegeuk Kim struct f2fs_io_info *); 1657cf04e8ebSJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *, 1658458e6197SJaegeuk Kim struct f2fs_io_info *); 1659216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 166039a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1661b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 1662429511cdSChao Yu void f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 1663429511cdSChao Yu void f2fs_destroy_extent_tree(struct inode *); 1664028a41e8SChao Yu void f2fs_init_extent_cache(struct inode *, struct f2fs_extent *); 16657e4dde79SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 16660bdee482SChao Yu void f2fs_preserve_extent_tree(struct inode *); 1667c718379bSJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t, bool); 166839a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t); 166964aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 1670458e6197SJaegeuk Kim int do_write_data_page(struct page *, struct f2fs_io_info *); 16719ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1672429511cdSChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 1673429511cdSChao Yu int __init create_extent_cache(void); 1674429511cdSChao Yu void destroy_extent_cache(void); 1675487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1676487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 167739a53e0cSJaegeuk Kim 167839a53e0cSJaegeuk Kim /* 167939a53e0cSJaegeuk Kim * gc.c 168039a53e0cSJaegeuk Kim */ 168139a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 168239a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1683de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1684408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *); 168539a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 168639a53e0cSJaegeuk Kim 168739a53e0cSJaegeuk Kim /* 168839a53e0cSJaegeuk Kim * recovery.c 168939a53e0cSJaegeuk Kim */ 16906ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 169139a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 169239a53e0cSJaegeuk Kim 169339a53e0cSJaegeuk Kim /* 169439a53e0cSJaegeuk Kim * debug.c 169539a53e0cSJaegeuk Kim */ 169639a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 169739a53e0cSJaegeuk Kim struct f2fs_stat_info { 169839a53e0cSJaegeuk Kim struct list_head stat_list; 169939a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 170039a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 170139a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 17024bf6fd9fSChao Yu int hit_ext, total_ext, ext_tree, ext_node; 170339a53e0cSJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 1704dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 170539a53e0cSJaegeuk Kim int total_count, utilization; 1706d24bdcbfSJaegeuk Kim int bg_gc, inline_inode, inline_dir, inmem_pages, wb_pages; 170739a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 170839a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 170939a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 171039a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 171139a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1712942e0be6SChangman Lee int prefree_count, call_count, cp_count; 171339a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 1714e1235983SChangman Lee int bg_node_segs, bg_data_segs; 171539a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 1716e1235983SChangman Lee int bg_data_blks, bg_node_blks; 171739a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 171839a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 171939a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 172039a53e0cSJaegeuk Kim 172139a53e0cSJaegeuk Kim unsigned int segment_count[2]; 172239a53e0cSJaegeuk Kim unsigned int block_count[2]; 1723b9a2c252SChangman Lee unsigned int inplace_count; 17246f0aacbcSJaegeuk Kim unsigned base_mem, cache_mem, page_mem; 172539a53e0cSJaegeuk Kim }; 172639a53e0cSJaegeuk Kim 1727963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1728963d4f7dSGu Zheng { 1729963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1730963d4f7dSGu Zheng } 1731963d4f7dSGu Zheng 1732942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 173339a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1734dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1735dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1736dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 1737dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++) 1738dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++) 17390dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 17400dbdc2aeSJaegeuk Kim do { \ 17410dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 174203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 17430dbdc2aeSJaegeuk Kim } while (0) 17440dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 17450dbdc2aeSJaegeuk Kim do { \ 17460dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 174703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 17480dbdc2aeSJaegeuk Kim } while (0) 17493289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 17503289c061SJaegeuk Kim do { \ 17513289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 175203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 17533289c061SJaegeuk Kim } while (0) 17543289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 17553289c061SJaegeuk Kim do { \ 17563289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 175703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 17583289c061SJaegeuk Kim } while (0) 1759dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1760dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1761dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1762dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 1763b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 1764b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 1765e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 176639a53e0cSJaegeuk Kim do { \ 1767963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 176839a53e0cSJaegeuk Kim (si)->tot_segs++; \ 1769e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 177039a53e0cSJaegeuk Kim si->data_segs++; \ 1771e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 1772e1235983SChangman Lee } else { \ 177339a53e0cSJaegeuk Kim si->node_segs++; \ 1774e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 1775e1235983SChangman Lee } \ 177639a53e0cSJaegeuk Kim } while (0) 177739a53e0cSJaegeuk Kim 177839a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 177939a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 178039a53e0cSJaegeuk Kim 1781e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 178239a53e0cSJaegeuk Kim do { \ 1783963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 178439a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 178539a53e0cSJaegeuk Kim si->data_blks += (blks); \ 1786e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 178739a53e0cSJaegeuk Kim } while (0) 178839a53e0cSJaegeuk Kim 1789e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 179039a53e0cSJaegeuk Kim do { \ 1791963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 179239a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 179339a53e0cSJaegeuk Kim si->node_blks += (blks); \ 1794e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 179539a53e0cSJaegeuk Kim } while (0) 179639a53e0cSJaegeuk Kim 179739a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 179839a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 17996e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void); 18004589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 180139a53e0cSJaegeuk Kim #else 1802942e0be6SChangman Lee #define stat_inc_cp_count(si) 180339a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 1804dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 1805dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) 1806dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) 1807dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 1808dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) 18090dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 18100dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 18113289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 18123289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 1813dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 1814dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 1815b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 1816e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 181739a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 1818e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 1819e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 182039a53e0cSJaegeuk Kim 182139a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 182239a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 18236e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { } 18244589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 182539a53e0cSJaegeuk Kim #endif 182639a53e0cSJaegeuk Kim 182739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 182839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 182939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 183039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 183139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 183239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 183339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 183439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 183539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 183629e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 18371001b347SHuajun Li 1838e18c65b2SHuajun Li /* 1839e18c65b2SHuajun Li * inline.c 1840e18c65b2SHuajun Li */ 1841e18c65b2SHuajun Li bool f2fs_may_inline(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