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); \ 319850cf4aSJaegeuk Kim sbi->need_fsck = true; \ 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 49*34d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 50*34d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 51*34d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 5239a53e0cSJaegeuk Kim 5339a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 5439a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 5539a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 5639a53e0cSJaegeuk Kim 5739a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 5839a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 5939a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 6039a53e0cSJaegeuk Kim 61a9841c4dSJaegeuk Kim typedef u32 block_t; /* 62a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 63a9841c4dSJaegeuk Kim * address format, __le32. 64a9841c4dSJaegeuk Kim */ 6539a53e0cSJaegeuk Kim typedef u32 nid_t; 6639a53e0cSJaegeuk Kim 6739a53e0cSJaegeuk Kim struct f2fs_mount_info { 6839a53e0cSJaegeuk Kim unsigned int opt; 6939a53e0cSJaegeuk Kim }; 7039a53e0cSJaegeuk Kim 717e586fa0SJaegeuk Kim #define CRCPOLY_LE 0xedb88320 727e586fa0SJaegeuk Kim 737e586fa0SJaegeuk Kim static inline __u32 f2fs_crc32(void *buf, size_t len) 7439a53e0cSJaegeuk Kim { 757e586fa0SJaegeuk Kim unsigned char *p = (unsigned char *)buf; 767e586fa0SJaegeuk Kim __u32 crc = F2FS_SUPER_MAGIC; 777e586fa0SJaegeuk Kim int i; 787e586fa0SJaegeuk Kim 797e586fa0SJaegeuk Kim while (len--) { 807e586fa0SJaegeuk Kim crc ^= *p++; 817e586fa0SJaegeuk Kim for (i = 0; i < 8; i++) 827e586fa0SJaegeuk Kim crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); 837e586fa0SJaegeuk Kim } 847e586fa0SJaegeuk Kim return crc; 8539a53e0cSJaegeuk Kim } 8639a53e0cSJaegeuk Kim 877e586fa0SJaegeuk Kim static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size) 8839a53e0cSJaegeuk Kim { 897e586fa0SJaegeuk Kim return f2fs_crc32(buf, buf_size) == blk_crc; 9039a53e0cSJaegeuk Kim } 9139a53e0cSJaegeuk Kim 9239a53e0cSJaegeuk Kim /* 9339a53e0cSJaegeuk Kim * For checkpoint manager 9439a53e0cSJaegeuk Kim */ 9539a53e0cSJaegeuk Kim enum { 9639a53e0cSJaegeuk Kim NAT_BITMAP, 9739a53e0cSJaegeuk Kim SIT_BITMAP 9839a53e0cSJaegeuk Kim }; 9939a53e0cSJaegeuk Kim 10075ab4cb8SJaegeuk Kim enum { 10175ab4cb8SJaegeuk Kim CP_UMOUNT, 10275ab4cb8SJaegeuk Kim CP_SYNC, 1034b2fecc8SJaegeuk Kim CP_DISCARD, 10475ab4cb8SJaegeuk Kim }; 10575ab4cb8SJaegeuk Kim 10675ab4cb8SJaegeuk Kim struct cp_control { 10775ab4cb8SJaegeuk Kim int reason; 1084b2fecc8SJaegeuk Kim __u64 trim_start; 1094b2fecc8SJaegeuk Kim __u64 trim_end; 1104b2fecc8SJaegeuk Kim __u64 trim_minlen; 1114b2fecc8SJaegeuk Kim __u64 trimmed; 11275ab4cb8SJaegeuk Kim }; 11375ab4cb8SJaegeuk Kim 114662befdaSChao Yu /* 11581c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 116662befdaSChao Yu */ 117662befdaSChao Yu enum { 118662befdaSChao Yu META_CP, 119662befdaSChao Yu META_NAT, 12081c1a0f1SChao Yu META_SIT, 1214c521f49SJaegeuk Kim META_SSA, 1224c521f49SJaegeuk Kim META_POR, 123662befdaSChao Yu }; 124662befdaSChao Yu 1256451e041SJaegeuk Kim /* for the list of ino */ 1266451e041SJaegeuk Kim enum { 1276451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 128fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 129fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1306451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1316451e041SJaegeuk Kim }; 1326451e041SJaegeuk Kim 1336451e041SJaegeuk Kim struct ino_entry { 13439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 13539a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 13639a53e0cSJaegeuk Kim }; 13739a53e0cSJaegeuk Kim 13839a53e0cSJaegeuk Kim /* for the list of directory inodes */ 13939a53e0cSJaegeuk Kim struct dir_inode_entry { 14039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 14139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 14239a53e0cSJaegeuk Kim }; 14339a53e0cSJaegeuk Kim 1447fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1457fd9e544SJaegeuk Kim struct discard_entry { 1467fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1477fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1487fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1497fd9e544SJaegeuk Kim }; 1507fd9e544SJaegeuk Kim 15139a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 15239a53e0cSJaegeuk Kim struct fsync_inode_entry { 15339a53e0cSJaegeuk Kim struct list_head list; /* list head */ 15439a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 155c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 156c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 157c52e1b10SJaegeuk Kim block_t last_inode; /* block address locating the last inode */ 15839a53e0cSJaegeuk Kim }; 15939a53e0cSJaegeuk Kim 16039a53e0cSJaegeuk Kim #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats)) 16139a53e0cSJaegeuk Kim #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits)) 16239a53e0cSJaegeuk Kim 16339a53e0cSJaegeuk Kim #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne) 16439a53e0cSJaegeuk Kim #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid) 16539a53e0cSJaegeuk Kim #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se) 16639a53e0cSJaegeuk Kim #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno) 16739a53e0cSJaegeuk Kim 168309cc2b6SJaegeuk Kim #define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum)) 169309cc2b6SJaegeuk Kim #define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum)) 170309cc2b6SJaegeuk Kim 17139a53e0cSJaegeuk Kim static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i) 17239a53e0cSJaegeuk Kim { 17339a53e0cSJaegeuk Kim int before = nats_in_cursum(rs); 17439a53e0cSJaegeuk Kim rs->n_nats = cpu_to_le16(before + i); 17539a53e0cSJaegeuk Kim return before; 17639a53e0cSJaegeuk Kim } 17739a53e0cSJaegeuk Kim 17839a53e0cSJaegeuk Kim static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i) 17939a53e0cSJaegeuk Kim { 18039a53e0cSJaegeuk Kim int before = sits_in_cursum(rs); 18139a53e0cSJaegeuk Kim rs->n_sits = cpu_to_le16(before + i); 18239a53e0cSJaegeuk Kim return before; 18339a53e0cSJaegeuk Kim } 18439a53e0cSJaegeuk Kim 185184a5cd2SChao Yu static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size, 186184a5cd2SChao Yu int type) 187184a5cd2SChao Yu { 188184a5cd2SChao Yu if (type == NAT_JOURNAL) 189309cc2b6SJaegeuk Kim return size <= MAX_NAT_JENTRIES(sum); 190309cc2b6SJaegeuk Kim return size <= MAX_SIT_JENTRIES(sum); 191184a5cd2SChao Yu } 192184a5cd2SChao Yu 19339a53e0cSJaegeuk Kim /* 194e9750824SNamjae Jeon * ioctl commands 195e9750824SNamjae Jeon */ 196e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 197e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 198e9750824SNamjae Jeon 19988b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 20088b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 20188b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 20202a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 20388b88a66SJaegeuk Kim 204e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 205e9750824SNamjae Jeon /* 206e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 207e9750824SNamjae Jeon */ 208e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 209e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 210e9750824SNamjae Jeon #endif 211e9750824SNamjae Jeon 212e9750824SNamjae Jeon /* 21339a53e0cSJaegeuk Kim * For INODE and NODE manager 21439a53e0cSJaegeuk Kim */ 215dbe6a5ffSJaegeuk Kim /* 216dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 217dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 218dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 21939a53e0cSJaegeuk Kim */ 220dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 221dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 222266e97a8SJaegeuk Kim enum { 223266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 224266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 225266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 226266e97a8SJaegeuk Kim * look up a node with readahead called 2274f4124d0SChao Yu * by get_data_block. 22839a53e0cSJaegeuk Kim */ 229266e97a8SJaegeuk Kim }; 230266e97a8SJaegeuk Kim 23139a53e0cSJaegeuk Kim #define F2FS_LINK_MAX 32000 /* maximum link count per file */ 23239a53e0cSJaegeuk Kim 233817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 234817202d9SChao Yu 23539a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 236c11abd1aSJaegeuk Kim #define F2FS_MIN_EXTENT_LEN 16 /* minimum extent length */ 237c11abd1aSJaegeuk Kim 23839a53e0cSJaegeuk Kim struct extent_info { 23939a53e0cSJaegeuk Kim rwlock_t ext_lock; /* rwlock for consistency */ 24039a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 24139a53e0cSJaegeuk Kim u32 blk_addr; /* start block address of the extent */ 242111d2495SMasanari Iida unsigned int len; /* length of the extent */ 24339a53e0cSJaegeuk Kim }; 24439a53e0cSJaegeuk Kim 24539a53e0cSJaegeuk Kim /* 24639a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 24739a53e0cSJaegeuk Kim */ 24839a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 249354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 25039a53e0cSJaegeuk Kim 251ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 252ab9fa662SJaegeuk Kim 25339a53e0cSJaegeuk Kim struct f2fs_inode_info { 25439a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 25539a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 25639a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 25738431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 25839a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 2596666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 26039a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 26139a53e0cSJaegeuk Kim 26239a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 26339a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 264d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 265a7ffdbe2SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 26639a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 26739a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 26839a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 269e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 27039a53e0cSJaegeuk Kim struct extent_info ext; /* in-memory extent cache entry */ 271ed57c27fSJaegeuk Kim struct dir_inode_entry *dirty_dir; /* the pointer of dirty dir */ 27288b88a66SJaegeuk Kim 27334ba94baSJaegeuk Kim struct radix_tree_root inmem_root; /* radix tree for inmem pages */ 27488b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 27588b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 27639a53e0cSJaegeuk Kim }; 27739a53e0cSJaegeuk Kim 27839a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 27939a53e0cSJaegeuk Kim struct f2fs_extent i_ext) 28039a53e0cSJaegeuk Kim { 28139a53e0cSJaegeuk Kim write_lock(&ext->ext_lock); 28239a53e0cSJaegeuk Kim ext->fofs = le32_to_cpu(i_ext.fofs); 28339a53e0cSJaegeuk Kim ext->blk_addr = le32_to_cpu(i_ext.blk_addr); 28439a53e0cSJaegeuk Kim ext->len = le32_to_cpu(i_ext.len); 28539a53e0cSJaegeuk Kim write_unlock(&ext->ext_lock); 28639a53e0cSJaegeuk Kim } 28739a53e0cSJaegeuk Kim 28839a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 28939a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 29039a53e0cSJaegeuk Kim { 29139a53e0cSJaegeuk Kim read_lock(&ext->ext_lock); 29239a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 29339a53e0cSJaegeuk Kim i_ext->blk_addr = cpu_to_le32(ext->blk_addr); 29439a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 29539a53e0cSJaegeuk Kim read_unlock(&ext->ext_lock); 29639a53e0cSJaegeuk Kim } 29739a53e0cSJaegeuk Kim 29839a53e0cSJaegeuk Kim struct f2fs_nm_info { 29939a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 30039a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 3017ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 30239a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 303cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 30439a53e0cSJaegeuk Kim 30539a53e0cSJaegeuk Kim /* NAT cache management */ 30639a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 307309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 30839a53e0cSJaegeuk Kim rwlock_t nat_tree_lock; /* protect nat_tree_lock */ 30939a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 310309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 311aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 31239a53e0cSJaegeuk Kim 31339a53e0cSJaegeuk Kim /* free node ids management */ 3148a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 31539a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 31639a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 31739a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 31839a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 31939a53e0cSJaegeuk Kim 32039a53e0cSJaegeuk Kim /* for checkpoint */ 32139a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 32239a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 32339a53e0cSJaegeuk Kim }; 32439a53e0cSJaegeuk Kim 32539a53e0cSJaegeuk Kim /* 32639a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 32739a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 32839a53e0cSJaegeuk Kim * by the data offset in a file. 32939a53e0cSJaegeuk Kim */ 33039a53e0cSJaegeuk Kim struct dnode_of_data { 33139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 33239a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 33339a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 33439a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 33539a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 33639a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 33739a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 33839a53e0cSJaegeuk Kim }; 33939a53e0cSJaegeuk Kim 34039a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 34139a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 34239a53e0cSJaegeuk Kim { 343d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 34439a53e0cSJaegeuk Kim dn->inode = inode; 34539a53e0cSJaegeuk Kim dn->inode_page = ipage; 34639a53e0cSJaegeuk Kim dn->node_page = npage; 34739a53e0cSJaegeuk Kim dn->nid = nid; 34839a53e0cSJaegeuk Kim } 34939a53e0cSJaegeuk Kim 35039a53e0cSJaegeuk Kim /* 35139a53e0cSJaegeuk Kim * For SIT manager 35239a53e0cSJaegeuk Kim * 35339a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 35439a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 35539a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 35639a53e0cSJaegeuk Kim * respectively. 35739a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 35839a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 35939a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 36039a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 36139a53e0cSJaegeuk Kim * data and 8 for node logs. 36239a53e0cSJaegeuk Kim */ 36339a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 36439a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 36539a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 36639a53e0cSJaegeuk Kim 36739a53e0cSJaegeuk Kim enum { 36839a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 36939a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 37039a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 37139a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 37239a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 37339a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 37439a53e0cSJaegeuk Kim NO_CHECK_TYPE 37539a53e0cSJaegeuk Kim }; 37639a53e0cSJaegeuk Kim 3776b4afdd7SJaegeuk Kim struct flush_cmd { 3786b4afdd7SJaegeuk Kim struct completion wait; 379721bd4d5SGu Zheng struct llist_node llnode; 3806b4afdd7SJaegeuk Kim int ret; 3816b4afdd7SJaegeuk Kim }; 3826b4afdd7SJaegeuk Kim 383a688b9d9SGu Zheng struct flush_cmd_control { 384a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 385a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 386721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 387721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 388a688b9d9SGu Zheng }; 389a688b9d9SGu Zheng 39039a53e0cSJaegeuk Kim struct f2fs_sm_info { 39139a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 39239a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 39339a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 39439a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 39539a53e0cSJaegeuk Kim 39639a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 39739a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 39839a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 39939a53e0cSJaegeuk Kim 40039a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 40139a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 40239a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 40339a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 40481eb8d6eSJaegeuk Kim 40581eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 40681eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 4077fd9e544SJaegeuk Kim 4087fd9e544SJaegeuk Kim /* for small discard management */ 4097fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 4107fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 4117fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 412216fbd64SJaegeuk Kim 413184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 414184a5cd2SChao Yu 415216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 416216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 417c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 4186b4afdd7SJaegeuk Kim 4196b4afdd7SJaegeuk Kim /* for flush command control */ 420a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 421a688b9d9SGu Zheng 42239a53e0cSJaegeuk Kim }; 42339a53e0cSJaegeuk Kim 42439a53e0cSJaegeuk Kim /* 42539a53e0cSJaegeuk Kim * For superblock 42639a53e0cSJaegeuk Kim */ 42739a53e0cSJaegeuk Kim /* 42839a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 42939a53e0cSJaegeuk Kim * 43039a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 43139a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 43239a53e0cSJaegeuk Kim */ 43339a53e0cSJaegeuk Kim enum count_type { 43439a53e0cSJaegeuk Kim F2FS_WRITEBACK, 43539a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 43639a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 43739a53e0cSJaegeuk Kim F2FS_DIRTY_META, 43839a53e0cSJaegeuk Kim NR_COUNT_TYPE, 43939a53e0cSJaegeuk Kim }; 44039a53e0cSJaegeuk Kim 44139a53e0cSJaegeuk Kim /* 442e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 44339a53e0cSJaegeuk Kim * The available types are: 44439a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 44539a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 44639a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 44739a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 44839a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 44939a53e0cSJaegeuk Kim * with waiting the bio's completion 45039a53e0cSJaegeuk Kim * ... Only can be used with META. 45139a53e0cSJaegeuk Kim */ 4527d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 45339a53e0cSJaegeuk Kim enum page_type { 45439a53e0cSJaegeuk Kim DATA, 45539a53e0cSJaegeuk Kim NODE, 45639a53e0cSJaegeuk Kim META, 45739a53e0cSJaegeuk Kim NR_PAGE_TYPE, 45839a53e0cSJaegeuk Kim META_FLUSH, 45939a53e0cSJaegeuk Kim }; 46039a53e0cSJaegeuk Kim 461458e6197SJaegeuk Kim struct f2fs_io_info { 462458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 4637e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 464458e6197SJaegeuk Kim }; 465458e6197SJaegeuk Kim 46693dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 4671ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 468458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 4691ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 4701ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 471458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 472df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 4731ff7bd3bSJaegeuk Kim }; 4741ff7bd3bSJaegeuk Kim 47539a53e0cSJaegeuk Kim struct f2fs_sb_info { 47639a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 4775e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 47839a53e0cSJaegeuk Kim struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 47939a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 48039a53e0cSJaegeuk Kim int s_dirty; /* dirty flag for checkpoint */ 4812ae4c673SJaegeuk Kim bool need_fsck; /* need fsck.f2fs to fix */ 48239a53e0cSJaegeuk Kim 48339a53e0cSJaegeuk Kim /* for node-related operations */ 48439a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 48539a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 48639a53e0cSJaegeuk Kim 48739a53e0cSJaegeuk Kim /* for segment-related operations */ 48839a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 4891ff7bd3bSJaegeuk Kim 4901ff7bd3bSJaegeuk Kim /* for bio operations */ 491924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 4921ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 4931b1f559fSJaegeuk Kim struct completion *wait_io; /* for completion bios */ 49439a53e0cSJaegeuk Kim 49539a53e0cSJaegeuk Kim /* for checkpoint */ 49639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 49739a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 49839936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 499e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 500b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 50139a53e0cSJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 502aabe5136SHaicheng Li bool por_doing; /* recovery is doing or not */ 503fb51b5efSChangman Lee wait_queue_head_t cp_wait; 50439a53e0cSJaegeuk Kim 5056451e041SJaegeuk Kim /* for inode management */ 50639efac41SJaegeuk Kim struct radix_tree_root ino_root[MAX_INO_ENTRY]; /* ino entry array */ 5076451e041SJaegeuk Kim spinlock_t ino_lock[MAX_INO_ENTRY]; /* for ino entry lock */ 5086451e041SJaegeuk Kim struct list_head ino_list[MAX_INO_ENTRY]; /* inode list head */ 5096451e041SJaegeuk Kim 5106451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 51139a53e0cSJaegeuk Kim unsigned int n_orphans; /* # of orphan inodes */ 5120d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 51339a53e0cSJaegeuk Kim 51439a53e0cSJaegeuk Kim /* for directory inode management */ 51539a53e0cSJaegeuk Kim struct list_head dir_inode_list; /* dir inode list */ 51639a53e0cSJaegeuk Kim spinlock_t dir_inode_lock; /* for dir inode list lock */ 51739a53e0cSJaegeuk Kim 51839a53e0cSJaegeuk Kim /* basic filesystem units */ 51939a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 52039a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 52139a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 52239a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 52339a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 52439a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 52539a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 52639a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 52739a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 52839a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 52939a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 53039a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 53139a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 53239a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 53339a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 534ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 53539a53e0cSJaegeuk Kim 53639a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 53739a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 53839a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 53939a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 54039a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 54139a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 54239a53e0cSJaegeuk Kim 54339a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 54439a53e0cSJaegeuk Kim 54539a53e0cSJaegeuk Kim /* for cleaning operations */ 54639a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 54739a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 5485ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 54939a53e0cSJaegeuk Kim 550b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 551b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 552b1c57c1cSJaegeuk Kim 55339a53e0cSJaegeuk Kim /* 55439a53e0cSJaegeuk Kim * for stat information. 55539a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 55639a53e0cSJaegeuk Kim */ 55735b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 55839a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 55939a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 56039a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 56139a53e0cSJaegeuk Kim int total_hit_ext, read_hit_ext; /* extent cache hit ratio */ 5620dbdc2aeSJaegeuk Kim int inline_inode; /* # of inline_data inodes */ 56339a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 56435b09d82SNamjae Jeon unsigned int n_dirty_dirs; /* # of dir inodes */ 56535b09d82SNamjae Jeon #endif 56635b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 56739a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 568b59d0baeSNamjae Jeon 569b59d0baeSNamjae Jeon /* For sysfs suppport */ 570b59d0baeSNamjae Jeon struct kobject s_kobj; 571b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 57239a53e0cSJaegeuk Kim }; 57339a53e0cSJaegeuk Kim 57439a53e0cSJaegeuk Kim /* 57539a53e0cSJaegeuk Kim * Inline functions 57639a53e0cSJaegeuk Kim */ 57739a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 57839a53e0cSJaegeuk Kim { 57939a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 58039a53e0cSJaegeuk Kim } 58139a53e0cSJaegeuk Kim 58239a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 58339a53e0cSJaegeuk Kim { 58439a53e0cSJaegeuk Kim return sb->s_fs_info; 58539a53e0cSJaegeuk Kim } 58639a53e0cSJaegeuk Kim 5874081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 5884081363fSJaegeuk Kim { 5894081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 5904081363fSJaegeuk Kim } 5914081363fSJaegeuk Kim 5924081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 5934081363fSJaegeuk Kim { 5944081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 5954081363fSJaegeuk Kim } 5964081363fSJaegeuk Kim 5974081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 5984081363fSJaegeuk Kim { 5994081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 6004081363fSJaegeuk Kim } 6014081363fSJaegeuk Kim 60239a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 60339a53e0cSJaegeuk Kim { 60439a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 60539a53e0cSJaegeuk Kim } 60639a53e0cSJaegeuk Kim 60739a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 60839a53e0cSJaegeuk Kim { 60939a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 61039a53e0cSJaegeuk Kim } 61139a53e0cSJaegeuk Kim 61245590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 61345590710SGu Zheng { 61445590710SGu Zheng return (struct f2fs_node *)page_address(page); 61545590710SGu Zheng } 61645590710SGu Zheng 61758bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 61858bfaf44SJaegeuk Kim { 61958bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 62058bfaf44SJaegeuk Kim } 62158bfaf44SJaegeuk Kim 62239a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 62339a53e0cSJaegeuk Kim { 62439a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 62539a53e0cSJaegeuk Kim } 62639a53e0cSJaegeuk Kim 62739a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 62839a53e0cSJaegeuk Kim { 62939a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 63039a53e0cSJaegeuk Kim } 63139a53e0cSJaegeuk Kim 63239a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 63339a53e0cSJaegeuk Kim { 63439a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 63539a53e0cSJaegeuk Kim } 63639a53e0cSJaegeuk Kim 63739a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 63839a53e0cSJaegeuk Kim { 63939a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 64039a53e0cSJaegeuk Kim } 64139a53e0cSJaegeuk Kim 64239a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 64339a53e0cSJaegeuk Kim { 64439a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 64539a53e0cSJaegeuk Kim } 64639a53e0cSJaegeuk Kim 6479df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 6489df27d98SGu Zheng { 6499df27d98SGu Zheng return sbi->meta_inode->i_mapping; 6509df27d98SGu Zheng } 6519df27d98SGu Zheng 6524ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 6534ef51a8fSJaegeuk Kim { 6544ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 6554ef51a8fSJaegeuk Kim } 6564ef51a8fSJaegeuk Kim 65739a53e0cSJaegeuk Kim static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi) 65839a53e0cSJaegeuk Kim { 65939a53e0cSJaegeuk Kim sbi->s_dirty = 1; 66039a53e0cSJaegeuk Kim } 66139a53e0cSJaegeuk Kim 66239a53e0cSJaegeuk Kim static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi) 66339a53e0cSJaegeuk Kim { 66439a53e0cSJaegeuk Kim sbi->s_dirty = 0; 66539a53e0cSJaegeuk Kim } 66639a53e0cSJaegeuk Kim 667d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 668d71b5564SJaegeuk Kim { 669d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 670d71b5564SJaegeuk Kim } 671d71b5564SJaegeuk Kim 67225ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 67325ca923bSJaegeuk Kim { 67425ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 67525ca923bSJaegeuk Kim return ckpt_flags & f; 67625ca923bSJaegeuk Kim } 67725ca923bSJaegeuk Kim 67825ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 67925ca923bSJaegeuk Kim { 68025ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 68125ca923bSJaegeuk Kim ckpt_flags |= f; 68225ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 68325ca923bSJaegeuk Kim } 68425ca923bSJaegeuk Kim 68525ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 68625ca923bSJaegeuk Kim { 68725ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 68825ca923bSJaegeuk Kim ckpt_flags &= (~f); 68925ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 69025ca923bSJaegeuk Kim } 69125ca923bSJaegeuk Kim 692e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 69339a53e0cSJaegeuk Kim { 694e479556bSGu Zheng down_read(&sbi->cp_rwsem); 69539a53e0cSJaegeuk Kim } 69639a53e0cSJaegeuk Kim 697e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 69839a53e0cSJaegeuk Kim { 699e479556bSGu Zheng up_read(&sbi->cp_rwsem); 70039936837SJaegeuk Kim } 70139936837SJaegeuk Kim 702e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 70339936837SJaegeuk Kim { 7040daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 70539936837SJaegeuk Kim } 70639936837SJaegeuk Kim 707e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 70839936837SJaegeuk Kim { 709e479556bSGu Zheng up_write(&sbi->cp_rwsem); 71039a53e0cSJaegeuk Kim } 71139a53e0cSJaegeuk Kim 71239a53e0cSJaegeuk Kim /* 71339a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 71439a53e0cSJaegeuk Kim */ 715064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 71639a53e0cSJaegeuk Kim { 717d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 718d6b7d4b3SChao Yu return -EINVAL; 719cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 720064e0823SNamjae Jeon return -EINVAL; 721064e0823SNamjae Jeon return 0; 72239a53e0cSJaegeuk Kim } 72339a53e0cSJaegeuk Kim 72439a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 72539a53e0cSJaegeuk Kim 72639a53e0cSJaegeuk Kim /* 72739a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 72839a53e0cSJaegeuk Kim */ 72939a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 73039a53e0cSJaegeuk Kim { 73139a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 7326c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 73339a53e0cSJaegeuk Kim else 7346c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 73539a53e0cSJaegeuk Kim } 73639a53e0cSJaegeuk Kim 7374bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 7384bc8e9bcSChao Yu { 7394bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 7404bc8e9bcSChao Yu } 7414bc8e9bcSChao Yu 74239a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 74339a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 74439a53e0cSJaegeuk Kim { 74539a53e0cSJaegeuk Kim block_t valid_block_count; 74639a53e0cSJaegeuk Kim 74739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 74839a53e0cSJaegeuk Kim valid_block_count = 74939a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 750cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 75139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 75239a53e0cSJaegeuk Kim return false; 75339a53e0cSJaegeuk Kim } 75439a53e0cSJaegeuk Kim inode->i_blocks += count; 75539a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 75639a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 75739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 75839a53e0cSJaegeuk Kim return true; 75939a53e0cSJaegeuk Kim } 76039a53e0cSJaegeuk Kim 761da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 76239a53e0cSJaegeuk Kim struct inode *inode, 76339a53e0cSJaegeuk Kim blkcnt_t count) 76439a53e0cSJaegeuk Kim { 76539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 7669850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 7679850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 76839a53e0cSJaegeuk Kim inode->i_blocks -= count; 76939a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 77039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 77139a53e0cSJaegeuk Kim } 77239a53e0cSJaegeuk Kim 77339a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 77439a53e0cSJaegeuk Kim { 77539a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 77639a53e0cSJaegeuk Kim F2FS_SET_SB_DIRT(sbi); 77739a53e0cSJaegeuk Kim } 77839a53e0cSJaegeuk Kim 779a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 78039a53e0cSJaegeuk Kim { 781a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 782a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 7834081363fSJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 78439a53e0cSJaegeuk Kim } 78539a53e0cSJaegeuk Kim 78639a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 78739a53e0cSJaegeuk Kim { 78839a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 78939a53e0cSJaegeuk Kim } 79039a53e0cSJaegeuk Kim 791a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 79239a53e0cSJaegeuk Kim { 793a7ffdbe2SJaegeuk Kim if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)) 7941fe54f9dSJaegeuk Kim return; 7951fe54f9dSJaegeuk Kim 796a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 797a7ffdbe2SJaegeuk Kim 798a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 7994081363fSJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 80039a53e0cSJaegeuk Kim } 80139a53e0cSJaegeuk Kim 80239a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 80339a53e0cSJaegeuk Kim { 80439a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 80539a53e0cSJaegeuk Kim } 80639a53e0cSJaegeuk Kim 807a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 808f8b2c1f9SJaegeuk Kim { 809a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 810f8b2c1f9SJaegeuk Kim } 811f8b2c1f9SJaegeuk Kim 8125ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 8135ac206cfSNamjae Jeon { 8145ac206cfSNamjae Jeon unsigned int pages_per_sec = sbi->segs_per_sec * 8155ac206cfSNamjae Jeon (1 << sbi->log_blocks_per_seg); 8165ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 8175ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 8185ac206cfSNamjae Jeon } 8195ac206cfSNamjae Jeon 82039a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 82139a53e0cSJaegeuk Kim { 8228b8343faSJaegeuk Kim return sbi->total_valid_block_count; 82339a53e0cSJaegeuk Kim } 82439a53e0cSJaegeuk Kim 82539a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 82639a53e0cSJaegeuk Kim { 82739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 82839a53e0cSJaegeuk Kim 82939a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 83039a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 83139a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 83239a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 83339a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 83439a53e0cSJaegeuk Kim 83539a53e0cSJaegeuk Kim return 0; 83639a53e0cSJaegeuk Kim } 83739a53e0cSJaegeuk Kim 83839a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 83939a53e0cSJaegeuk Kim { 84039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 8411dbe4152SChangman Lee int offset; 8421dbe4152SChangman Lee 8431dbe4152SChangman Lee if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload) > 0) { 8441dbe4152SChangman Lee if (flag == NAT_BITMAP) 8451dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 8461dbe4152SChangman Lee else 84765b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 8481dbe4152SChangman Lee } else { 8491dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 85025ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 85139a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 85239a53e0cSJaegeuk Kim } 8531dbe4152SChangman Lee } 85439a53e0cSJaegeuk Kim 85539a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 85639a53e0cSJaegeuk Kim { 85739a53e0cSJaegeuk Kim block_t start_addr; 85839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 859d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 86039a53e0cSJaegeuk Kim 86125ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 86239a53e0cSJaegeuk Kim 86339a53e0cSJaegeuk Kim /* 86439a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 865e1c42045Sarter97 * and even segment must be at cp segment 1 86639a53e0cSJaegeuk Kim */ 86739a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 86839a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 86939a53e0cSJaegeuk Kim 87039a53e0cSJaegeuk Kim return start_addr; 87139a53e0cSJaegeuk Kim } 87239a53e0cSJaegeuk Kim 87339a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 87439a53e0cSJaegeuk Kim { 87539a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 87639a53e0cSJaegeuk Kim } 87739a53e0cSJaegeuk Kim 87839a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 879ef86d709SGu Zheng struct inode *inode) 88039a53e0cSJaegeuk Kim { 88139a53e0cSJaegeuk Kim block_t valid_block_count; 88239a53e0cSJaegeuk Kim unsigned int valid_node_count; 88339a53e0cSJaegeuk Kim 88439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 88539a53e0cSJaegeuk Kim 886ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 887cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 88839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 88939a53e0cSJaegeuk Kim return false; 89039a53e0cSJaegeuk Kim } 89139a53e0cSJaegeuk Kim 892ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 893cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 89439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 89539a53e0cSJaegeuk Kim return false; 89639a53e0cSJaegeuk Kim } 89739a53e0cSJaegeuk Kim 89839a53e0cSJaegeuk Kim if (inode) 899ef86d709SGu Zheng inode->i_blocks++; 900ef86d709SGu Zheng 901ef86d709SGu Zheng sbi->alloc_valid_block_count++; 902ef86d709SGu Zheng sbi->total_valid_node_count++; 903ef86d709SGu Zheng sbi->total_valid_block_count++; 90439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 90539a53e0cSJaegeuk Kim 90639a53e0cSJaegeuk Kim return true; 90739a53e0cSJaegeuk Kim } 90839a53e0cSJaegeuk Kim 90939a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 910ef86d709SGu Zheng struct inode *inode) 91139a53e0cSJaegeuk Kim { 91239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 91339a53e0cSJaegeuk Kim 9149850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 9159850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 9169850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 91739a53e0cSJaegeuk Kim 918ef86d709SGu Zheng inode->i_blocks--; 919ef86d709SGu Zheng sbi->total_valid_node_count--; 920ef86d709SGu Zheng sbi->total_valid_block_count--; 92139a53e0cSJaegeuk Kim 92239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 92339a53e0cSJaegeuk Kim } 92439a53e0cSJaegeuk Kim 92539a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 92639a53e0cSJaegeuk Kim { 9278b8343faSJaegeuk Kim return sbi->total_valid_node_count; 92839a53e0cSJaegeuk Kim } 92939a53e0cSJaegeuk Kim 93039a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 93139a53e0cSJaegeuk Kim { 93239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 9339850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 93439a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 93539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 93639a53e0cSJaegeuk Kim } 93739a53e0cSJaegeuk Kim 9380e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 93939a53e0cSJaegeuk Kim { 94039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 9419850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 94239a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 94339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 94439a53e0cSJaegeuk Kim } 94539a53e0cSJaegeuk Kim 94639a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 94739a53e0cSJaegeuk Kim { 9488b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 94939a53e0cSJaegeuk Kim } 95039a53e0cSJaegeuk Kim 95139a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 95239a53e0cSJaegeuk Kim { 953031fa8ccSJaegeuk Kim if (!page) 95439a53e0cSJaegeuk Kim return; 95539a53e0cSJaegeuk Kim 95639a53e0cSJaegeuk Kim if (unlock) { 9579850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 95839a53e0cSJaegeuk Kim unlock_page(page); 95939a53e0cSJaegeuk Kim } 96039a53e0cSJaegeuk Kim page_cache_release(page); 96139a53e0cSJaegeuk Kim } 96239a53e0cSJaegeuk Kim 96339a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 96439a53e0cSJaegeuk Kim { 96539a53e0cSJaegeuk Kim if (dn->node_page) 96639a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 96739a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 96839a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 96939a53e0cSJaegeuk Kim dn->node_page = NULL; 97039a53e0cSJaegeuk Kim dn->inode_page = NULL; 97139a53e0cSJaegeuk Kim } 97239a53e0cSJaegeuk Kim 97339a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 974e8512d2eSGu Zheng size_t size) 97539a53e0cSJaegeuk Kim { 976e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 97739a53e0cSJaegeuk Kim } 97839a53e0cSJaegeuk Kim 9797bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 9807bd59381SGu Zheng gfp_t flags) 9817bd59381SGu Zheng { 9827bd59381SGu Zheng void *entry; 9837bd59381SGu Zheng retry: 9847bd59381SGu Zheng entry = kmem_cache_alloc(cachep, flags); 9857bd59381SGu Zheng if (!entry) { 9867bd59381SGu Zheng cond_resched(); 9877bd59381SGu Zheng goto retry; 9887bd59381SGu Zheng } 9897bd59381SGu Zheng 9907bd59381SGu Zheng return entry; 9917bd59381SGu Zheng } 9927bd59381SGu Zheng 99339a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 99439a53e0cSJaegeuk Kim 99539a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 99639a53e0cSJaegeuk Kim { 99745590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 99839a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 99939a53e0cSJaegeuk Kim } 100039a53e0cSJaegeuk Kim 100139a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 100239a53e0cSJaegeuk Kim { 100339a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 100439a53e0cSJaegeuk Kim } 100539a53e0cSJaegeuk Kim 100639a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 100739a53e0cSJaegeuk Kim unsigned int offset) 100839a53e0cSJaegeuk Kim { 100939a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 101039a53e0cSJaegeuk Kim __le32 *addr_array; 101145590710SGu Zheng raw_node = F2FS_NODE(node_page); 101239a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 101339a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 101439a53e0cSJaegeuk Kim } 101539a53e0cSJaegeuk Kim 101639a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 101739a53e0cSJaegeuk Kim { 101839a53e0cSJaegeuk Kim int mask; 101939a53e0cSJaegeuk Kim 102039a53e0cSJaegeuk Kim addr += (nr >> 3); 102139a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 102239a53e0cSJaegeuk Kim return mask & *addr; 102339a53e0cSJaegeuk Kim } 102439a53e0cSJaegeuk Kim 102539a53e0cSJaegeuk Kim static inline int f2fs_set_bit(unsigned int nr, char *addr) 102639a53e0cSJaegeuk Kim { 102739a53e0cSJaegeuk Kim int mask; 102839a53e0cSJaegeuk Kim int ret; 102939a53e0cSJaegeuk Kim 103039a53e0cSJaegeuk Kim addr += (nr >> 3); 103139a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 103239a53e0cSJaegeuk Kim ret = mask & *addr; 103339a53e0cSJaegeuk Kim *addr |= mask; 103439a53e0cSJaegeuk Kim return ret; 103539a53e0cSJaegeuk Kim } 103639a53e0cSJaegeuk Kim 103739a53e0cSJaegeuk Kim static inline int f2fs_clear_bit(unsigned int nr, char *addr) 103839a53e0cSJaegeuk Kim { 103939a53e0cSJaegeuk Kim int mask; 104039a53e0cSJaegeuk Kim int ret; 104139a53e0cSJaegeuk Kim 104239a53e0cSJaegeuk Kim addr += (nr >> 3); 104339a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 104439a53e0cSJaegeuk Kim ret = mask & *addr; 104539a53e0cSJaegeuk Kim *addr &= ~mask; 104639a53e0cSJaegeuk Kim return ret; 104739a53e0cSJaegeuk Kim } 104839a53e0cSJaegeuk Kim 104939a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 105039a53e0cSJaegeuk Kim enum { 105139a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1052b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1053ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 105439a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 105539a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 105639a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1057699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 105874d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1059c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1060444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 10611001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 1062*34d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1063fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1064fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 106588b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 106688b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 106702a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 106839a53e0cSJaegeuk Kim }; 106939a53e0cSJaegeuk Kim 107039a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 107139a53e0cSJaegeuk Kim { 107261e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 107339a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 107439a53e0cSJaegeuk Kim } 107539a53e0cSJaegeuk Kim 107639a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 107739a53e0cSJaegeuk Kim { 107839a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 107939a53e0cSJaegeuk Kim } 108039a53e0cSJaegeuk Kim 108139a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 108239a53e0cSJaegeuk Kim { 108361e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 108439a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 108539a53e0cSJaegeuk Kim } 108639a53e0cSJaegeuk Kim 108739a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 108839a53e0cSJaegeuk Kim { 108939a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 109039a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 109139a53e0cSJaegeuk Kim } 109239a53e0cSJaegeuk Kim 109339a53e0cSJaegeuk Kim static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag) 109439a53e0cSJaegeuk Kim { 109539a53e0cSJaegeuk Kim if (is_inode_flag_set(fi, FI_ACL_MODE)) { 109639a53e0cSJaegeuk Kim clear_inode_flag(fi, FI_ACL_MODE); 109739a53e0cSJaegeuk Kim return 1; 109839a53e0cSJaegeuk Kim } 109939a53e0cSJaegeuk Kim return 0; 110039a53e0cSJaegeuk Kim } 110139a53e0cSJaegeuk Kim 1102444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1103444c580fSJaegeuk Kim struct f2fs_inode *ri) 1104444c580fSJaegeuk Kim { 1105444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1106444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 11071001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 11081001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 1109*34d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1110*34d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1111444c580fSJaegeuk Kim } 1112444c580fSJaegeuk Kim 1113444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1114444c580fSJaegeuk Kim struct f2fs_inode *ri) 1115444c580fSJaegeuk Kim { 1116444c580fSJaegeuk Kim ri->i_inline = 0; 1117444c580fSJaegeuk Kim 1118444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1119444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 11201001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 11211001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 1122*34d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 1123*34d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1124444c580fSJaegeuk Kim } 1125444c580fSJaegeuk Kim 1126987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1127987c7c31SChao Yu { 1128987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1129987c7c31SChao Yu } 1130987c7c31SChao Yu 1131de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1132de93653fSJaegeuk Kim { 1133987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1134de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1135de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1136de93653fSJaegeuk Kim } 1137de93653fSJaegeuk Kim 113865985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 113965985d93SJaegeuk Kim { 1140695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 114165985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 114265985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 114365985d93SJaegeuk Kim } 114465985d93SJaegeuk Kim 114565985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 114665985d93SJaegeuk Kim { 1147987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 114865985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 114965985d93SJaegeuk Kim else 115065985d93SJaegeuk Kim return 0; 115165985d93SJaegeuk Kim } 115265985d93SJaegeuk Kim 11530dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 11540dbdc2aeSJaegeuk Kim { 11550dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 11560dbdc2aeSJaegeuk Kim } 11570dbdc2aeSJaegeuk Kim 115888b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 115988b88a66SJaegeuk Kim { 116088b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 116188b88a66SJaegeuk Kim } 116288b88a66SJaegeuk Kim 116302a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 116402a1335fSJaegeuk Kim { 116502a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 116602a1335fSJaegeuk Kim } 116702a1335fSJaegeuk Kim 11681001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 11691001b347SHuajun Li { 1170695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 11711001b347SHuajun Li return (void *)&(ri->i_addr[1]); 11721001b347SHuajun Li } 11731001b347SHuajun Li 1174*34d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 1175*34d67debSChao Yu { 1176*34d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 1177*34d67debSChao Yu } 1178*34d67debSChao Yu 1179*34d67debSChao Yu static inline void *inline_dentry_addr(struct page *page) 1180*34d67debSChao Yu { 1181*34d67debSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1182*34d67debSChao Yu return (void *)&(ri->i_addr[1]); 1183*34d67debSChao Yu } 1184*34d67debSChao Yu 118577888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 118677888c1eSJaegeuk Kim { 118777888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 118877888c1eSJaegeuk Kim } 118977888c1eSJaegeuk Kim 11901e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 11911e968fdfSJaegeuk Kim { 11921e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 11931e968fdfSJaegeuk Kim } 11941e968fdfSJaegeuk Kim 1195744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1196744602cfSJaegeuk Kim { 1197744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1198744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1199744602cfSJaegeuk Kim } 1200744602cfSJaegeuk Kim 1201a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1202a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1203a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1204a6dda0e6SChristoph Hellwig 1205267378d4SChao Yu /* get offset of first page in next direct node */ 1206267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1207267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1208267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1209267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1210267378d4SChao Yu 121139a53e0cSJaegeuk Kim /* 121239a53e0cSJaegeuk Kim * file.c 121339a53e0cSJaegeuk Kim */ 121439a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 121539a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1216764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 121739a53e0cSJaegeuk Kim void f2fs_truncate(struct inode *); 12182d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 121939a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 122039a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1221b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 122239a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1223e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 122439a53e0cSJaegeuk Kim 122539a53e0cSJaegeuk Kim /* 122639a53e0cSJaegeuk Kim * inode.c 122739a53e0cSJaegeuk Kim */ 122839a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 122939a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 12304660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 123139a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *); 1232744602cfSJaegeuk Kim void update_inode_page(struct inode *); 123339a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 123439a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 123544c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 123639a53e0cSJaegeuk Kim 123739a53e0cSJaegeuk Kim /* 123839a53e0cSJaegeuk Kim * namei.c 123939a53e0cSJaegeuk Kim */ 124039a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 124139a53e0cSJaegeuk Kim 124239a53e0cSJaegeuk Kim /* 124339a53e0cSJaegeuk Kim * dir.c 124439a53e0cSJaegeuk Kim */ 124539a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 124639a53e0cSJaegeuk Kim struct page **); 124739a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 124839a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 124939a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 125039a53e0cSJaegeuk Kim struct page *, struct inode *); 12511cd14cafSJaegeuk Kim int update_dent_inode(struct inode *, const struct qstr *); 1252b7f7a5e0SAl Viro int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *); 125339a53e0cSJaegeuk Kim void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *); 1254b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 125539a53e0cSJaegeuk Kim int f2fs_make_empty(struct inode *, struct inode *); 125639a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 125739a53e0cSJaegeuk Kim 1258b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1259b7f7a5e0SAl Viro { 1260b7f7a5e0SAl Viro return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name, 1261b7f7a5e0SAl Viro inode); 1262b7f7a5e0SAl Viro } 1263b7f7a5e0SAl Viro 126439a53e0cSJaegeuk Kim /* 126539a53e0cSJaegeuk Kim * super.c 126639a53e0cSJaegeuk Kim */ 126739a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1268a07ef784SNamjae Jeon extern __printf(3, 4) 1269a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 127039a53e0cSJaegeuk Kim 127139a53e0cSJaegeuk Kim /* 127239a53e0cSJaegeuk Kim * hash.c 127339a53e0cSJaegeuk Kim */ 1274eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 127539a53e0cSJaegeuk Kim 127639a53e0cSJaegeuk Kim /* 127739a53e0cSJaegeuk Kim * node.c 127839a53e0cSJaegeuk Kim */ 127939a53e0cSJaegeuk Kim struct dnode_of_data; 128039a53e0cSJaegeuk Kim struct node_info; 128139a53e0cSJaegeuk Kim 12826fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 128388bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 128488bd02c9SJaegeuk Kim bool has_fsynced_inode(struct f2fs_sb_info *, nid_t); 128588bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 128639a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 128739a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 128839a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 12894f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1290cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 129158e674d6SGu Zheng void remove_inode_page(struct inode *); 1292a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 12938ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 129439a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 129539a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 129639a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 129739a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 129839a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 129939a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 130039a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 130139a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 130270cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 13031c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 130439a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 130539a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 130639a53e0cSJaegeuk Kim struct f2fs_summary_block *); 130739a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 130839a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 130939a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 13106e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 131139a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 131239a53e0cSJaegeuk Kim 131339a53e0cSJaegeuk Kim /* 131439a53e0cSJaegeuk Kim * segment.c 131539a53e0cSJaegeuk Kim */ 131688b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 1317cbcb2872SJaegeuk Kim void invalidate_inmem_page(struct inode *, struct page *); 131888b88a66SJaegeuk Kim void commit_inmem_pages(struct inode *, bool); 131939a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *); 13204660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 13216b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 13222163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 13232163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 132439a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 13255e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 132639a53e0cSJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *); 13274b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1328cf2271e7SJaegeuk Kim void discard_next_dnode(struct f2fs_sb_info *, block_t); 132939a53e0cSJaegeuk Kim int npages_for_summary_flush(struct f2fs_sb_info *); 133039a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 13314b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 133239a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1333577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 1334fb5566daSJaegeuk Kim void write_node_page(struct f2fs_sb_info *, struct page *, 1335fb5566daSJaegeuk Kim struct f2fs_io_info *, unsigned int, block_t, block_t *); 1336458e6197SJaegeuk Kim void write_data_page(struct page *, struct dnode_of_data *, block_t *, 1337458e6197SJaegeuk Kim struct f2fs_io_info *); 1338458e6197SJaegeuk Kim void rewrite_data_page(struct page *, block_t, struct f2fs_io_info *); 133939a53e0cSJaegeuk Kim void recover_data_page(struct f2fs_sb_info *, struct page *, 134039a53e0cSJaegeuk Kim struct f2fs_summary *, block_t, block_t); 1341bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1342bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 13435514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 134439a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 134539a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 134639a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 134739a53e0cSJaegeuk Kim int, unsigned int, int); 13484b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 134939a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 135039a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 13517fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 13527fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 135339a53e0cSJaegeuk Kim 135439a53e0cSJaegeuk Kim /* 135539a53e0cSJaegeuk Kim * checkpoint.c 135639a53e0cSJaegeuk Kim */ 135739a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 135839a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 13594c521f49SJaegeuk Kim struct page *get_meta_page_ra(struct f2fs_sb_info *, pgoff_t); 13604c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int); 136139a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1362fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1363fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 13646f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *); 1365fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1366cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1367cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 136839a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 136939a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 13708f99a946SChao Yu void recover_orphan_inodes(struct f2fs_sb_info *); 137139a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1372a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 13735deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 137439a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *); 137539a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *); 137675ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 13776451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 13786e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 137939a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 138039a53e0cSJaegeuk Kim 138139a53e0cSJaegeuk Kim /* 138239a53e0cSJaegeuk Kim * data.c 138339a53e0cSJaegeuk Kim */ 1384458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 138593dfe2acSJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *, block_t, int); 138693dfe2acSJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *, block_t, 1387458e6197SJaegeuk Kim struct f2fs_io_info *); 138839a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1389b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 139039a53e0cSJaegeuk Kim void update_extent_cache(block_t, struct dnode_of_data *); 1391c718379bSJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t, bool); 139239a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t); 139364aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 1394458e6197SJaegeuk Kim int do_write_data_page(struct page *, struct f2fs_io_info *); 13959ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 139639a53e0cSJaegeuk Kim 139739a53e0cSJaegeuk Kim /* 139839a53e0cSJaegeuk Kim * gc.c 139939a53e0cSJaegeuk Kim */ 140039a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 140139a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1402de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1403408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *); 140439a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 14056e6093a8SNamjae Jeon int __init create_gc_caches(void); 140639a53e0cSJaegeuk Kim void destroy_gc_caches(void); 140739a53e0cSJaegeuk Kim 140839a53e0cSJaegeuk Kim /* 140939a53e0cSJaegeuk Kim * recovery.c 141039a53e0cSJaegeuk Kim */ 14116ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 141239a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 141339a53e0cSJaegeuk Kim 141439a53e0cSJaegeuk Kim /* 141539a53e0cSJaegeuk Kim * debug.c 141639a53e0cSJaegeuk Kim */ 141739a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 141839a53e0cSJaegeuk Kim struct f2fs_stat_info { 141939a53e0cSJaegeuk Kim struct list_head stat_list; 142039a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 142139a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 142239a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 142339a53e0cSJaegeuk Kim int hit_ext, total_ext; 142439a53e0cSJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 142539a53e0cSJaegeuk Kim int nats, sits, fnids; 142639a53e0cSJaegeuk Kim int total_count, utilization; 14270dbdc2aeSJaegeuk Kim int bg_gc, inline_inode; 142839a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 142939a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 143039a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 143139a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 143239a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1433942e0be6SChangman Lee int prefree_count, call_count, cp_count; 143439a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 143539a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 143639a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 143739a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 143839a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 143939a53e0cSJaegeuk Kim 144039a53e0cSJaegeuk Kim unsigned int segment_count[2]; 144139a53e0cSJaegeuk Kim unsigned int block_count[2]; 144239a53e0cSJaegeuk Kim unsigned base_mem, cache_mem; 144339a53e0cSJaegeuk Kim }; 144439a53e0cSJaegeuk Kim 1445963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1446963d4f7dSGu Zheng { 1447963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1448963d4f7dSGu Zheng } 1449963d4f7dSGu Zheng 1450942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 145139a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1452dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1453dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1454dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 1455dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++) 1456dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++) 14570dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 14580dbdc2aeSJaegeuk Kim do { \ 14590dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 14604081363fSJaegeuk Kim ((F2FS_I_SB(inode))->inline_inode++); \ 14610dbdc2aeSJaegeuk Kim } while (0) 14620dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 14630dbdc2aeSJaegeuk Kim do { \ 14640dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 14654081363fSJaegeuk Kim ((F2FS_I_SB(inode))->inline_inode--); \ 14660dbdc2aeSJaegeuk Kim } while (0) 14670dbdc2aeSJaegeuk Kim 1468dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1469dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1470dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1471dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 147239a53e0cSJaegeuk Kim 147339a53e0cSJaegeuk Kim #define stat_inc_seg_count(sbi, type) \ 147439a53e0cSJaegeuk Kim do { \ 1475963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 147639a53e0cSJaegeuk Kim (si)->tot_segs++; \ 147739a53e0cSJaegeuk Kim if (type == SUM_TYPE_DATA) \ 147839a53e0cSJaegeuk Kim si->data_segs++; \ 147939a53e0cSJaegeuk Kim else \ 148039a53e0cSJaegeuk Kim si->node_segs++; \ 148139a53e0cSJaegeuk Kim } while (0) 148239a53e0cSJaegeuk Kim 148339a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 148439a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 148539a53e0cSJaegeuk Kim 148639a53e0cSJaegeuk Kim #define stat_inc_data_blk_count(sbi, blks) \ 148739a53e0cSJaegeuk Kim do { \ 1488963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 148939a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 149039a53e0cSJaegeuk Kim si->data_blks += (blks); \ 149139a53e0cSJaegeuk Kim } while (0) 149239a53e0cSJaegeuk Kim 149339a53e0cSJaegeuk Kim #define stat_inc_node_blk_count(sbi, blks) \ 149439a53e0cSJaegeuk Kim do { \ 1495963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 149639a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 149739a53e0cSJaegeuk Kim si->node_blks += (blks); \ 149839a53e0cSJaegeuk Kim } while (0) 149939a53e0cSJaegeuk Kim 150039a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 150139a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 15026e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void); 15034589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 150439a53e0cSJaegeuk Kim #else 1505942e0be6SChangman Lee #define stat_inc_cp_count(si) 150639a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 1507dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 1508dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) 1509dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) 1510dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 1511dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) 15120dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 15130dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 1514dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 1515dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 151639a53e0cSJaegeuk Kim #define stat_inc_seg_count(si, type) 151739a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 151839a53e0cSJaegeuk Kim #define stat_inc_data_blk_count(si, blks) 151939a53e0cSJaegeuk Kim #define stat_inc_node_blk_count(sbi, blks) 152039a53e0cSJaegeuk Kim 152139a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 152239a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 15236e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { } 15244589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 152539a53e0cSJaegeuk Kim #endif 152639a53e0cSJaegeuk Kim 152739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 152839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 152939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 153039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 153139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 153239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 153339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 153439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 153539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 15361001b347SHuajun Li 1537e18c65b2SHuajun Li /* 1538e18c65b2SHuajun Li * inline.c 1539e18c65b2SHuajun Li */ 1540e18c65b2SHuajun Li bool f2fs_may_inline(struct inode *); 1541e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 1542b067ba1fSJaegeuk Kim int f2fs_convert_inline_data(struct inode *, pgoff_t, struct page *); 1543e18c65b2SHuajun Li int f2fs_write_inline_data(struct inode *, struct page *, unsigned int); 15448aa6f1c5SChao Yu void truncate_inline_data(struct inode *, u64); 15450342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 154639a53e0cSJaegeuk Kim #endif 1547