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 4934d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 5034d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 5134d67debSChao 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 */ 2157b3cd7d6SJaegeuk Kim /* for directory operations */ 2167b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 2177b3cd7d6SJaegeuk Kim const void *bitmap; 2187b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 2197b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 2207b3cd7d6SJaegeuk Kim int max; 2217b3cd7d6SJaegeuk Kim }; 2227b3cd7d6SJaegeuk Kim 2237b3cd7d6SJaegeuk Kim static inline void make_dentry_ptr(struct f2fs_dentry_ptr *d, 2247b3cd7d6SJaegeuk Kim void *src, int type) 2257b3cd7d6SJaegeuk Kim { 2267b3cd7d6SJaegeuk Kim if (type == 1) { 2277b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 2287b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 2297b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2307b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 2317b3cd7d6SJaegeuk Kim d->filename = t->filename; 2327b3cd7d6SJaegeuk Kim } else { 2337b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 2347b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 2357b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2367b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 2377b3cd7d6SJaegeuk Kim d->filename = t->filename; 2387b3cd7d6SJaegeuk Kim } 2397b3cd7d6SJaegeuk Kim } 2407b3cd7d6SJaegeuk Kim 241dbe6a5ffSJaegeuk Kim /* 242dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 243dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 244dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 24539a53e0cSJaegeuk Kim */ 246dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 247dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 248266e97a8SJaegeuk Kim enum { 249266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 250266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 251266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 252266e97a8SJaegeuk Kim * look up a node with readahead called 2534f4124d0SChao Yu * by get_data_block. 25439a53e0cSJaegeuk Kim */ 255266e97a8SJaegeuk Kim }; 256266e97a8SJaegeuk Kim 25739a53e0cSJaegeuk Kim #define F2FS_LINK_MAX 32000 /* maximum link count per file */ 25839a53e0cSJaegeuk Kim 259817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 260817202d9SChao Yu 26139a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 262c11abd1aSJaegeuk Kim #define F2FS_MIN_EXTENT_LEN 16 /* minimum extent length */ 263c11abd1aSJaegeuk Kim 26439a53e0cSJaegeuk Kim struct extent_info { 26539a53e0cSJaegeuk Kim rwlock_t ext_lock; /* rwlock for consistency */ 26639a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 26739a53e0cSJaegeuk Kim u32 blk_addr; /* start block address of the extent */ 268111d2495SMasanari Iida unsigned int len; /* length of the extent */ 26939a53e0cSJaegeuk Kim }; 27039a53e0cSJaegeuk Kim 27139a53e0cSJaegeuk Kim /* 27239a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 27339a53e0cSJaegeuk Kim */ 27439a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 275354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 27639a53e0cSJaegeuk Kim 277ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 278ab9fa662SJaegeuk Kim 27939a53e0cSJaegeuk Kim struct f2fs_inode_info { 28039a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 28139a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 28239a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 28338431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 28439a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 2856666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 28639a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 28739a53e0cSJaegeuk Kim 28839a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 28939a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 290d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 291a7ffdbe2SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 29239a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 29339a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 29439a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 295e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 29639a53e0cSJaegeuk Kim struct extent_info ext; /* in-memory extent cache entry */ 297ed57c27fSJaegeuk Kim struct dir_inode_entry *dirty_dir; /* the pointer of dirty dir */ 29888b88a66SJaegeuk Kim 29934ba94baSJaegeuk Kim struct radix_tree_root inmem_root; /* radix tree for inmem pages */ 30088b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 30188b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 30239a53e0cSJaegeuk Kim }; 30339a53e0cSJaegeuk Kim 30439a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 30539a53e0cSJaegeuk Kim struct f2fs_extent i_ext) 30639a53e0cSJaegeuk Kim { 30739a53e0cSJaegeuk Kim write_lock(&ext->ext_lock); 30839a53e0cSJaegeuk Kim ext->fofs = le32_to_cpu(i_ext.fofs); 30939a53e0cSJaegeuk Kim ext->blk_addr = le32_to_cpu(i_ext.blk_addr); 31039a53e0cSJaegeuk Kim ext->len = le32_to_cpu(i_ext.len); 31139a53e0cSJaegeuk Kim write_unlock(&ext->ext_lock); 31239a53e0cSJaegeuk Kim } 31339a53e0cSJaegeuk Kim 31439a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 31539a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 31639a53e0cSJaegeuk Kim { 31739a53e0cSJaegeuk Kim read_lock(&ext->ext_lock); 31839a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 31939a53e0cSJaegeuk Kim i_ext->blk_addr = cpu_to_le32(ext->blk_addr); 32039a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 32139a53e0cSJaegeuk Kim read_unlock(&ext->ext_lock); 32239a53e0cSJaegeuk Kim } 32339a53e0cSJaegeuk Kim 32439a53e0cSJaegeuk Kim struct f2fs_nm_info { 32539a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 32639a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 3277ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 32839a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 329cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 33039a53e0cSJaegeuk Kim 33139a53e0cSJaegeuk Kim /* NAT cache management */ 33239a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 333309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 33439a53e0cSJaegeuk Kim rwlock_t nat_tree_lock; /* protect nat_tree_lock */ 33539a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 336309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 337aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 33839a53e0cSJaegeuk Kim 33939a53e0cSJaegeuk Kim /* free node ids management */ 3408a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 34139a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 34239a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 34339a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 34439a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 34539a53e0cSJaegeuk Kim 34639a53e0cSJaegeuk Kim /* for checkpoint */ 34739a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 34839a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 34939a53e0cSJaegeuk Kim }; 35039a53e0cSJaegeuk Kim 35139a53e0cSJaegeuk Kim /* 35239a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 35339a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 35439a53e0cSJaegeuk Kim * by the data offset in a file. 35539a53e0cSJaegeuk Kim */ 35639a53e0cSJaegeuk Kim struct dnode_of_data { 35739a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 35839a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 35939a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 36039a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 36139a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 36239a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 36339a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 36439a53e0cSJaegeuk Kim }; 36539a53e0cSJaegeuk Kim 36639a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 36739a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 36839a53e0cSJaegeuk Kim { 369d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 37039a53e0cSJaegeuk Kim dn->inode = inode; 37139a53e0cSJaegeuk Kim dn->inode_page = ipage; 37239a53e0cSJaegeuk Kim dn->node_page = npage; 37339a53e0cSJaegeuk Kim dn->nid = nid; 37439a53e0cSJaegeuk Kim } 37539a53e0cSJaegeuk Kim 37639a53e0cSJaegeuk Kim /* 37739a53e0cSJaegeuk Kim * For SIT manager 37839a53e0cSJaegeuk Kim * 37939a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 38039a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 38139a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 38239a53e0cSJaegeuk Kim * respectively. 38339a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 38439a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 38539a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 38639a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 38739a53e0cSJaegeuk Kim * data and 8 for node logs. 38839a53e0cSJaegeuk Kim */ 38939a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 39039a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 39139a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 39239a53e0cSJaegeuk Kim 39339a53e0cSJaegeuk Kim enum { 39439a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 39539a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 39639a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 39739a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 39839a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 39939a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 40039a53e0cSJaegeuk Kim NO_CHECK_TYPE 40139a53e0cSJaegeuk Kim }; 40239a53e0cSJaegeuk Kim 4036b4afdd7SJaegeuk Kim struct flush_cmd { 4046b4afdd7SJaegeuk Kim struct completion wait; 405721bd4d5SGu Zheng struct llist_node llnode; 4066b4afdd7SJaegeuk Kim int ret; 4076b4afdd7SJaegeuk Kim }; 4086b4afdd7SJaegeuk Kim 409a688b9d9SGu Zheng struct flush_cmd_control { 410a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 411a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 412721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 413721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 414a688b9d9SGu Zheng }; 415a688b9d9SGu Zheng 41639a53e0cSJaegeuk Kim struct f2fs_sm_info { 41739a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 41839a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 41939a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 42039a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 42139a53e0cSJaegeuk Kim 42239a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 42339a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 42439a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 42539a53e0cSJaegeuk Kim 42639a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 42739a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 42839a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 42939a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 43081eb8d6eSJaegeuk Kim 43181eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 43281eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 4337fd9e544SJaegeuk Kim 4347fd9e544SJaegeuk Kim /* for small discard management */ 4357fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 4367fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 4377fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 438216fbd64SJaegeuk Kim 439184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 440184a5cd2SChao Yu 441216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 442216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 443c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 4446b4afdd7SJaegeuk Kim 4456b4afdd7SJaegeuk Kim /* for flush command control */ 446a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 447a688b9d9SGu Zheng 44839a53e0cSJaegeuk Kim }; 44939a53e0cSJaegeuk Kim 45039a53e0cSJaegeuk Kim /* 45139a53e0cSJaegeuk Kim * For superblock 45239a53e0cSJaegeuk Kim */ 45339a53e0cSJaegeuk Kim /* 45439a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 45539a53e0cSJaegeuk Kim * 45639a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 45739a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 45839a53e0cSJaegeuk Kim */ 45939a53e0cSJaegeuk Kim enum count_type { 46039a53e0cSJaegeuk Kim F2FS_WRITEBACK, 46139a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 46239a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 46339a53e0cSJaegeuk Kim F2FS_DIRTY_META, 46439a53e0cSJaegeuk Kim NR_COUNT_TYPE, 46539a53e0cSJaegeuk Kim }; 46639a53e0cSJaegeuk Kim 46739a53e0cSJaegeuk Kim /* 468e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 46939a53e0cSJaegeuk Kim * The available types are: 47039a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 47139a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 47239a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 47339a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 47439a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 47539a53e0cSJaegeuk Kim * with waiting the bio's completion 47639a53e0cSJaegeuk Kim * ... Only can be used with META. 47739a53e0cSJaegeuk Kim */ 4787d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 47939a53e0cSJaegeuk Kim enum page_type { 48039a53e0cSJaegeuk Kim DATA, 48139a53e0cSJaegeuk Kim NODE, 48239a53e0cSJaegeuk Kim META, 48339a53e0cSJaegeuk Kim NR_PAGE_TYPE, 48439a53e0cSJaegeuk Kim META_FLUSH, 48539a53e0cSJaegeuk Kim }; 48639a53e0cSJaegeuk Kim 487458e6197SJaegeuk Kim struct f2fs_io_info { 488458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 4897e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 490458e6197SJaegeuk Kim }; 491458e6197SJaegeuk Kim 49293dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 4931ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 494458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 4951ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 4961ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 497458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 498df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 4991ff7bd3bSJaegeuk Kim }; 5001ff7bd3bSJaegeuk Kim 50139a53e0cSJaegeuk Kim struct f2fs_sb_info { 50239a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 5035e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 50439a53e0cSJaegeuk Kim struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 50539a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 50639a53e0cSJaegeuk Kim int s_dirty; /* dirty flag for checkpoint */ 5072ae4c673SJaegeuk Kim bool need_fsck; /* need fsck.f2fs to fix */ 50839a53e0cSJaegeuk Kim 50939a53e0cSJaegeuk Kim /* for node-related operations */ 51039a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 51139a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 51239a53e0cSJaegeuk Kim 51339a53e0cSJaegeuk Kim /* for segment-related operations */ 51439a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 5151ff7bd3bSJaegeuk Kim 5161ff7bd3bSJaegeuk Kim /* for bio operations */ 517924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 5181ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 5191b1f559fSJaegeuk Kim struct completion *wait_io; /* for completion bios */ 52039a53e0cSJaegeuk Kim 52139a53e0cSJaegeuk Kim /* for checkpoint */ 52239a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 52339a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 52439936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 525e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 526b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 52739a53e0cSJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 528aabe5136SHaicheng Li bool por_doing; /* recovery is doing or not */ 529fb51b5efSChangman Lee wait_queue_head_t cp_wait; 53039a53e0cSJaegeuk Kim 5316451e041SJaegeuk Kim /* for inode management */ 53239efac41SJaegeuk Kim struct radix_tree_root ino_root[MAX_INO_ENTRY]; /* ino entry array */ 5336451e041SJaegeuk Kim spinlock_t ino_lock[MAX_INO_ENTRY]; /* for ino entry lock */ 5346451e041SJaegeuk Kim struct list_head ino_list[MAX_INO_ENTRY]; /* inode list head */ 5356451e041SJaegeuk Kim 5366451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 53739a53e0cSJaegeuk Kim unsigned int n_orphans; /* # of orphan inodes */ 5380d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 53939a53e0cSJaegeuk Kim 54039a53e0cSJaegeuk Kim /* for directory inode management */ 54139a53e0cSJaegeuk Kim struct list_head dir_inode_list; /* dir inode list */ 54239a53e0cSJaegeuk Kim spinlock_t dir_inode_lock; /* for dir inode list lock */ 54339a53e0cSJaegeuk Kim 54439a53e0cSJaegeuk Kim /* basic filesystem units */ 54539a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 54639a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 54739a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 54839a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 54939a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 55039a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 55139a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 55239a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 55339a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 55439a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 55539a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 55639a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 55739a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 55839a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 55939a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 560ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 56139a53e0cSJaegeuk Kim 56239a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 56339a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 56439a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 56539a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 56639a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 56739a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 56839a53e0cSJaegeuk Kim 56939a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 57039a53e0cSJaegeuk Kim 57139a53e0cSJaegeuk Kim /* for cleaning operations */ 57239a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 57339a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 5745ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 57539a53e0cSJaegeuk Kim 576b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 577b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 578b1c57c1cSJaegeuk Kim 57939a53e0cSJaegeuk Kim /* 58039a53e0cSJaegeuk Kim * for stat information. 58139a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 58239a53e0cSJaegeuk Kim */ 58335b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 58439a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 58539a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 58639a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 58739a53e0cSJaegeuk Kim int total_hit_ext, read_hit_ext; /* extent cache hit ratio */ 5880dbdc2aeSJaegeuk Kim int inline_inode; /* # of inline_data inodes */ 5893289c061SJaegeuk Kim int inline_dir; /* # of inline_dentry inodes */ 59039a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 59135b09d82SNamjae Jeon unsigned int n_dirty_dirs; /* # of dir inodes */ 59235b09d82SNamjae Jeon #endif 59335b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 59439a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 595b59d0baeSNamjae Jeon 596b59d0baeSNamjae Jeon /* For sysfs suppport */ 597b59d0baeSNamjae Jeon struct kobject s_kobj; 598b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 59939a53e0cSJaegeuk Kim }; 60039a53e0cSJaegeuk Kim 60139a53e0cSJaegeuk Kim /* 60239a53e0cSJaegeuk Kim * Inline functions 60339a53e0cSJaegeuk Kim */ 60439a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 60539a53e0cSJaegeuk Kim { 60639a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 60739a53e0cSJaegeuk Kim } 60839a53e0cSJaegeuk Kim 60939a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 61039a53e0cSJaegeuk Kim { 61139a53e0cSJaegeuk Kim return sb->s_fs_info; 61239a53e0cSJaegeuk Kim } 61339a53e0cSJaegeuk Kim 6144081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 6154081363fSJaegeuk Kim { 6164081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 6174081363fSJaegeuk Kim } 6184081363fSJaegeuk Kim 6194081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 6204081363fSJaegeuk Kim { 6214081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 6224081363fSJaegeuk Kim } 6234081363fSJaegeuk Kim 6244081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 6254081363fSJaegeuk Kim { 6264081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 6274081363fSJaegeuk Kim } 6284081363fSJaegeuk Kim 62939a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 63039a53e0cSJaegeuk Kim { 63139a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 63239a53e0cSJaegeuk Kim } 63339a53e0cSJaegeuk Kim 63439a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 63539a53e0cSJaegeuk Kim { 63639a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 63739a53e0cSJaegeuk Kim } 63839a53e0cSJaegeuk Kim 63945590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 64045590710SGu Zheng { 64145590710SGu Zheng return (struct f2fs_node *)page_address(page); 64245590710SGu Zheng } 64345590710SGu Zheng 64458bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 64558bfaf44SJaegeuk Kim { 64658bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 64758bfaf44SJaegeuk Kim } 64858bfaf44SJaegeuk Kim 64939a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 65039a53e0cSJaegeuk Kim { 65139a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 65239a53e0cSJaegeuk Kim } 65339a53e0cSJaegeuk Kim 65439a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 65539a53e0cSJaegeuk Kim { 65639a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 65739a53e0cSJaegeuk Kim } 65839a53e0cSJaegeuk Kim 65939a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 66039a53e0cSJaegeuk Kim { 66139a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 66239a53e0cSJaegeuk Kim } 66339a53e0cSJaegeuk Kim 66439a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 66539a53e0cSJaegeuk Kim { 66639a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 66739a53e0cSJaegeuk Kim } 66839a53e0cSJaegeuk Kim 66939a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 67039a53e0cSJaegeuk Kim { 67139a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 67239a53e0cSJaegeuk Kim } 67339a53e0cSJaegeuk Kim 6749df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 6759df27d98SGu Zheng { 6769df27d98SGu Zheng return sbi->meta_inode->i_mapping; 6779df27d98SGu Zheng } 6789df27d98SGu Zheng 6794ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 6804ef51a8fSJaegeuk Kim { 6814ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 6824ef51a8fSJaegeuk Kim } 6834ef51a8fSJaegeuk Kim 68439a53e0cSJaegeuk Kim static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi) 68539a53e0cSJaegeuk Kim { 68639a53e0cSJaegeuk Kim sbi->s_dirty = 1; 68739a53e0cSJaegeuk Kim } 68839a53e0cSJaegeuk Kim 68939a53e0cSJaegeuk Kim static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi) 69039a53e0cSJaegeuk Kim { 69139a53e0cSJaegeuk Kim sbi->s_dirty = 0; 69239a53e0cSJaegeuk Kim } 69339a53e0cSJaegeuk Kim 694d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 695d71b5564SJaegeuk Kim { 696d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 697d71b5564SJaegeuk Kim } 698d71b5564SJaegeuk Kim 69925ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 70025ca923bSJaegeuk Kim { 70125ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 70225ca923bSJaegeuk Kim return ckpt_flags & f; 70325ca923bSJaegeuk Kim } 70425ca923bSJaegeuk Kim 70525ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 70625ca923bSJaegeuk Kim { 70725ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 70825ca923bSJaegeuk Kim ckpt_flags |= f; 70925ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 71025ca923bSJaegeuk Kim } 71125ca923bSJaegeuk Kim 71225ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 71325ca923bSJaegeuk Kim { 71425ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 71525ca923bSJaegeuk Kim ckpt_flags &= (~f); 71625ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 71725ca923bSJaegeuk Kim } 71825ca923bSJaegeuk Kim 719e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 72039a53e0cSJaegeuk Kim { 721e479556bSGu Zheng down_read(&sbi->cp_rwsem); 72239a53e0cSJaegeuk Kim } 72339a53e0cSJaegeuk Kim 724e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 72539a53e0cSJaegeuk Kim { 726e479556bSGu Zheng up_read(&sbi->cp_rwsem); 72739936837SJaegeuk Kim } 72839936837SJaegeuk Kim 729e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 73039936837SJaegeuk Kim { 7310daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 73239936837SJaegeuk Kim } 73339936837SJaegeuk Kim 734e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 73539936837SJaegeuk Kim { 736e479556bSGu Zheng up_write(&sbi->cp_rwsem); 73739a53e0cSJaegeuk Kim } 73839a53e0cSJaegeuk Kim 73939a53e0cSJaegeuk Kim /* 74039a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 74139a53e0cSJaegeuk Kim */ 742064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 74339a53e0cSJaegeuk Kim { 744d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 745d6b7d4b3SChao Yu return -EINVAL; 746cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 747064e0823SNamjae Jeon return -EINVAL; 748064e0823SNamjae Jeon return 0; 74939a53e0cSJaegeuk Kim } 75039a53e0cSJaegeuk Kim 75139a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 75239a53e0cSJaegeuk Kim 75339a53e0cSJaegeuk Kim /* 75439a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 75539a53e0cSJaegeuk Kim */ 75639a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 75739a53e0cSJaegeuk Kim { 75839a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 7596c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 76039a53e0cSJaegeuk Kim else 7616c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 76239a53e0cSJaegeuk Kim } 76339a53e0cSJaegeuk Kim 7644bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 7654bc8e9bcSChao Yu { 7664bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 7674bc8e9bcSChao Yu } 7684bc8e9bcSChao Yu 76939a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 77039a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 77139a53e0cSJaegeuk Kim { 77239a53e0cSJaegeuk Kim block_t valid_block_count; 77339a53e0cSJaegeuk Kim 77439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 77539a53e0cSJaegeuk Kim valid_block_count = 77639a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 777cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 77839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 77939a53e0cSJaegeuk Kim return false; 78039a53e0cSJaegeuk Kim } 78139a53e0cSJaegeuk Kim inode->i_blocks += count; 78239a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 78339a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 78439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 78539a53e0cSJaegeuk Kim return true; 78639a53e0cSJaegeuk Kim } 78739a53e0cSJaegeuk Kim 788da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 78939a53e0cSJaegeuk Kim struct inode *inode, 79039a53e0cSJaegeuk Kim blkcnt_t count) 79139a53e0cSJaegeuk Kim { 79239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 7939850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 7949850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 79539a53e0cSJaegeuk Kim inode->i_blocks -= count; 79639a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 79739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 79839a53e0cSJaegeuk Kim } 79939a53e0cSJaegeuk Kim 80039a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 80139a53e0cSJaegeuk Kim { 80239a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 80339a53e0cSJaegeuk Kim F2FS_SET_SB_DIRT(sbi); 80439a53e0cSJaegeuk Kim } 80539a53e0cSJaegeuk Kim 806a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 80739a53e0cSJaegeuk Kim { 808a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 809a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 8104081363fSJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 81139a53e0cSJaegeuk Kim } 81239a53e0cSJaegeuk Kim 81339a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 81439a53e0cSJaegeuk Kim { 81539a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 81639a53e0cSJaegeuk Kim } 81739a53e0cSJaegeuk Kim 818a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 81939a53e0cSJaegeuk Kim { 820a7ffdbe2SJaegeuk Kim if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)) 8211fe54f9dSJaegeuk Kim return; 8221fe54f9dSJaegeuk Kim 823a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 824a7ffdbe2SJaegeuk Kim 825a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 8264081363fSJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 82739a53e0cSJaegeuk Kim } 82839a53e0cSJaegeuk Kim 82939a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 83039a53e0cSJaegeuk Kim { 83139a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 83239a53e0cSJaegeuk Kim } 83339a53e0cSJaegeuk Kim 834a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 835f8b2c1f9SJaegeuk Kim { 836a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 837f8b2c1f9SJaegeuk Kim } 838f8b2c1f9SJaegeuk Kim 8395ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 8405ac206cfSNamjae Jeon { 8415ac206cfSNamjae Jeon unsigned int pages_per_sec = sbi->segs_per_sec * 8425ac206cfSNamjae Jeon (1 << sbi->log_blocks_per_seg); 8435ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 8445ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 8455ac206cfSNamjae Jeon } 8465ac206cfSNamjae Jeon 84739a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 84839a53e0cSJaegeuk Kim { 8498b8343faSJaegeuk Kim return sbi->total_valid_block_count; 85039a53e0cSJaegeuk Kim } 85139a53e0cSJaegeuk Kim 85239a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 85339a53e0cSJaegeuk Kim { 85439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 85539a53e0cSJaegeuk Kim 85639a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 85739a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 85839a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 85939a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 86039a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 86139a53e0cSJaegeuk Kim 86239a53e0cSJaegeuk Kim return 0; 86339a53e0cSJaegeuk Kim } 86439a53e0cSJaegeuk Kim 86539a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 86639a53e0cSJaegeuk Kim { 86739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 8681dbe4152SChangman Lee int offset; 8691dbe4152SChangman Lee 8701dbe4152SChangman Lee if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload) > 0) { 8711dbe4152SChangman Lee if (flag == NAT_BITMAP) 8721dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 8731dbe4152SChangman Lee else 87465b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 8751dbe4152SChangman Lee } else { 8761dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 87725ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 87839a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 87939a53e0cSJaegeuk Kim } 8801dbe4152SChangman Lee } 88139a53e0cSJaegeuk Kim 88239a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 88339a53e0cSJaegeuk Kim { 88439a53e0cSJaegeuk Kim block_t start_addr; 88539a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 886d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 88739a53e0cSJaegeuk Kim 88825ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 88939a53e0cSJaegeuk Kim 89039a53e0cSJaegeuk Kim /* 89139a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 892e1c42045Sarter97 * and even segment must be at cp segment 1 89339a53e0cSJaegeuk Kim */ 89439a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 89539a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 89639a53e0cSJaegeuk Kim 89739a53e0cSJaegeuk Kim return start_addr; 89839a53e0cSJaegeuk Kim } 89939a53e0cSJaegeuk Kim 90039a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 90139a53e0cSJaegeuk Kim { 90239a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 90339a53e0cSJaegeuk Kim } 90439a53e0cSJaegeuk Kim 90539a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 906ef86d709SGu Zheng struct inode *inode) 90739a53e0cSJaegeuk Kim { 90839a53e0cSJaegeuk Kim block_t valid_block_count; 90939a53e0cSJaegeuk Kim unsigned int valid_node_count; 91039a53e0cSJaegeuk Kim 91139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 91239a53e0cSJaegeuk Kim 913ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 914cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 91539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 91639a53e0cSJaegeuk Kim return false; 91739a53e0cSJaegeuk Kim } 91839a53e0cSJaegeuk Kim 919ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 920cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 92139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 92239a53e0cSJaegeuk Kim return false; 92339a53e0cSJaegeuk Kim } 92439a53e0cSJaegeuk Kim 92539a53e0cSJaegeuk Kim if (inode) 926ef86d709SGu Zheng inode->i_blocks++; 927ef86d709SGu Zheng 928ef86d709SGu Zheng sbi->alloc_valid_block_count++; 929ef86d709SGu Zheng sbi->total_valid_node_count++; 930ef86d709SGu Zheng sbi->total_valid_block_count++; 93139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 93239a53e0cSJaegeuk Kim 93339a53e0cSJaegeuk Kim return true; 93439a53e0cSJaegeuk Kim } 93539a53e0cSJaegeuk Kim 93639a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 937ef86d709SGu Zheng struct inode *inode) 93839a53e0cSJaegeuk Kim { 93939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 94039a53e0cSJaegeuk Kim 9419850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 9429850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 9439850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 94439a53e0cSJaegeuk Kim 945ef86d709SGu Zheng inode->i_blocks--; 946ef86d709SGu Zheng sbi->total_valid_node_count--; 947ef86d709SGu Zheng sbi->total_valid_block_count--; 94839a53e0cSJaegeuk Kim 94939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 95039a53e0cSJaegeuk Kim } 95139a53e0cSJaegeuk Kim 95239a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 95339a53e0cSJaegeuk Kim { 9548b8343faSJaegeuk Kim return sbi->total_valid_node_count; 95539a53e0cSJaegeuk Kim } 95639a53e0cSJaegeuk Kim 95739a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 95839a53e0cSJaegeuk Kim { 95939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 9609850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 96139a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 96239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 96339a53e0cSJaegeuk Kim } 96439a53e0cSJaegeuk Kim 9650e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 96639a53e0cSJaegeuk Kim { 96739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 9689850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 96939a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 97039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 97139a53e0cSJaegeuk Kim } 97239a53e0cSJaegeuk Kim 97339a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 97439a53e0cSJaegeuk Kim { 9758b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 97639a53e0cSJaegeuk Kim } 97739a53e0cSJaegeuk Kim 97839a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 97939a53e0cSJaegeuk Kim { 980031fa8ccSJaegeuk Kim if (!page) 98139a53e0cSJaegeuk Kim return; 98239a53e0cSJaegeuk Kim 98339a53e0cSJaegeuk Kim if (unlock) { 9849850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 98539a53e0cSJaegeuk Kim unlock_page(page); 98639a53e0cSJaegeuk Kim } 98739a53e0cSJaegeuk Kim page_cache_release(page); 98839a53e0cSJaegeuk Kim } 98939a53e0cSJaegeuk Kim 99039a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 99139a53e0cSJaegeuk Kim { 99239a53e0cSJaegeuk Kim if (dn->node_page) 99339a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 99439a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 99539a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 99639a53e0cSJaegeuk Kim dn->node_page = NULL; 99739a53e0cSJaegeuk Kim dn->inode_page = NULL; 99839a53e0cSJaegeuk Kim } 99939a53e0cSJaegeuk Kim 100039a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1001e8512d2eSGu Zheng size_t size) 100239a53e0cSJaegeuk Kim { 1003e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 100439a53e0cSJaegeuk Kim } 100539a53e0cSJaegeuk Kim 10067bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 10077bd59381SGu Zheng gfp_t flags) 10087bd59381SGu Zheng { 10097bd59381SGu Zheng void *entry; 10107bd59381SGu Zheng retry: 10117bd59381SGu Zheng entry = kmem_cache_alloc(cachep, flags); 10127bd59381SGu Zheng if (!entry) { 10137bd59381SGu Zheng cond_resched(); 10147bd59381SGu Zheng goto retry; 10157bd59381SGu Zheng } 10167bd59381SGu Zheng 10177bd59381SGu Zheng return entry; 10187bd59381SGu Zheng } 10197bd59381SGu Zheng 102039a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 102139a53e0cSJaegeuk Kim 102239a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 102339a53e0cSJaegeuk Kim { 102445590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 102539a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 102639a53e0cSJaegeuk Kim } 102739a53e0cSJaegeuk Kim 102839a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 102939a53e0cSJaegeuk Kim { 103039a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 103139a53e0cSJaegeuk Kim } 103239a53e0cSJaegeuk Kim 103339a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 103439a53e0cSJaegeuk Kim unsigned int offset) 103539a53e0cSJaegeuk Kim { 103639a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 103739a53e0cSJaegeuk Kim __le32 *addr_array; 103845590710SGu Zheng raw_node = F2FS_NODE(node_page); 103939a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 104039a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 104139a53e0cSJaegeuk Kim } 104239a53e0cSJaegeuk Kim 104339a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 104439a53e0cSJaegeuk Kim { 104539a53e0cSJaegeuk Kim int mask; 104639a53e0cSJaegeuk Kim 104739a53e0cSJaegeuk Kim addr += (nr >> 3); 104839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 104939a53e0cSJaegeuk Kim return mask & *addr; 105039a53e0cSJaegeuk Kim } 105139a53e0cSJaegeuk Kim 105239a53e0cSJaegeuk Kim static inline int f2fs_set_bit(unsigned int nr, char *addr) 105339a53e0cSJaegeuk Kim { 105439a53e0cSJaegeuk Kim int mask; 105539a53e0cSJaegeuk Kim int ret; 105639a53e0cSJaegeuk Kim 105739a53e0cSJaegeuk Kim addr += (nr >> 3); 105839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 105939a53e0cSJaegeuk Kim ret = mask & *addr; 106039a53e0cSJaegeuk Kim *addr |= mask; 106139a53e0cSJaegeuk Kim return ret; 106239a53e0cSJaegeuk Kim } 106339a53e0cSJaegeuk Kim 106439a53e0cSJaegeuk Kim static inline int f2fs_clear_bit(unsigned int nr, char *addr) 106539a53e0cSJaegeuk Kim { 106639a53e0cSJaegeuk Kim int mask; 106739a53e0cSJaegeuk Kim int ret; 106839a53e0cSJaegeuk Kim 106939a53e0cSJaegeuk Kim addr += (nr >> 3); 107039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 107139a53e0cSJaegeuk Kim ret = mask & *addr; 107239a53e0cSJaegeuk Kim *addr &= ~mask; 107339a53e0cSJaegeuk Kim return ret; 107439a53e0cSJaegeuk Kim } 107539a53e0cSJaegeuk Kim 1076*c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1077*c6ac4c0eSGu Zheng { 1078*c6ac4c0eSGu Zheng int mask; 1079*c6ac4c0eSGu Zheng 1080*c6ac4c0eSGu Zheng addr += (nr >> 3); 1081*c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1082*c6ac4c0eSGu Zheng *addr ^= mask; 1083*c6ac4c0eSGu Zheng } 1084*c6ac4c0eSGu Zheng 108539a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 108639a53e0cSJaegeuk Kim enum { 108739a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1088b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1089ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 109039a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 109139a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 109239a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1093699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 109474d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1095c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1096444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 10971001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 109834d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1099fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1100fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 110188b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 110288b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 110302a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 110439a53e0cSJaegeuk Kim }; 110539a53e0cSJaegeuk Kim 110639a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 110739a53e0cSJaegeuk Kim { 110861e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 110939a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 111039a53e0cSJaegeuk Kim } 111139a53e0cSJaegeuk Kim 111239a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 111339a53e0cSJaegeuk Kim { 111439a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 111539a53e0cSJaegeuk Kim } 111639a53e0cSJaegeuk Kim 111739a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 111839a53e0cSJaegeuk Kim { 111961e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 112039a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 112139a53e0cSJaegeuk Kim } 112239a53e0cSJaegeuk Kim 112339a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 112439a53e0cSJaegeuk Kim { 112539a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 112639a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 112739a53e0cSJaegeuk Kim } 112839a53e0cSJaegeuk Kim 1129444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1130444c580fSJaegeuk Kim struct f2fs_inode *ri) 1131444c580fSJaegeuk Kim { 1132444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1133444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 11341001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 11351001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 113634d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 113734d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1138444c580fSJaegeuk Kim } 1139444c580fSJaegeuk Kim 1140444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1141444c580fSJaegeuk Kim struct f2fs_inode *ri) 1142444c580fSJaegeuk Kim { 1143444c580fSJaegeuk Kim ri->i_inline = 0; 1144444c580fSJaegeuk Kim 1145444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1146444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 11471001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 11481001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 114934d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 115034d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1151444c580fSJaegeuk Kim } 1152444c580fSJaegeuk Kim 1153987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1154987c7c31SChao Yu { 1155987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1156987c7c31SChao Yu } 1157987c7c31SChao Yu 1158de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1159de93653fSJaegeuk Kim { 1160987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1161de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1162de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1163de93653fSJaegeuk Kim } 1164de93653fSJaegeuk Kim 116565985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 116665985d93SJaegeuk Kim { 1167695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 116865985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 116965985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 117065985d93SJaegeuk Kim } 117165985d93SJaegeuk Kim 117265985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 117365985d93SJaegeuk Kim { 1174987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 117565985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 117665985d93SJaegeuk Kim else 117765985d93SJaegeuk Kim return 0; 117865985d93SJaegeuk Kim } 117965985d93SJaegeuk Kim 11800dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 11810dbdc2aeSJaegeuk Kim { 11820dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 11830dbdc2aeSJaegeuk Kim } 11840dbdc2aeSJaegeuk Kim 118588b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 118688b88a66SJaegeuk Kim { 118788b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 118888b88a66SJaegeuk Kim } 118988b88a66SJaegeuk Kim 119002a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 119102a1335fSJaegeuk Kim { 119202a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 119302a1335fSJaegeuk Kim } 119402a1335fSJaegeuk Kim 11951001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 11961001b347SHuajun Li { 1197695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 11981001b347SHuajun Li return (void *)&(ri->i_addr[1]); 11991001b347SHuajun Li } 12001001b347SHuajun Li 120134d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 120234d67debSChao Yu { 120334d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 120434d67debSChao Yu } 120534d67debSChao Yu 120634d67debSChao Yu static inline void *inline_dentry_addr(struct page *page) 120734d67debSChao Yu { 120834d67debSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 120934d67debSChao Yu return (void *)&(ri->i_addr[1]); 121034d67debSChao Yu } 121134d67debSChao Yu 121277888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 121377888c1eSJaegeuk Kim { 121477888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 121577888c1eSJaegeuk Kim } 121677888c1eSJaegeuk Kim 12171e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 12181e968fdfSJaegeuk Kim { 12191e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 12201e968fdfSJaegeuk Kim } 12211e968fdfSJaegeuk Kim 1222744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1223744602cfSJaegeuk Kim { 1224744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1225744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1226744602cfSJaegeuk Kim } 1227744602cfSJaegeuk Kim 1228a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1229a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1230a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1231a6dda0e6SChristoph Hellwig 1232267378d4SChao Yu /* get offset of first page in next direct node */ 1233267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1234267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1235267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1236267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1237267378d4SChao Yu 123839a53e0cSJaegeuk Kim /* 123939a53e0cSJaegeuk Kim * file.c 124039a53e0cSJaegeuk Kim */ 124139a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 124239a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1243764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 124439a53e0cSJaegeuk Kim void f2fs_truncate(struct inode *); 12452d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 124639a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 124739a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1248b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 124939a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1250e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 125139a53e0cSJaegeuk Kim 125239a53e0cSJaegeuk Kim /* 125339a53e0cSJaegeuk Kim * inode.c 125439a53e0cSJaegeuk Kim */ 125539a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 125639a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 12574660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 125839a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *); 1259744602cfSJaegeuk Kim void update_inode_page(struct inode *); 126039a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 126139a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 126244c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 126339a53e0cSJaegeuk Kim 126439a53e0cSJaegeuk Kim /* 126539a53e0cSJaegeuk Kim * namei.c 126639a53e0cSJaegeuk Kim */ 126739a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 126839a53e0cSJaegeuk Kim 126939a53e0cSJaegeuk Kim /* 127039a53e0cSJaegeuk Kim * dir.c 127139a53e0cSJaegeuk Kim */ 1272dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1273dbeacf02SChao Yu void set_de_type(struct f2fs_dir_entry *, struct inode *); 12747b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct qstr *, int *, 12757b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr *); 12767b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 12777b3cd7d6SJaegeuk Kim unsigned int); 1278062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1279062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1280dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1281bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1282dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1283a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1284dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 128539a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 128639a53e0cSJaegeuk Kim struct page **); 128739a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 128839a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 128939a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 129039a53e0cSJaegeuk Kim struct page *, struct inode *); 12911cd14cafSJaegeuk Kim int update_dent_inode(struct inode *, const struct qstr *); 1292b7f7a5e0SAl Viro int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *); 1293dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1294dbeacf02SChao Yu struct inode *); 1295b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 129639a53e0cSJaegeuk Kim int f2fs_make_empty(struct inode *, struct inode *); 129739a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 129839a53e0cSJaegeuk Kim 1299b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1300b7f7a5e0SAl Viro { 1301b7f7a5e0SAl Viro return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name, 1302b7f7a5e0SAl Viro inode); 1303b7f7a5e0SAl Viro } 1304b7f7a5e0SAl Viro 130539a53e0cSJaegeuk Kim /* 130639a53e0cSJaegeuk Kim * super.c 130739a53e0cSJaegeuk Kim */ 130839a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1309a07ef784SNamjae Jeon extern __printf(3, 4) 1310a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 131139a53e0cSJaegeuk Kim 131239a53e0cSJaegeuk Kim /* 131339a53e0cSJaegeuk Kim * hash.c 131439a53e0cSJaegeuk Kim */ 1315eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 131639a53e0cSJaegeuk Kim 131739a53e0cSJaegeuk Kim /* 131839a53e0cSJaegeuk Kim * node.c 131939a53e0cSJaegeuk Kim */ 132039a53e0cSJaegeuk Kim struct dnode_of_data; 132139a53e0cSJaegeuk Kim struct node_info; 132239a53e0cSJaegeuk Kim 13236fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 132488bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 132588bd02c9SJaegeuk Kim bool has_fsynced_inode(struct f2fs_sb_info *, nid_t); 132688bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 132739a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 132839a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 132939a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 13304f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1331cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 133258e674d6SGu Zheng void remove_inode_page(struct inode *); 1333a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 13348ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 133539a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 133639a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 133739a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 133839a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 133939a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 134039a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 134139a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 134239a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 134370cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 13441c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 134539a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 134639a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 134739a53e0cSJaegeuk Kim struct f2fs_summary_block *); 134839a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 134939a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 135039a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 13516e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 135239a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 135339a53e0cSJaegeuk Kim 135439a53e0cSJaegeuk Kim /* 135539a53e0cSJaegeuk Kim * segment.c 135639a53e0cSJaegeuk Kim */ 135788b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 1358cbcb2872SJaegeuk Kim void invalidate_inmem_page(struct inode *, struct page *); 135988b88a66SJaegeuk Kim void commit_inmem_pages(struct inode *, bool); 136039a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *); 13614660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 13626b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 13632163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 13642163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 136539a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 13665e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 136739a53e0cSJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *); 13684b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1369cf2271e7SJaegeuk Kim void discard_next_dnode(struct f2fs_sb_info *, block_t); 137039a53e0cSJaegeuk Kim int npages_for_summary_flush(struct f2fs_sb_info *); 137139a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 13724b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 137339a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1374577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 1375fb5566daSJaegeuk Kim void write_node_page(struct f2fs_sb_info *, struct page *, 1376fb5566daSJaegeuk Kim struct f2fs_io_info *, unsigned int, block_t, block_t *); 1377458e6197SJaegeuk Kim void write_data_page(struct page *, struct dnode_of_data *, block_t *, 1378458e6197SJaegeuk Kim struct f2fs_io_info *); 1379458e6197SJaegeuk Kim void rewrite_data_page(struct page *, block_t, struct f2fs_io_info *); 138039a53e0cSJaegeuk Kim void recover_data_page(struct f2fs_sb_info *, struct page *, 138139a53e0cSJaegeuk Kim struct f2fs_summary *, block_t, block_t); 1382bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1383bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 13845514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 138539a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 138639a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 138739a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 138839a53e0cSJaegeuk Kim int, unsigned int, int); 13894b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 139039a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 139139a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 13927fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 13937fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 139439a53e0cSJaegeuk Kim 139539a53e0cSJaegeuk Kim /* 139639a53e0cSJaegeuk Kim * checkpoint.c 139739a53e0cSJaegeuk Kim */ 139839a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 139939a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 14004c521f49SJaegeuk Kim struct page *get_meta_page_ra(struct f2fs_sb_info *, pgoff_t); 14014c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int); 140239a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1403fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1404fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 14056f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *); 1406fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1407cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1408cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 140939a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 141039a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 14118f99a946SChao Yu void recover_orphan_inodes(struct f2fs_sb_info *); 141239a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1413a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 14145deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 141539a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *); 141639a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *); 141775ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 14186451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 14196e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 142039a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 142139a53e0cSJaegeuk Kim 142239a53e0cSJaegeuk Kim /* 142339a53e0cSJaegeuk Kim * data.c 142439a53e0cSJaegeuk Kim */ 1425458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 142693dfe2acSJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *, block_t, int); 142793dfe2acSJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *, block_t, 1428458e6197SJaegeuk Kim struct f2fs_io_info *); 142939a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1430b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 143139a53e0cSJaegeuk Kim void update_extent_cache(block_t, struct dnode_of_data *); 1432c718379bSJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t, bool); 143339a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t); 143464aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 1435458e6197SJaegeuk Kim int do_write_data_page(struct page *, struct f2fs_io_info *); 14369ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 143739a53e0cSJaegeuk Kim 143839a53e0cSJaegeuk Kim /* 143939a53e0cSJaegeuk Kim * gc.c 144039a53e0cSJaegeuk Kim */ 144139a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 144239a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1443de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1444408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *); 144539a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 14466e6093a8SNamjae Jeon int __init create_gc_caches(void); 144739a53e0cSJaegeuk Kim void destroy_gc_caches(void); 144839a53e0cSJaegeuk Kim 144939a53e0cSJaegeuk Kim /* 145039a53e0cSJaegeuk Kim * recovery.c 145139a53e0cSJaegeuk Kim */ 14526ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 145339a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 145439a53e0cSJaegeuk Kim 145539a53e0cSJaegeuk Kim /* 145639a53e0cSJaegeuk Kim * debug.c 145739a53e0cSJaegeuk Kim */ 145839a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 145939a53e0cSJaegeuk Kim struct f2fs_stat_info { 146039a53e0cSJaegeuk Kim struct list_head stat_list; 146139a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 146239a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 146339a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 146439a53e0cSJaegeuk Kim int hit_ext, total_ext; 146539a53e0cSJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 146639a53e0cSJaegeuk Kim int nats, sits, fnids; 146739a53e0cSJaegeuk Kim int total_count, utilization; 14683289c061SJaegeuk Kim int bg_gc, inline_inode, inline_dir; 146939a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 147039a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 147139a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 147239a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 147339a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1474942e0be6SChangman Lee int prefree_count, call_count, cp_count; 147539a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 147639a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 147739a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 147839a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 147939a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 148039a53e0cSJaegeuk Kim 148139a53e0cSJaegeuk Kim unsigned int segment_count[2]; 148239a53e0cSJaegeuk Kim unsigned int block_count[2]; 148339a53e0cSJaegeuk Kim unsigned base_mem, cache_mem; 148439a53e0cSJaegeuk Kim }; 148539a53e0cSJaegeuk Kim 1486963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1487963d4f7dSGu Zheng { 1488963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1489963d4f7dSGu Zheng } 1490963d4f7dSGu Zheng 1491942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 149239a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1493dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1494dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1495dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 1496dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++) 1497dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++) 14980dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 14990dbdc2aeSJaegeuk Kim do { \ 15000dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 15014081363fSJaegeuk Kim ((F2FS_I_SB(inode))->inline_inode++); \ 15020dbdc2aeSJaegeuk Kim } while (0) 15030dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 15040dbdc2aeSJaegeuk Kim do { \ 15050dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 15064081363fSJaegeuk Kim ((F2FS_I_SB(inode))->inline_inode--); \ 15070dbdc2aeSJaegeuk Kim } while (0) 15083289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 15093289c061SJaegeuk Kim do { \ 15103289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 15113289c061SJaegeuk Kim ((F2FS_I_SB(inode))->inline_dir++); \ 15123289c061SJaegeuk Kim } while (0) 15133289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 15143289c061SJaegeuk Kim do { \ 15153289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 15163289c061SJaegeuk Kim ((F2FS_I_SB(inode))->inline_dir--); \ 15173289c061SJaegeuk Kim } while (0) 1518dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1519dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1520dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1521dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 152239a53e0cSJaegeuk Kim 152339a53e0cSJaegeuk Kim #define stat_inc_seg_count(sbi, type) \ 152439a53e0cSJaegeuk Kim do { \ 1525963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 152639a53e0cSJaegeuk Kim (si)->tot_segs++; \ 152739a53e0cSJaegeuk Kim if (type == SUM_TYPE_DATA) \ 152839a53e0cSJaegeuk Kim si->data_segs++; \ 152939a53e0cSJaegeuk Kim else \ 153039a53e0cSJaegeuk Kim si->node_segs++; \ 153139a53e0cSJaegeuk Kim } while (0) 153239a53e0cSJaegeuk Kim 153339a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 153439a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 153539a53e0cSJaegeuk Kim 153639a53e0cSJaegeuk Kim #define stat_inc_data_blk_count(sbi, blks) \ 153739a53e0cSJaegeuk Kim do { \ 1538963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 153939a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 154039a53e0cSJaegeuk Kim si->data_blks += (blks); \ 154139a53e0cSJaegeuk Kim } while (0) 154239a53e0cSJaegeuk Kim 154339a53e0cSJaegeuk Kim #define stat_inc_node_blk_count(sbi, blks) \ 154439a53e0cSJaegeuk Kim do { \ 1545963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 154639a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 154739a53e0cSJaegeuk Kim si->node_blks += (blks); \ 154839a53e0cSJaegeuk Kim } while (0) 154939a53e0cSJaegeuk Kim 155039a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 155139a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 15526e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void); 15534589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 155439a53e0cSJaegeuk Kim #else 1555942e0be6SChangman Lee #define stat_inc_cp_count(si) 155639a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 1557dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 1558dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) 1559dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) 1560dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 1561dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) 15620dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 15630dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 15643289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 15653289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 1566dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 1567dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 156839a53e0cSJaegeuk Kim #define stat_inc_seg_count(si, type) 156939a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 157039a53e0cSJaegeuk Kim #define stat_inc_data_blk_count(si, blks) 157139a53e0cSJaegeuk Kim #define stat_inc_node_blk_count(sbi, blks) 157239a53e0cSJaegeuk Kim 157339a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 157439a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 15756e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { } 15764589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 157739a53e0cSJaegeuk Kim #endif 157839a53e0cSJaegeuk Kim 157939a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 158039a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 158139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 158239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 158339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 158439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 158539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 158639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 158739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 15881001b347SHuajun Li 1589e18c65b2SHuajun Li /* 1590e18c65b2SHuajun Li * inline.c 1591e18c65b2SHuajun Li */ 1592e18c65b2SHuajun Li bool f2fs_may_inline(struct inode *); 1593e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 1594b067ba1fSJaegeuk Kim int f2fs_convert_inline_data(struct inode *, pgoff_t, struct page *); 1595e18c65b2SHuajun Li int f2fs_write_inline_data(struct inode *, struct page *, unsigned int); 15968aa6f1c5SChao Yu void truncate_inline_data(struct inode *, u64); 15970342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 1598201a05beSChao Yu struct f2fs_dir_entry *find_in_inline_dir(struct inode *, struct qstr *, 1599201a05beSChao Yu struct page **); 1600201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 1601201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 1602201a05beSChao Yu int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *); 1603201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 1604201a05beSChao Yu struct inode *, struct inode *); 1605201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 1606201a05beSChao Yu int f2fs_read_inline_dir(struct file *, struct dir_context *); 160739a53e0cSJaegeuk Kim #endif 1608