10a8165d7SJaegeuk Kim /* 239a53e0cSJaegeuk Kim * fs/f2fs/f2fs.h 339a53e0cSJaegeuk Kim * 439a53e0cSJaegeuk Kim * Copyright (c) 2012 Samsung Electronics Co., Ltd. 539a53e0cSJaegeuk Kim * http://www.samsung.com/ 639a53e0cSJaegeuk Kim * 739a53e0cSJaegeuk Kim * This program is free software; you can redistribute it and/or modify 839a53e0cSJaegeuk Kim * it under the terms of the GNU General Public License version 2 as 939a53e0cSJaegeuk Kim * published by the Free Software Foundation. 1039a53e0cSJaegeuk Kim */ 1139a53e0cSJaegeuk Kim #ifndef _LINUX_F2FS_H 1239a53e0cSJaegeuk Kim #define _LINUX_F2FS_H 1339a53e0cSJaegeuk Kim 1439a53e0cSJaegeuk Kim #include <linux/types.h> 1539a53e0cSJaegeuk Kim #include <linux/page-flags.h> 1639a53e0cSJaegeuk Kim #include <linux/buffer_head.h> 1739a53e0cSJaegeuk Kim #include <linux/slab.h> 1839a53e0cSJaegeuk Kim #include <linux/crc32.h> 1939a53e0cSJaegeuk Kim #include <linux/magic.h> 20c2d715d1SJaegeuk Kim #include <linux/kobject.h> 217bd59381SGu Zheng #include <linux/sched.h> 2239307a8eSJaegeuk Kim #include <linux/vmalloc.h> 23740432f8SJaegeuk Kim #include <linux/bio.h> 2439a53e0cSJaegeuk Kim 255d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 269850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 270daaad97SJaegeuk Kim #define f2fs_down_write(x, y) down_write_nest_lock(x, y) 285d56b671SJaegeuk Kim #else 299850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 309850cf4aSJaegeuk Kim do { \ 319850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 329850cf4aSJaegeuk Kim WARN_ON(1); \ 33caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 349850cf4aSJaegeuk Kim } \ 359850cf4aSJaegeuk Kim } while (0) 360daaad97SJaegeuk Kim #define f2fs_down_write(x, y) down_write(x) 375d56b671SJaegeuk Kim #endif 385d56b671SJaegeuk Kim 3939a53e0cSJaegeuk Kim /* 4039a53e0cSJaegeuk Kim * For mount options 4139a53e0cSJaegeuk Kim */ 4239a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 4339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 4439a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 4539a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 4639a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 4739a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 4839a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 49444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 501001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 5134d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 5234d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 5334d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 54d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 5589672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 566aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 5739a53e0cSJaegeuk Kim 5839a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 5939a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 6039a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 6139a53e0cSJaegeuk Kim 6239a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 6339a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 6439a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 6539a53e0cSJaegeuk Kim 66a9841c4dSJaegeuk Kim typedef u32 block_t; /* 67a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 68a9841c4dSJaegeuk Kim * address format, __le32. 69a9841c4dSJaegeuk Kim */ 7039a53e0cSJaegeuk Kim typedef u32 nid_t; 7139a53e0cSJaegeuk Kim 7239a53e0cSJaegeuk Kim struct f2fs_mount_info { 7339a53e0cSJaegeuk Kim unsigned int opt; 7439a53e0cSJaegeuk Kim }; 7539a53e0cSJaegeuk Kim 76cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 77cde4de12SJaegeuk Kim 7876f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 7976f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 8076f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 8176f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) 8276f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 8376f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) 8476f105a2SJaegeuk Kim 857e586fa0SJaegeuk Kim #define CRCPOLY_LE 0xedb88320 867e586fa0SJaegeuk Kim 877e586fa0SJaegeuk Kim static inline __u32 f2fs_crc32(void *buf, size_t len) 8839a53e0cSJaegeuk Kim { 897e586fa0SJaegeuk Kim unsigned char *p = (unsigned char *)buf; 907e586fa0SJaegeuk Kim __u32 crc = F2FS_SUPER_MAGIC; 917e586fa0SJaegeuk Kim int i; 927e586fa0SJaegeuk Kim 937e586fa0SJaegeuk Kim while (len--) { 947e586fa0SJaegeuk Kim crc ^= *p++; 957e586fa0SJaegeuk Kim for (i = 0; i < 8; i++) 967e586fa0SJaegeuk Kim crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); 977e586fa0SJaegeuk Kim } 987e586fa0SJaegeuk Kim return crc; 9939a53e0cSJaegeuk Kim } 10039a53e0cSJaegeuk Kim 1017e586fa0SJaegeuk Kim static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size) 10239a53e0cSJaegeuk Kim { 1037e586fa0SJaegeuk Kim return f2fs_crc32(buf, buf_size) == blk_crc; 10439a53e0cSJaegeuk Kim } 10539a53e0cSJaegeuk Kim 10639a53e0cSJaegeuk Kim /* 10739a53e0cSJaegeuk Kim * For checkpoint manager 10839a53e0cSJaegeuk Kim */ 10939a53e0cSJaegeuk Kim enum { 11039a53e0cSJaegeuk Kim NAT_BITMAP, 11139a53e0cSJaegeuk Kim SIT_BITMAP 11239a53e0cSJaegeuk Kim }; 11339a53e0cSJaegeuk Kim 11475ab4cb8SJaegeuk Kim enum { 11575ab4cb8SJaegeuk Kim CP_UMOUNT, 116119ee914SJaegeuk Kim CP_FASTBOOT, 11775ab4cb8SJaegeuk Kim CP_SYNC, 11810027551SJaegeuk Kim CP_RECOVERY, 1194b2fecc8SJaegeuk Kim CP_DISCARD, 12075ab4cb8SJaegeuk Kim }; 12175ab4cb8SJaegeuk Kim 122bba681cbSJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 32 123bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 124bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 125a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 126a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 12760b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 128bba681cbSJaegeuk Kim 12975ab4cb8SJaegeuk Kim struct cp_control { 13075ab4cb8SJaegeuk Kim int reason; 1314b2fecc8SJaegeuk Kim __u64 trim_start; 1324b2fecc8SJaegeuk Kim __u64 trim_end; 1334b2fecc8SJaegeuk Kim __u64 trim_minlen; 1344b2fecc8SJaegeuk Kim __u64 trimmed; 13575ab4cb8SJaegeuk Kim }; 13675ab4cb8SJaegeuk Kim 137662befdaSChao Yu /* 13881c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 139662befdaSChao Yu */ 140662befdaSChao Yu enum { 141662befdaSChao Yu META_CP, 142662befdaSChao Yu META_NAT, 14381c1a0f1SChao Yu META_SIT, 1444c521f49SJaegeuk Kim META_SSA, 1454c521f49SJaegeuk Kim META_POR, 146662befdaSChao Yu }; 147662befdaSChao Yu 1486451e041SJaegeuk Kim /* for the list of ino */ 1496451e041SJaegeuk Kim enum { 1506451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 151fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 152fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1536451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1546451e041SJaegeuk Kim }; 1556451e041SJaegeuk Kim 1566451e041SJaegeuk Kim struct ino_entry { 15739a53e0cSJaegeuk Kim struct list_head list; /* list head */ 15839a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 15939a53e0cSJaegeuk Kim }; 16039a53e0cSJaegeuk Kim 16106292073SChao Yu /* 16206292073SChao Yu * for the list of directory inodes or gc inodes. 16306292073SChao Yu * NOTE: there are two slab users for this structure, if we add/modify/delete 16406292073SChao Yu * fields in structure for one of slab users, it may affect fields or size of 16506292073SChao Yu * other one, in this condition, it's better to split both of slab and related 16606292073SChao Yu * data structure. 16706292073SChao Yu */ 16806292073SChao Yu struct inode_entry { 16939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17039a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 17139a53e0cSJaegeuk Kim }; 17239a53e0cSJaegeuk Kim 1737fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1747fd9e544SJaegeuk Kim struct discard_entry { 1757fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1767fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1777fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1787fd9e544SJaegeuk Kim }; 1797fd9e544SJaegeuk Kim 18039a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 18139a53e0cSJaegeuk Kim struct fsync_inode_entry { 18239a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18339a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 184c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 185c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 186c52e1b10SJaegeuk Kim block_t last_inode; /* block address locating the last inode */ 18739a53e0cSJaegeuk Kim }; 18839a53e0cSJaegeuk Kim 18939a53e0cSJaegeuk Kim #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats)) 19039a53e0cSJaegeuk Kim #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits)) 19139a53e0cSJaegeuk Kim 19239a53e0cSJaegeuk Kim #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne) 19339a53e0cSJaegeuk Kim #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid) 19439a53e0cSJaegeuk Kim #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se) 19539a53e0cSJaegeuk Kim #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno) 19639a53e0cSJaegeuk Kim 197309cc2b6SJaegeuk Kim #define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum)) 198309cc2b6SJaegeuk Kim #define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum)) 199309cc2b6SJaegeuk Kim 20039a53e0cSJaegeuk Kim static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i) 20139a53e0cSJaegeuk Kim { 20239a53e0cSJaegeuk Kim int before = nats_in_cursum(rs); 20339a53e0cSJaegeuk Kim rs->n_nats = cpu_to_le16(before + i); 20439a53e0cSJaegeuk Kim return before; 20539a53e0cSJaegeuk Kim } 20639a53e0cSJaegeuk Kim 20739a53e0cSJaegeuk Kim static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i) 20839a53e0cSJaegeuk Kim { 20939a53e0cSJaegeuk Kim int before = sits_in_cursum(rs); 21039a53e0cSJaegeuk Kim rs->n_sits = cpu_to_le16(before + i); 21139a53e0cSJaegeuk Kim return before; 21239a53e0cSJaegeuk Kim } 21339a53e0cSJaegeuk Kim 214184a5cd2SChao Yu static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size, 215184a5cd2SChao Yu int type) 216184a5cd2SChao Yu { 217184a5cd2SChao Yu if (type == NAT_JOURNAL) 218309cc2b6SJaegeuk Kim return size <= MAX_NAT_JENTRIES(sum); 219309cc2b6SJaegeuk Kim return size <= MAX_SIT_JENTRIES(sum); 220184a5cd2SChao Yu } 221184a5cd2SChao Yu 22239a53e0cSJaegeuk Kim /* 223e9750824SNamjae Jeon * ioctl commands 224e9750824SNamjae Jeon */ 225e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 226e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 227d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 228e9750824SNamjae Jeon 22988b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 23088b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 23188b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 23202a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2331e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2341e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 235c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 236456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 23788b88a66SJaegeuk Kim 238f424f664SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY \ 239f424f664SJaegeuk Kim _IOR('f', 19, struct f2fs_encryption_policy) 240f424f664SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT \ 241f424f664SJaegeuk Kim _IOW('f', 20, __u8[16]) 242f424f664SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY \ 243f424f664SJaegeuk Kim _IOW('f', 21, struct f2fs_encryption_policy) 244f424f664SJaegeuk Kim 2451abff93dSJaegeuk Kim /* 2461abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2471abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2481abff93dSJaegeuk Kim */ 2491abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2501abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2511abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2521abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 253c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 2541abff93dSJaegeuk Kim 255e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 256e9750824SNamjae Jeon /* 257e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 258e9750824SNamjae Jeon */ 259e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 260e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 261e9750824SNamjae Jeon #endif 262e9750824SNamjae Jeon 263e9750824SNamjae Jeon /* 26439a53e0cSJaegeuk Kim * For INODE and NODE manager 26539a53e0cSJaegeuk Kim */ 2667b3cd7d6SJaegeuk Kim /* for directory operations */ 2676b3bd08fSJaegeuk Kim struct f2fs_str { 2686b3bd08fSJaegeuk Kim unsigned char *name; 2696b3bd08fSJaegeuk Kim u32 len; 2706b3bd08fSJaegeuk Kim }; 2716b3bd08fSJaegeuk Kim 2726b3bd08fSJaegeuk Kim struct f2fs_filename { 2736b3bd08fSJaegeuk Kim const struct qstr *usr_fname; 2746b3bd08fSJaegeuk Kim struct f2fs_str disk_name; 2756b3bd08fSJaegeuk Kim f2fs_hash_t hash; 2766b3bd08fSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2776b3bd08fSJaegeuk Kim struct f2fs_str crypto_buf; 2786b3bd08fSJaegeuk Kim #endif 2796b3bd08fSJaegeuk Kim }; 2806b3bd08fSJaegeuk Kim 2816b3bd08fSJaegeuk Kim #define FSTR_INIT(n, l) { .name = n, .len = l } 2826b3bd08fSJaegeuk Kim #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len) 2836b3bd08fSJaegeuk Kim #define fname_name(p) ((p)->disk_name.name) 2846b3bd08fSJaegeuk Kim #define fname_len(p) ((p)->disk_name.len) 2856b3bd08fSJaegeuk Kim 2867b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 287d8c6822aSJaegeuk Kim struct inode *inode; 2887b3cd7d6SJaegeuk Kim const void *bitmap; 2897b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 2907b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 2917b3cd7d6SJaegeuk Kim int max; 2927b3cd7d6SJaegeuk Kim }; 2937b3cd7d6SJaegeuk Kim 294d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode, 295d8c6822aSJaegeuk Kim struct f2fs_dentry_ptr *d, void *src, int type) 2967b3cd7d6SJaegeuk Kim { 297d8c6822aSJaegeuk Kim d->inode = inode; 298d8c6822aSJaegeuk Kim 2997b3cd7d6SJaegeuk Kim if (type == 1) { 3007b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 3017b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 3027b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3037b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3047b3cd7d6SJaegeuk Kim d->filename = t->filename; 3057b3cd7d6SJaegeuk Kim } else { 3067b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 3077b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3087b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3097b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3107b3cd7d6SJaegeuk Kim d->filename = t->filename; 3117b3cd7d6SJaegeuk Kim } 3127b3cd7d6SJaegeuk Kim } 3137b3cd7d6SJaegeuk Kim 314dbe6a5ffSJaegeuk Kim /* 315dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 316dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 317dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 31839a53e0cSJaegeuk Kim */ 319dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 320dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 321266e97a8SJaegeuk Kim enum { 322266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 323266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 324266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 325266e97a8SJaegeuk Kim * look up a node with readahead called 3264f4124d0SChao Yu * by get_data_block. 32739a53e0cSJaegeuk Kim */ 328266e97a8SJaegeuk Kim }; 329266e97a8SJaegeuk Kim 330a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 33139a53e0cSJaegeuk Kim 332817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 333817202d9SChao Yu 33413054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 33513054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 33613054c54SChao Yu 33739a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 33813054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 33913054c54SChao Yu 34013054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 34113054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 342c11abd1aSJaegeuk Kim 34339a53e0cSJaegeuk Kim struct extent_info { 34439a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3454d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 346111d2495SMasanari Iida unsigned int len; /* length of the extent */ 34739a53e0cSJaegeuk Kim }; 34839a53e0cSJaegeuk Kim 34913054c54SChao Yu struct extent_node { 35013054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 35113054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 35213054c54SChao Yu struct extent_info ei; /* extent info */ 35313054c54SChao Yu }; 35413054c54SChao Yu 35513054c54SChao Yu struct extent_tree { 35613054c54SChao Yu nid_t ino; /* inode number */ 35713054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 35862c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 3593e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 36013054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 36113054c54SChao Yu atomic_t refcount; /* reference count of rb-tree */ 36213054c54SChao Yu unsigned int count; /* # of extent node in rb-tree*/ 36313054c54SChao Yu }; 36413054c54SChao Yu 36539a53e0cSJaegeuk Kim /* 366003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 367003a3e1dSJaegeuk Kim * 368003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 369003a3e1dSJaegeuk Kim */ 370003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 371003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 3727f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 3737f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 3747f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 375003a3e1dSJaegeuk Kim 376003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 377003a3e1dSJaegeuk Kim block_t m_pblk; 378003a3e1dSJaegeuk Kim block_t m_lblk; 379003a3e1dSJaegeuk Kim unsigned int m_len; 380003a3e1dSJaegeuk Kim unsigned int m_flags; 381003a3e1dSJaegeuk Kim }; 382003a3e1dSJaegeuk Kim 383e2b4e2bcSChao Yu /* for flag in get_data_block */ 384e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 385e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 386e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 387e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 388e2b4e2bcSChao Yu 389003a3e1dSJaegeuk Kim /* 39039a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 39139a53e0cSJaegeuk Kim */ 39239a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 393354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 394cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 395e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 39639a53e0cSJaegeuk Kim 397b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 398b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 399b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 400b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 401b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 402b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 403cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 404cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 405cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 406e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 407e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 408cde4de12SJaegeuk Kim 409cde4de12SJaegeuk Kim /* Encryption algorithms */ 410cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_INVALID 0 411cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_XTS 1 412cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_GCM 2 413cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CBC 3 414cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CTS 4 415b5492af7SJaegeuk Kim 416f424f664SJaegeuk Kim #include "f2fs_crypto.h" 417f424f664SJaegeuk Kim 418ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 419ab9fa662SJaegeuk Kim 42039a53e0cSJaegeuk Kim struct f2fs_inode_info { 42139a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 42239a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 42339a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 42438431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 42539a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4266666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 42739a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 42839a53e0cSJaegeuk Kim 42939a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 43039a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 431d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 432a7ffdbe2SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 43339a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 43439a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 43539a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 436e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 43706292073SChao Yu struct inode_entry *dirty_dir; /* the pointer of dirty dir */ 43888b88a66SJaegeuk Kim 43988b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 44088b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 441cde4de12SJaegeuk Kim 4423e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 4433e72f721SJaegeuk Kim 444cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 445cde4de12SJaegeuk Kim /* Encryption params */ 446cde4de12SJaegeuk Kim struct f2fs_crypt_info *i_crypt_info; 447cde4de12SJaegeuk Kim #endif 44839a53e0cSJaegeuk Kim }; 44939a53e0cSJaegeuk Kim 45039a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 45139a53e0cSJaegeuk Kim struct f2fs_extent i_ext) 45239a53e0cSJaegeuk Kim { 45339a53e0cSJaegeuk Kim ext->fofs = le32_to_cpu(i_ext.fofs); 4544d0b0bd4SChao Yu ext->blk = le32_to_cpu(i_ext.blk); 45539a53e0cSJaegeuk Kim ext->len = le32_to_cpu(i_ext.len); 45639a53e0cSJaegeuk Kim } 45739a53e0cSJaegeuk Kim 45839a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 45939a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 46039a53e0cSJaegeuk Kim { 46139a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4624d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 46339a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 46439a53e0cSJaegeuk Kim } 46539a53e0cSJaegeuk Kim 466429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 467429511cdSChao Yu u32 blk, unsigned int len) 468429511cdSChao Yu { 469429511cdSChao Yu ei->fofs = fofs; 470429511cdSChao Yu ei->blk = blk; 471429511cdSChao Yu ei->len = len; 472429511cdSChao Yu } 473429511cdSChao Yu 4740bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1, 4750bdee482SChao Yu struct extent_info *ei2) 4760bdee482SChao Yu { 4770bdee482SChao Yu return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 4780bdee482SChao Yu ei1->len == ei2->len); 4790bdee482SChao Yu } 4800bdee482SChao Yu 481429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 482429511cdSChao Yu struct extent_info *front) 483429511cdSChao Yu { 484429511cdSChao Yu return (back->fofs + back->len == front->fofs && 485429511cdSChao Yu back->blk + back->len == front->blk); 486429511cdSChao Yu } 487429511cdSChao Yu 488429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 489429511cdSChao Yu struct extent_info *back) 490429511cdSChao Yu { 491429511cdSChao Yu return __is_extent_mergeable(back, cur); 492429511cdSChao Yu } 493429511cdSChao Yu 494429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 495429511cdSChao Yu struct extent_info *front) 496429511cdSChao Yu { 497429511cdSChao Yu return __is_extent_mergeable(cur, front); 498429511cdSChao Yu } 499429511cdSChao Yu 5004abd3f5aSChao Yu static inline void __try_update_largest_extent(struct extent_tree *et, 5014abd3f5aSChao Yu struct extent_node *en) 5024abd3f5aSChao Yu { 5034abd3f5aSChao Yu if (en->ei.len > et->largest.len) 5044abd3f5aSChao Yu et->largest = en->ei; 5054abd3f5aSChao Yu } 5064abd3f5aSChao Yu 50739a53e0cSJaegeuk Kim struct f2fs_nm_info { 50839a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 50939a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 5107ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 51139a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 512cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 513ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 51439a53e0cSJaegeuk Kim 51539a53e0cSJaegeuk Kim /* NAT cache management */ 51639a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 517309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 5188b26ef98SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 51939a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 520309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 521aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 52239a53e0cSJaegeuk Kim 52339a53e0cSJaegeuk Kim /* free node ids management */ 5248a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 52539a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 52639a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 52739a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 52839a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 52939a53e0cSJaegeuk Kim 53039a53e0cSJaegeuk Kim /* for checkpoint */ 53139a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 53239a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 53339a53e0cSJaegeuk Kim }; 53439a53e0cSJaegeuk Kim 53539a53e0cSJaegeuk Kim /* 53639a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 53739a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 53839a53e0cSJaegeuk Kim * by the data offset in a file. 53939a53e0cSJaegeuk Kim */ 54039a53e0cSJaegeuk Kim struct dnode_of_data { 54139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 54239a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 54339a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 54439a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 54539a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 54639a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 54739a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 54839a53e0cSJaegeuk Kim }; 54939a53e0cSJaegeuk Kim 55039a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 55139a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 55239a53e0cSJaegeuk Kim { 553d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 55439a53e0cSJaegeuk Kim dn->inode = inode; 55539a53e0cSJaegeuk Kim dn->inode_page = ipage; 55639a53e0cSJaegeuk Kim dn->node_page = npage; 55739a53e0cSJaegeuk Kim dn->nid = nid; 55839a53e0cSJaegeuk Kim } 55939a53e0cSJaegeuk Kim 56039a53e0cSJaegeuk Kim /* 56139a53e0cSJaegeuk Kim * For SIT manager 56239a53e0cSJaegeuk Kim * 56339a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 56439a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 56539a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 56639a53e0cSJaegeuk Kim * respectively. 56739a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 56839a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 56939a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 57039a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 57139a53e0cSJaegeuk Kim * data and 8 for node logs. 57239a53e0cSJaegeuk Kim */ 57339a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 57439a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 57539a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 57639a53e0cSJaegeuk Kim 57739a53e0cSJaegeuk Kim enum { 57839a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 57939a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 58039a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 58139a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 58239a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 58339a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 58438aa0889SJaegeuk Kim NO_CHECK_TYPE, 58538aa0889SJaegeuk Kim CURSEG_DIRECT_IO, /* to use for the direct IO path */ 58639a53e0cSJaegeuk Kim }; 58739a53e0cSJaegeuk Kim 5886b4afdd7SJaegeuk Kim struct flush_cmd { 5896b4afdd7SJaegeuk Kim struct completion wait; 590721bd4d5SGu Zheng struct llist_node llnode; 5916b4afdd7SJaegeuk Kim int ret; 5926b4afdd7SJaegeuk Kim }; 5936b4afdd7SJaegeuk Kim 594a688b9d9SGu Zheng struct flush_cmd_control { 595a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 596a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 597721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 598721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 599a688b9d9SGu Zheng }; 600a688b9d9SGu Zheng 60139a53e0cSJaegeuk Kim struct f2fs_sm_info { 60239a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 60339a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 60439a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 60539a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 60639a53e0cSJaegeuk Kim 60739a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 60839a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 60939a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 61039a53e0cSJaegeuk Kim 61139a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 61239a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 61339a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 61439a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 61581eb8d6eSJaegeuk Kim 61681eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 61781eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 6187fd9e544SJaegeuk Kim 6197fd9e544SJaegeuk Kim /* for small discard management */ 6207fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 6217fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 6227fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 623216fbd64SJaegeuk Kim 624bba681cbSJaegeuk Kim /* for batched trimming */ 625bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 626bba681cbSJaegeuk Kim 627184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 628184a5cd2SChao Yu 629216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 630216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 631c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 6326b4afdd7SJaegeuk Kim 6336b4afdd7SJaegeuk Kim /* for flush command control */ 634a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 635a688b9d9SGu Zheng 63639a53e0cSJaegeuk Kim }; 63739a53e0cSJaegeuk Kim 63839a53e0cSJaegeuk Kim /* 63939a53e0cSJaegeuk Kim * For superblock 64039a53e0cSJaegeuk Kim */ 64139a53e0cSJaegeuk Kim /* 64239a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 64339a53e0cSJaegeuk Kim * 64439a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 64539a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 64639a53e0cSJaegeuk Kim */ 64739a53e0cSJaegeuk Kim enum count_type { 64839a53e0cSJaegeuk Kim F2FS_WRITEBACK, 64939a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 65039a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 65139a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6528dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 65339a53e0cSJaegeuk Kim NR_COUNT_TYPE, 65439a53e0cSJaegeuk Kim }; 65539a53e0cSJaegeuk Kim 65639a53e0cSJaegeuk Kim /* 657e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 65839a53e0cSJaegeuk Kim * The available types are: 65939a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 66039a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 66139a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 66239a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 66339a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 66439a53e0cSJaegeuk Kim * with waiting the bio's completion 66539a53e0cSJaegeuk Kim * ... Only can be used with META. 66639a53e0cSJaegeuk Kim */ 6677d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 66839a53e0cSJaegeuk Kim enum page_type { 66939a53e0cSJaegeuk Kim DATA, 67039a53e0cSJaegeuk Kim NODE, 67139a53e0cSJaegeuk Kim META, 67239a53e0cSJaegeuk Kim NR_PAGE_TYPE, 67339a53e0cSJaegeuk Kim META_FLUSH, 6748ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 6758ce67cb0SJaegeuk Kim INMEM_DROP, 6768ce67cb0SJaegeuk Kim IPU, 6778ce67cb0SJaegeuk Kim OPU, 67839a53e0cSJaegeuk Kim }; 67939a53e0cSJaegeuk Kim 680458e6197SJaegeuk Kim struct f2fs_io_info { 68105ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 682458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 6837e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 684cf04e8ebSJaegeuk Kim block_t blk_addr; /* block address to be written */ 68505ca3632SJaegeuk Kim struct page *page; /* page to be written */ 6864375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 687458e6197SJaegeuk Kim }; 688458e6197SJaegeuk Kim 68993dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 6901ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 691458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 6921ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 6931ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 694458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 695df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 6961ff7bd3bSJaegeuk Kim }; 6971ff7bd3bSJaegeuk Kim 69867298804SChao Yu /* for inner inode cache management */ 69967298804SChao Yu struct inode_management { 70067298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 70167298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 70267298804SChao Yu struct list_head ino_list; /* inode list head */ 70367298804SChao Yu unsigned long ino_num; /* number of entries */ 70467298804SChao Yu }; 70567298804SChao Yu 706caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 707caf0047eSChao Yu enum { 708caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 709caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 710caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 711caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 712caf0047eSChao Yu }; 713caf0047eSChao Yu 71439a53e0cSJaegeuk Kim struct f2fs_sb_info { 71539a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 7165e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 71739a53e0cSJaegeuk Kim struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 71839a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 719caf0047eSChao Yu int s_flag; /* flags for sbi */ 72039a53e0cSJaegeuk Kim 72139a53e0cSJaegeuk Kim /* for node-related operations */ 72239a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 72339a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 72439a53e0cSJaegeuk Kim 72539a53e0cSJaegeuk Kim /* for segment-related operations */ 72639a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 7271ff7bd3bSJaegeuk Kim 7281ff7bd3bSJaegeuk Kim /* for bio operations */ 729924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 7301ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 73139a53e0cSJaegeuk Kim 73239a53e0cSJaegeuk Kim /* for checkpoint */ 73339a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 73439a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 73539936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 736e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 737b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 7385463e7c1SJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 739fb51b5efSChangman Lee wait_queue_head_t cp_wait; 74060b99b48SJaegeuk Kim long cp_expires, cp_interval; /* next expected periodic cp */ 74139a53e0cSJaegeuk Kim 74267298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 7436451e041SJaegeuk Kim 7446451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 7450d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 74639a53e0cSJaegeuk Kim 74739a53e0cSJaegeuk Kim /* for directory inode management */ 74839a53e0cSJaegeuk Kim struct list_head dir_inode_list; /* dir inode list */ 74939a53e0cSJaegeuk Kim spinlock_t dir_inode_lock; /* for dir inode list lock */ 75039a53e0cSJaegeuk Kim 75113054c54SChao Yu /* for extent tree cache */ 75213054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 75313054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 75413054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 75513054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 75613054c54SChao Yu int total_ext_tree; /* extent tree count */ 75713054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 75813054c54SChao Yu 75939a53e0cSJaegeuk Kim /* basic filesystem units */ 76039a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 76139a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 76239a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 76339a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 76439a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 76539a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 76639a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 76739a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 76839a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 76939a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 77039a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 77139a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 77239a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 77339a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 77439a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 775ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 77639a53e0cSJaegeuk Kim 77739a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 77839a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 77939a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 780a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 78139a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 78239a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 78339a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 78439a53e0cSJaegeuk Kim 78539a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 78639a53e0cSJaegeuk Kim 78739a53e0cSJaegeuk Kim /* for cleaning operations */ 78839a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 78939a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 7905ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 79139a53e0cSJaegeuk Kim 792b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 793b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 794b1c57c1cSJaegeuk Kim 79539a53e0cSJaegeuk Kim /* 79639a53e0cSJaegeuk Kim * for stat information. 79739a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 79839a53e0cSJaegeuk Kim */ 79935b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 80039a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 80139a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 80239a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 803b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 8045b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 8055b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 8065b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 8075b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 808d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 80903e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 81003e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 81139a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 81235b09d82SNamjae Jeon unsigned int n_dirty_dirs; /* # of dir inodes */ 81335b09d82SNamjae Jeon #endif 81435b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 81539a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 816b59d0baeSNamjae Jeon 817b59d0baeSNamjae Jeon /* For sysfs suppport */ 818b59d0baeSNamjae Jeon struct kobject s_kobj; 819b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 8202658e50dSJaegeuk Kim 8212658e50dSJaegeuk Kim /* For shrinker support */ 8222658e50dSJaegeuk Kim struct list_head s_list; 8232658e50dSJaegeuk Kim struct mutex umount_mutex; 8242658e50dSJaegeuk Kim unsigned int shrinker_run_no; 82539a53e0cSJaegeuk Kim }; 82639a53e0cSJaegeuk Kim 82739a53e0cSJaegeuk Kim /* 82839a53e0cSJaegeuk Kim * Inline functions 82939a53e0cSJaegeuk Kim */ 83039a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 83139a53e0cSJaegeuk Kim { 83239a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 83339a53e0cSJaegeuk Kim } 83439a53e0cSJaegeuk Kim 83539a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 83639a53e0cSJaegeuk Kim { 83739a53e0cSJaegeuk Kim return sb->s_fs_info; 83839a53e0cSJaegeuk Kim } 83939a53e0cSJaegeuk Kim 8404081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 8414081363fSJaegeuk Kim { 8424081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 8434081363fSJaegeuk Kim } 8444081363fSJaegeuk Kim 8454081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 8464081363fSJaegeuk Kim { 8474081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 8484081363fSJaegeuk Kim } 8494081363fSJaegeuk Kim 8504081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 8514081363fSJaegeuk Kim { 8524081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 8534081363fSJaegeuk Kim } 8544081363fSJaegeuk Kim 85539a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 85639a53e0cSJaegeuk Kim { 85739a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 85839a53e0cSJaegeuk Kim } 85939a53e0cSJaegeuk Kim 86039a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 86139a53e0cSJaegeuk Kim { 86239a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 86339a53e0cSJaegeuk Kim } 86439a53e0cSJaegeuk Kim 86545590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 86645590710SGu Zheng { 86745590710SGu Zheng return (struct f2fs_node *)page_address(page); 86845590710SGu Zheng } 86945590710SGu Zheng 87058bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 87158bfaf44SJaegeuk Kim { 87258bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 87358bfaf44SJaegeuk Kim } 87458bfaf44SJaegeuk Kim 87539a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 87639a53e0cSJaegeuk Kim { 87739a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 87839a53e0cSJaegeuk Kim } 87939a53e0cSJaegeuk Kim 88039a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 88139a53e0cSJaegeuk Kim { 88239a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 88339a53e0cSJaegeuk Kim } 88439a53e0cSJaegeuk Kim 88539a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 88639a53e0cSJaegeuk Kim { 88739a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 88839a53e0cSJaegeuk Kim } 88939a53e0cSJaegeuk Kim 89039a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 89139a53e0cSJaegeuk Kim { 89239a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 89339a53e0cSJaegeuk Kim } 89439a53e0cSJaegeuk Kim 89539a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 89639a53e0cSJaegeuk Kim { 89739a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 89839a53e0cSJaegeuk Kim } 89939a53e0cSJaegeuk Kim 9009df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 9019df27d98SGu Zheng { 9029df27d98SGu Zheng return sbi->meta_inode->i_mapping; 9039df27d98SGu Zheng } 9049df27d98SGu Zheng 9054ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 9064ef51a8fSJaegeuk Kim { 9074ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 9084ef51a8fSJaegeuk Kim } 9094ef51a8fSJaegeuk Kim 910caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 91139a53e0cSJaegeuk Kim { 912caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 91339a53e0cSJaegeuk Kim } 91439a53e0cSJaegeuk Kim 915caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 91639a53e0cSJaegeuk Kim { 917caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 918caf0047eSChao Yu } 919caf0047eSChao Yu 920caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 921caf0047eSChao Yu { 922caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 92339a53e0cSJaegeuk Kim } 92439a53e0cSJaegeuk Kim 925d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 926d71b5564SJaegeuk Kim { 927d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 928d71b5564SJaegeuk Kim } 929d71b5564SJaegeuk Kim 93025ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 93125ca923bSJaegeuk Kim { 93225ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 93325ca923bSJaegeuk Kim return ckpt_flags & f; 93425ca923bSJaegeuk Kim } 93525ca923bSJaegeuk Kim 93625ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 93725ca923bSJaegeuk Kim { 93825ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 93925ca923bSJaegeuk Kim ckpt_flags |= f; 94025ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 94125ca923bSJaegeuk Kim } 94225ca923bSJaegeuk Kim 94325ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 94425ca923bSJaegeuk Kim { 94525ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 94625ca923bSJaegeuk Kim ckpt_flags &= (~f); 94725ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 94825ca923bSJaegeuk Kim } 94925ca923bSJaegeuk Kim 950e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 95139a53e0cSJaegeuk Kim { 952e479556bSGu Zheng down_read(&sbi->cp_rwsem); 95339a53e0cSJaegeuk Kim } 95439a53e0cSJaegeuk Kim 955e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 95639a53e0cSJaegeuk Kim { 957e479556bSGu Zheng up_read(&sbi->cp_rwsem); 95839936837SJaegeuk Kim } 95939936837SJaegeuk Kim 960e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 96139936837SJaegeuk Kim { 9620daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 96339936837SJaegeuk Kim } 96439936837SJaegeuk Kim 965e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 96639936837SJaegeuk Kim { 967e479556bSGu Zheng up_write(&sbi->cp_rwsem); 96839a53e0cSJaegeuk Kim } 96939a53e0cSJaegeuk Kim 970119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 971119ee914SJaegeuk Kim { 972119ee914SJaegeuk Kim int reason = CP_SYNC; 973119ee914SJaegeuk Kim 974119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 975119ee914SJaegeuk Kim reason = CP_FASTBOOT; 976119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 977119ee914SJaegeuk Kim reason = CP_UMOUNT; 978119ee914SJaegeuk Kim return reason; 979119ee914SJaegeuk Kim } 980119ee914SJaegeuk Kim 981119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 982119ee914SJaegeuk Kim { 983119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 984119ee914SJaegeuk Kim } 985119ee914SJaegeuk Kim 986119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 987119ee914SJaegeuk Kim { 988119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 989119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 990119ee914SJaegeuk Kim } 991119ee914SJaegeuk Kim 99239a53e0cSJaegeuk Kim /* 99339a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 99439a53e0cSJaegeuk Kim */ 995064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 99639a53e0cSJaegeuk Kim { 997d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 998d6b7d4b3SChao Yu return -EINVAL; 999cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1000064e0823SNamjae Jeon return -EINVAL; 1001064e0823SNamjae Jeon return 0; 100239a53e0cSJaegeuk Kim } 100339a53e0cSJaegeuk Kim 100439a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 100539a53e0cSJaegeuk Kim 100639a53e0cSJaegeuk Kim /* 100739a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 100839a53e0cSJaegeuk Kim */ 100939a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 101039a53e0cSJaegeuk Kim { 101139a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 10126c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 101339a53e0cSJaegeuk Kim else 10146c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 101539a53e0cSJaegeuk Kim } 101639a53e0cSJaegeuk Kim 10174bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 10184bc8e9bcSChao Yu { 10194bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 10204bc8e9bcSChao Yu } 10214bc8e9bcSChao Yu 102239a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 102339a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 102439a53e0cSJaegeuk Kim { 102539a53e0cSJaegeuk Kim block_t valid_block_count; 102639a53e0cSJaegeuk Kim 102739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 102839a53e0cSJaegeuk Kim valid_block_count = 102939a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 1030cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 103139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 103239a53e0cSJaegeuk Kim return false; 103339a53e0cSJaegeuk Kim } 103439a53e0cSJaegeuk Kim inode->i_blocks += count; 103539a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 103639a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 103739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 103839a53e0cSJaegeuk Kim return true; 103939a53e0cSJaegeuk Kim } 104039a53e0cSJaegeuk Kim 1041da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 104239a53e0cSJaegeuk Kim struct inode *inode, 104339a53e0cSJaegeuk Kim blkcnt_t count) 104439a53e0cSJaegeuk Kim { 104539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 10469850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 10479850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 104839a53e0cSJaegeuk Kim inode->i_blocks -= count; 104939a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 105039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 105139a53e0cSJaegeuk Kim } 105239a53e0cSJaegeuk Kim 105339a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 105439a53e0cSJaegeuk Kim { 105539a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 1056caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 105739a53e0cSJaegeuk Kim } 105839a53e0cSJaegeuk Kim 1059a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 106039a53e0cSJaegeuk Kim { 1061a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1062a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10634081363fSJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 106439a53e0cSJaegeuk Kim } 106539a53e0cSJaegeuk Kim 106639a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 106739a53e0cSJaegeuk Kim { 106839a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 106939a53e0cSJaegeuk Kim } 107039a53e0cSJaegeuk Kim 1071a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 107239a53e0cSJaegeuk Kim { 10735ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 10745ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 10751fe54f9dSJaegeuk Kim return; 10761fe54f9dSJaegeuk Kim 1077a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1078a7ffdbe2SJaegeuk Kim 1079a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10804081363fSJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 108139a53e0cSJaegeuk Kim } 108239a53e0cSJaegeuk Kim 108339a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 108439a53e0cSJaegeuk Kim { 108539a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 108639a53e0cSJaegeuk Kim } 108739a53e0cSJaegeuk Kim 1088a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1089f8b2c1f9SJaegeuk Kim { 1090a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1091f8b2c1f9SJaegeuk Kim } 1092f8b2c1f9SJaegeuk Kim 10935ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 10945ac206cfSNamjae Jeon { 10955ac206cfSNamjae Jeon unsigned int pages_per_sec = sbi->segs_per_sec * 10965ac206cfSNamjae Jeon (1 << sbi->log_blocks_per_seg); 10975ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 10985ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 10995ac206cfSNamjae Jeon } 11005ac206cfSNamjae Jeon 110139a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 110239a53e0cSJaegeuk Kim { 11038b8343faSJaegeuk Kim return sbi->total_valid_block_count; 110439a53e0cSJaegeuk Kim } 110539a53e0cSJaegeuk Kim 110639a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 110739a53e0cSJaegeuk Kim { 110839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 110939a53e0cSJaegeuk Kim 111039a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 111139a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 111239a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 111339a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 111439a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 111539a53e0cSJaegeuk Kim 111639a53e0cSJaegeuk Kim return 0; 111739a53e0cSJaegeuk Kim } 111839a53e0cSJaegeuk Kim 111955141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 112055141486SWanpeng Li { 112155141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 112255141486SWanpeng Li } 112355141486SWanpeng Li 112439a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 112539a53e0cSJaegeuk Kim { 112639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 11271dbe4152SChangman Lee int offset; 11281dbe4152SChangman Lee 112955141486SWanpeng Li if (__cp_payload(sbi) > 0) { 11301dbe4152SChangman Lee if (flag == NAT_BITMAP) 11311dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 11321dbe4152SChangman Lee else 113365b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 11341dbe4152SChangman Lee } else { 11351dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 113625ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 113739a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 113839a53e0cSJaegeuk Kim } 11391dbe4152SChangman Lee } 114039a53e0cSJaegeuk Kim 114139a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 114239a53e0cSJaegeuk Kim { 114339a53e0cSJaegeuk Kim block_t start_addr; 114439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1145d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 114639a53e0cSJaegeuk Kim 114725ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 114839a53e0cSJaegeuk Kim 114939a53e0cSJaegeuk Kim /* 115039a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1151e1c42045Sarter97 * and even segment must be at cp segment 1 115239a53e0cSJaegeuk Kim */ 115339a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 115439a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 115539a53e0cSJaegeuk Kim 115639a53e0cSJaegeuk Kim return start_addr; 115739a53e0cSJaegeuk Kim } 115839a53e0cSJaegeuk Kim 115939a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 116039a53e0cSJaegeuk Kim { 116139a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 116239a53e0cSJaegeuk Kim } 116339a53e0cSJaegeuk Kim 116439a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1165ef86d709SGu Zheng struct inode *inode) 116639a53e0cSJaegeuk Kim { 116739a53e0cSJaegeuk Kim block_t valid_block_count; 116839a53e0cSJaegeuk Kim unsigned int valid_node_count; 116939a53e0cSJaegeuk Kim 117039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 117139a53e0cSJaegeuk Kim 1172ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1173cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 117439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 117539a53e0cSJaegeuk Kim return false; 117639a53e0cSJaegeuk Kim } 117739a53e0cSJaegeuk Kim 1178ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1179cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 118039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 118139a53e0cSJaegeuk Kim return false; 118239a53e0cSJaegeuk Kim } 118339a53e0cSJaegeuk Kim 118439a53e0cSJaegeuk Kim if (inode) 1185ef86d709SGu Zheng inode->i_blocks++; 1186ef86d709SGu Zheng 1187ef86d709SGu Zheng sbi->alloc_valid_block_count++; 1188ef86d709SGu Zheng sbi->total_valid_node_count++; 1189ef86d709SGu Zheng sbi->total_valid_block_count++; 119039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 119139a53e0cSJaegeuk Kim 119239a53e0cSJaegeuk Kim return true; 119339a53e0cSJaegeuk Kim } 119439a53e0cSJaegeuk Kim 119539a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1196ef86d709SGu Zheng struct inode *inode) 119739a53e0cSJaegeuk Kim { 119839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 119939a53e0cSJaegeuk Kim 12009850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 12019850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 12029850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 120339a53e0cSJaegeuk Kim 1204ef86d709SGu Zheng inode->i_blocks--; 1205ef86d709SGu Zheng sbi->total_valid_node_count--; 1206ef86d709SGu Zheng sbi->total_valid_block_count--; 120739a53e0cSJaegeuk Kim 120839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 120939a53e0cSJaegeuk Kim } 121039a53e0cSJaegeuk Kim 121139a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 121239a53e0cSJaegeuk Kim { 12138b8343faSJaegeuk Kim return sbi->total_valid_node_count; 121439a53e0cSJaegeuk Kim } 121539a53e0cSJaegeuk Kim 121639a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 121739a53e0cSJaegeuk Kim { 121839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12199850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 122039a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 122139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 122239a53e0cSJaegeuk Kim } 122339a53e0cSJaegeuk Kim 12240e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 122539a53e0cSJaegeuk Kim { 122639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12279850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 122839a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 122939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 123039a53e0cSJaegeuk Kim } 123139a53e0cSJaegeuk Kim 123239a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 123339a53e0cSJaegeuk Kim { 12348b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 123539a53e0cSJaegeuk Kim } 123639a53e0cSJaegeuk Kim 1237a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1238a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1239a56c7c6fSJaegeuk Kim { 1240a56c7c6fSJaegeuk Kim if (!for_write) 1241a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1242a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1243a56c7c6fSJaegeuk Kim } 1244a56c7c6fSJaegeuk Kim 12456e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 12466e2c64adSJaegeuk Kim { 12476e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 12486e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 12496e2c64adSJaegeuk Kim 12506e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 12516e2c64adSJaegeuk Kim kunmap(dst); 12526e2c64adSJaegeuk Kim kunmap(src); 12536e2c64adSJaegeuk Kim } 12546e2c64adSJaegeuk Kim 125539a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 125639a53e0cSJaegeuk Kim { 1257031fa8ccSJaegeuk Kim if (!page) 125839a53e0cSJaegeuk Kim return; 125939a53e0cSJaegeuk Kim 126039a53e0cSJaegeuk Kim if (unlock) { 12619850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 126239a53e0cSJaegeuk Kim unlock_page(page); 126339a53e0cSJaegeuk Kim } 126439a53e0cSJaegeuk Kim page_cache_release(page); 126539a53e0cSJaegeuk Kim } 126639a53e0cSJaegeuk Kim 126739a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 126839a53e0cSJaegeuk Kim { 126939a53e0cSJaegeuk Kim if (dn->node_page) 127039a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 127139a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 127239a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 127339a53e0cSJaegeuk Kim dn->node_page = NULL; 127439a53e0cSJaegeuk Kim dn->inode_page = NULL; 127539a53e0cSJaegeuk Kim } 127639a53e0cSJaegeuk Kim 127739a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1278e8512d2eSGu Zheng size_t size) 127939a53e0cSJaegeuk Kim { 1280e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 128139a53e0cSJaegeuk Kim } 128239a53e0cSJaegeuk Kim 12837bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 12847bd59381SGu Zheng gfp_t flags) 12857bd59381SGu Zheng { 12867bd59381SGu Zheng void *entry; 12877bd59381SGu Zheng 128880c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 128980c54505SJaegeuk Kim if (!entry) 129080c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 12917bd59381SGu Zheng return entry; 12927bd59381SGu Zheng } 12937bd59381SGu Zheng 1294740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1295740432f8SJaegeuk Kim { 1296740432f8SJaegeuk Kim struct bio *bio; 1297740432f8SJaegeuk Kim 1298740432f8SJaegeuk Kim /* No failure on bio allocation */ 1299740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 130080c54505SJaegeuk Kim if (!bio) 130180c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1302740432f8SJaegeuk Kim return bio; 1303740432f8SJaegeuk Kim } 1304740432f8SJaegeuk Kim 13059be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 13069be32d72SJaegeuk Kim unsigned long index, void *item) 13079be32d72SJaegeuk Kim { 13089be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 13099be32d72SJaegeuk Kim cond_resched(); 13109be32d72SJaegeuk Kim } 13119be32d72SJaegeuk Kim 131239a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 131339a53e0cSJaegeuk Kim 131439a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 131539a53e0cSJaegeuk Kim { 131645590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 131739a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 131839a53e0cSJaegeuk Kim } 131939a53e0cSJaegeuk Kim 132039a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 132139a53e0cSJaegeuk Kim { 132239a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 132339a53e0cSJaegeuk Kim } 132439a53e0cSJaegeuk Kim 132539a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 132639a53e0cSJaegeuk Kim unsigned int offset) 132739a53e0cSJaegeuk Kim { 132839a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 132939a53e0cSJaegeuk Kim __le32 *addr_array; 133045590710SGu Zheng raw_node = F2FS_NODE(node_page); 133139a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 133239a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 133339a53e0cSJaegeuk Kim } 133439a53e0cSJaegeuk Kim 133539a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 133639a53e0cSJaegeuk Kim { 133739a53e0cSJaegeuk Kim int mask; 133839a53e0cSJaegeuk Kim 133939a53e0cSJaegeuk Kim addr += (nr >> 3); 134039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 134139a53e0cSJaegeuk Kim return mask & *addr; 134239a53e0cSJaegeuk Kim } 134339a53e0cSJaegeuk Kim 1344a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1345a66cdd98SJaegeuk Kim { 1346a66cdd98SJaegeuk Kim int mask; 1347a66cdd98SJaegeuk Kim 1348a66cdd98SJaegeuk Kim addr += (nr >> 3); 1349a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1350a66cdd98SJaegeuk Kim *addr |= mask; 1351a66cdd98SJaegeuk Kim } 1352a66cdd98SJaegeuk Kim 1353a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1354a66cdd98SJaegeuk Kim { 1355a66cdd98SJaegeuk Kim int mask; 1356a66cdd98SJaegeuk Kim 1357a66cdd98SJaegeuk Kim addr += (nr >> 3); 1358a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1359a66cdd98SJaegeuk Kim *addr &= ~mask; 1360a66cdd98SJaegeuk Kim } 1361a66cdd98SJaegeuk Kim 136252aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 136339a53e0cSJaegeuk Kim { 136439a53e0cSJaegeuk Kim int mask; 136539a53e0cSJaegeuk Kim int ret; 136639a53e0cSJaegeuk Kim 136739a53e0cSJaegeuk Kim addr += (nr >> 3); 136839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 136939a53e0cSJaegeuk Kim ret = mask & *addr; 137039a53e0cSJaegeuk Kim *addr |= mask; 137139a53e0cSJaegeuk Kim return ret; 137239a53e0cSJaegeuk Kim } 137339a53e0cSJaegeuk Kim 137452aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 137539a53e0cSJaegeuk Kim { 137639a53e0cSJaegeuk Kim int mask; 137739a53e0cSJaegeuk Kim int ret; 137839a53e0cSJaegeuk Kim 137939a53e0cSJaegeuk Kim addr += (nr >> 3); 138039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 138139a53e0cSJaegeuk Kim ret = mask & *addr; 138239a53e0cSJaegeuk Kim *addr &= ~mask; 138339a53e0cSJaegeuk Kim return ret; 138439a53e0cSJaegeuk Kim } 138539a53e0cSJaegeuk Kim 1386c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1387c6ac4c0eSGu Zheng { 1388c6ac4c0eSGu Zheng int mask; 1389c6ac4c0eSGu Zheng 1390c6ac4c0eSGu Zheng addr += (nr >> 3); 1391c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1392c6ac4c0eSGu Zheng *addr ^= mask; 1393c6ac4c0eSGu Zheng } 1394c6ac4c0eSGu Zheng 139539a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 139639a53e0cSJaegeuk Kim enum { 139739a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1398b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1399ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 140039a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 140139a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 140239a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1403c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1404699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 140574d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1406c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1407444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 14081001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 140934d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1410fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1411fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 141288b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 141388b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 141402a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 14153c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 14161e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1417b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1418510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 141939a53e0cSJaegeuk Kim }; 142039a53e0cSJaegeuk Kim 142139a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 142239a53e0cSJaegeuk Kim { 142361e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 142439a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 142539a53e0cSJaegeuk Kim } 142639a53e0cSJaegeuk Kim 142739a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 142839a53e0cSJaegeuk Kim { 142939a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 143039a53e0cSJaegeuk Kim } 143139a53e0cSJaegeuk Kim 143239a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 143339a53e0cSJaegeuk Kim { 143461e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 143539a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 143639a53e0cSJaegeuk Kim } 143739a53e0cSJaegeuk Kim 143839a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 143939a53e0cSJaegeuk Kim { 144039a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 144139a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 144239a53e0cSJaegeuk Kim } 144339a53e0cSJaegeuk Kim 1444444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1445444c580fSJaegeuk Kim struct f2fs_inode *ri) 1446444c580fSJaegeuk Kim { 1447444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1448444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 14491001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 14501001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 145134d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 145234d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1453b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1454b3d208f9SJaegeuk Kim set_inode_flag(fi, FI_DATA_EXIST); 1455510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1456510022a8SJaegeuk Kim set_inode_flag(fi, FI_INLINE_DOTS); 1457444c580fSJaegeuk Kim } 1458444c580fSJaegeuk Kim 1459444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1460444c580fSJaegeuk Kim struct f2fs_inode *ri) 1461444c580fSJaegeuk Kim { 1462444c580fSJaegeuk Kim ri->i_inline = 0; 1463444c580fSJaegeuk Kim 1464444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1465444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 14661001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 14671001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 146834d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 146934d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1470b3d208f9SJaegeuk Kim if (is_inode_flag_set(fi, FI_DATA_EXIST)) 1471b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1472510022a8SJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_DOTS)) 1473510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1474444c580fSJaegeuk Kim } 1475444c580fSJaegeuk Kim 1476987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1477987c7c31SChao Yu { 1478987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1479987c7c31SChao Yu } 1480987c7c31SChao Yu 1481de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1482de93653fSJaegeuk Kim { 1483987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1484de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1485de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1486de93653fSJaegeuk Kim } 1487de93653fSJaegeuk Kim 148865985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 148965985d93SJaegeuk Kim { 1490695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 149165985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 149265985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 149365985d93SJaegeuk Kim } 149465985d93SJaegeuk Kim 149565985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 149665985d93SJaegeuk Kim { 1497987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 149865985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 149965985d93SJaegeuk Kim else 150065985d93SJaegeuk Kim return 0; 150165985d93SJaegeuk Kim } 150265985d93SJaegeuk Kim 15030dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 15040dbdc2aeSJaegeuk Kim { 15050dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 15060dbdc2aeSJaegeuk Kim } 15070dbdc2aeSJaegeuk Kim 1508b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1509b3d208f9SJaegeuk Kim { 1510b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 1511b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1512b3d208f9SJaegeuk Kim } 1513b3d208f9SJaegeuk Kim 1514b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1515b3d208f9SJaegeuk Kim { 1516b3d208f9SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST); 1517b3d208f9SJaegeuk Kim } 1518b3d208f9SJaegeuk Kim 1519510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1520510022a8SJaegeuk Kim { 1521510022a8SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS); 1522510022a8SJaegeuk Kim } 1523510022a8SJaegeuk Kim 152488b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 152588b88a66SJaegeuk Kim { 152688b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 152788b88a66SJaegeuk Kim } 152888b88a66SJaegeuk Kim 152902a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 153002a1335fSJaegeuk Kim { 153102a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 153202a1335fSJaegeuk Kim } 153302a1335fSJaegeuk Kim 15343c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 15353c6c2bebSJaegeuk Kim { 15363c6c2bebSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); 15373c6c2bebSJaegeuk Kim } 15383c6c2bebSJaegeuk Kim 15391e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 15401e84371fSJaegeuk Kim { 15411e84371fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE); 15421e84371fSJaegeuk Kim } 15431e84371fSJaegeuk Kim 15441001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 15451001b347SHuajun Li { 1546695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 15471001b347SHuajun Li return (void *)&(ri->i_addr[1]); 15481001b347SHuajun Li } 15491001b347SHuajun Li 155034d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 155134d67debSChao Yu { 155234d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 155334d67debSChao Yu } 155434d67debSChao Yu 15559486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 15569486ba44SJaegeuk Kim { 15579486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 15589486ba44SJaegeuk Kim kunmap(page); 15599486ba44SJaegeuk Kim } 15609486ba44SJaegeuk Kim 1561b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1562b5492af7SJaegeuk Kim { 1563b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1564b5492af7SJaegeuk Kim } 1565b5492af7SJaegeuk Kim 1566b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1567b5492af7SJaegeuk Kim { 1568b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1569b5492af7SJaegeuk Kim } 1570b5492af7SJaegeuk Kim 1571b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1572b5492af7SJaegeuk Kim { 1573b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1574b5492af7SJaegeuk Kim } 1575b5492af7SJaegeuk Kim 157677888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 157777888c1eSJaegeuk Kim { 157877888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 157977888c1eSJaegeuk Kim } 158077888c1eSJaegeuk Kim 15811e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 15821e968fdfSJaegeuk Kim { 15831e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 15841e968fdfSJaegeuk Kim } 15851e968fdfSJaegeuk Kim 1586744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1587744602cfSJaegeuk Kim { 1588744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1589744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1590744602cfSJaegeuk Kim } 1591744602cfSJaegeuk Kim 1592eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1593eaa693f4SJaegeuk Kim { 1594eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1595eaa693f4SJaegeuk Kim return true; 1596eaa693f4SJaegeuk Kim 1597eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1598eaa693f4SJaegeuk Kim return true; 1599eaa693f4SJaegeuk Kim 1600eaa693f4SJaegeuk Kim return false; 1601eaa693f4SJaegeuk Kim } 1602eaa693f4SJaegeuk Kim 16033e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 16043e72f721SJaegeuk Kim { 16053e72f721SJaegeuk Kim mode_t mode = inode->i_mode; 16063e72f721SJaegeuk Kim 16073e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 16083e72f721SJaegeuk Kim is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT)) 16093e72f721SJaegeuk Kim return false; 16103e72f721SJaegeuk Kim 16113e72f721SJaegeuk Kim return S_ISREG(mode); 16123e72f721SJaegeuk Kim } 16133e72f721SJaegeuk Kim 161439307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 161539307a8eSJaegeuk Kim { 161639307a8eSJaegeuk Kim void *ret; 161739307a8eSJaegeuk Kim 161839307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 161939307a8eSJaegeuk Kim if (!ret) 162039307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 162139307a8eSJaegeuk Kim return ret; 162239307a8eSJaegeuk Kim } 162339307a8eSJaegeuk Kim 162439307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 162539307a8eSJaegeuk Kim { 162639307a8eSJaegeuk Kim void *ret; 162739307a8eSJaegeuk Kim 162839307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 162939307a8eSJaegeuk Kim if (!ret) 163039307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 163139307a8eSJaegeuk Kim return ret; 163239307a8eSJaegeuk Kim } 163339307a8eSJaegeuk Kim 1634a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1635a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1636a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1637a6dda0e6SChristoph Hellwig 1638267378d4SChao Yu /* get offset of first page in next direct node */ 1639267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1640267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1641267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1642267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1643267378d4SChao Yu 164439a53e0cSJaegeuk Kim /* 164539a53e0cSJaegeuk Kim * file.c 164639a53e0cSJaegeuk Kim */ 164739a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 164839a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1649764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 1650b0154891SChao Yu int f2fs_truncate(struct inode *, bool); 16512d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 165239a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 165339a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1654b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 165539a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1656e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 165739a53e0cSJaegeuk Kim 165839a53e0cSJaegeuk Kim /* 165939a53e0cSJaegeuk Kim * inode.c 166039a53e0cSJaegeuk Kim */ 166139a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 166239a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 16634660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 166439a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *); 1665744602cfSJaegeuk Kim void update_inode_page(struct inode *); 166639a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 166739a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 166844c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 166939a53e0cSJaegeuk Kim 167039a53e0cSJaegeuk Kim /* 167139a53e0cSJaegeuk Kim * namei.c 167239a53e0cSJaegeuk Kim */ 167339a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 167439a53e0cSJaegeuk Kim 167539a53e0cSJaegeuk Kim /* 167639a53e0cSJaegeuk Kim * dir.c 167739a53e0cSJaegeuk Kim */ 1678dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1679510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 16806e22c691SJaegeuk Kim 16816e22c691SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct f2fs_filename *, 16826e22c691SJaegeuk Kim f2fs_hash_t, int *, struct f2fs_dentry_ptr *); 16837b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 1684d8c6822aSJaegeuk Kim unsigned int, struct f2fs_str *); 1685062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1686062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1687dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1688bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1689dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1690a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1691dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 169239a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 169339a53e0cSJaegeuk Kim struct page **); 169439a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 169539a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 169639a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 169739a53e0cSJaegeuk Kim struct page *, struct inode *); 1698e7d55452SJaegeuk Kim int update_dent_inode(struct inode *, struct inode *, const struct qstr *); 1699510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 17003b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1701510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1702510022a8SJaegeuk Kim umode_t); 1703dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1704dbeacf02SChao Yu struct inode *); 1705b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 170639a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 170739a53e0cSJaegeuk Kim 1708b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1709b7f7a5e0SAl Viro { 17102b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1711510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1712b7f7a5e0SAl Viro } 1713b7f7a5e0SAl Viro 171439a53e0cSJaegeuk Kim /* 171539a53e0cSJaegeuk Kim * super.c 171639a53e0cSJaegeuk Kim */ 1717c5bda1c8SChao Yu int f2fs_commit_super(struct f2fs_sb_info *, bool); 171839a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1719a07ef784SNamjae Jeon extern __printf(3, 4) 1720a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 172139a53e0cSJaegeuk Kim 172239a53e0cSJaegeuk Kim /* 172339a53e0cSJaegeuk Kim * hash.c 172439a53e0cSJaegeuk Kim */ 1725eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 172639a53e0cSJaegeuk Kim 172739a53e0cSJaegeuk Kim /* 172839a53e0cSJaegeuk Kim * node.c 172939a53e0cSJaegeuk Kim */ 173039a53e0cSJaegeuk Kim struct dnode_of_data; 173139a53e0cSJaegeuk Kim struct node_info; 173239a53e0cSJaegeuk Kim 17336fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 17342dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t); 173588bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 173688bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 173739a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 173839a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 173939a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 17404f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1741cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 174213ec7297SChao Yu int remove_inode_page(struct inode *); 1743a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 17448ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 174539a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 174639a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 174739a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 174839a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 174939a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 175039a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 175139a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 175239a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 175331696580SChao Yu int try_to_free_nids(struct f2fs_sb_info *, int); 175470cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 17551c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 175639a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 175739a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 175839a53e0cSJaegeuk Kim struct f2fs_summary_block *); 175939a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 176039a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 176139a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 17626e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 176339a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 176439a53e0cSJaegeuk Kim 176539a53e0cSJaegeuk Kim /* 176639a53e0cSJaegeuk Kim * segment.c 176739a53e0cSJaegeuk Kim */ 176888b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 1769edb27deeSJaegeuk Kim int commit_inmem_pages(struct inode *, bool); 177039a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *); 17714660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 17726b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 17732163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 17742163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 177539a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 17766e2c64adSJaegeuk Kim bool is_checkpointed_data(struct f2fs_sb_info *, block_t); 17775e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 1778836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 17794b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1780e90c2d28SChao Yu bool discard_next_dnode(struct f2fs_sb_info *, block_t); 17813fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 178239a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 17834b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 178439a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1785381722d2SChao Yu void update_meta_page(struct f2fs_sb_info *, void *, block_t); 1786577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 178705ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 178805ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 178905ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 1790528e3459SChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *, 1791528e3459SChao Yu block_t, block_t, unsigned char, bool); 1792bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1793bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 17945514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 179508b39fbdSChao Yu void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t); 179639a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 179739a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 179839a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 179939a53e0cSJaegeuk Kim int, unsigned int, int); 18004b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 180139a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 180239a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 18037fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 18047fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 180539a53e0cSJaegeuk Kim 180639a53e0cSJaegeuk Kim /* 180739a53e0cSJaegeuk Kim * checkpoint.c 180839a53e0cSJaegeuk Kim */ 180939a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 181039a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 18112b947003SChao Yu struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t); 1812f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 181326879fb1SChao Yu int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool); 1814635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 181539a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1816fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1817fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 18186f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *); 1819fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1820cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1821cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 182239a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 182339a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 18248c14bfadSChao Yu int recover_orphan_inodes(struct f2fs_sb_info *); 182539a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1826a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 18275deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 182839a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *); 182939a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *); 183075ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 18316451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 18326e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 183339a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 183439a53e0cSJaegeuk Kim 183539a53e0cSJaegeuk Kim /* 183639a53e0cSJaegeuk Kim * data.c 183739a53e0cSJaegeuk Kim */ 1838458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 183905ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 184005ca3632SJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_io_info *); 1841216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 184239a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1843759af1c9SFan Li int f2fs_get_block(struct dnode_of_data *, pgoff_t); 1844b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 1845a56c7c6fSJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int, bool); 184643f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t); 1847a56c7c6fSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t, bool); 184864aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 184905ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 18509ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1851487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1852487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 185339a53e0cSJaegeuk Kim 185439a53e0cSJaegeuk Kim /* 185539a53e0cSJaegeuk Kim * gc.c 185639a53e0cSJaegeuk Kim */ 185739a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 185839a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1859de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1860d530d4d8SChao Yu int f2fs_gc(struct f2fs_sb_info *, bool); 186139a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 186239a53e0cSJaegeuk Kim 186339a53e0cSJaegeuk Kim /* 186439a53e0cSJaegeuk Kim * recovery.c 186539a53e0cSJaegeuk Kim */ 18666ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 186739a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 186839a53e0cSJaegeuk Kim 186939a53e0cSJaegeuk Kim /* 187039a53e0cSJaegeuk Kim * debug.c 187139a53e0cSJaegeuk Kim */ 187239a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 187339a53e0cSJaegeuk Kim struct f2fs_stat_info { 187439a53e0cSJaegeuk Kim struct list_head stat_list; 187539a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 187639a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 187739a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 18785b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 18795b7ee374SChao Yu unsigned long long hit_total, total_ext; 1880029e13ccSChao Yu int ext_tree, ext_node; 188139a53e0cSJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 1882dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 188339a53e0cSJaegeuk Kim int total_count, utilization; 1884d5e8f6c9SChao Yu int bg_gc, inmem_pages, wb_pages; 1885d5e8f6c9SChao Yu int inline_xattr, inline_inode, inline_dir; 188639a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 188739a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 188839a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 188939a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 189039a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1891942e0be6SChangman Lee int prefree_count, call_count, cp_count; 189239a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 1893e1235983SChangman Lee int bg_node_segs, bg_data_segs; 189439a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 1895e1235983SChangman Lee int bg_data_blks, bg_node_blks; 189639a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 189739a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 189839a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 189939a53e0cSJaegeuk Kim 190039a53e0cSJaegeuk Kim unsigned int segment_count[2]; 190139a53e0cSJaegeuk Kim unsigned int block_count[2]; 1902b9a2c252SChangman Lee unsigned int inplace_count; 19039edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 190439a53e0cSJaegeuk Kim }; 190539a53e0cSJaegeuk Kim 1906963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1907963d4f7dSGu Zheng { 1908963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1909963d4f7dSGu Zheng } 1910963d4f7dSGu Zheng 1911942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 191239a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1913dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1914dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1915dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 19165b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 19175b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 19185b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 19195b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 1920d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 1921d5e8f6c9SChao Yu do { \ 1922d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1923d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 1924d5e8f6c9SChao Yu } while (0) 1925d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 1926d5e8f6c9SChao Yu do { \ 1927d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1928d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 1929d5e8f6c9SChao Yu } while (0) 19300dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 19310dbdc2aeSJaegeuk Kim do { \ 19320dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 193303e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 19340dbdc2aeSJaegeuk Kim } while (0) 19350dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 19360dbdc2aeSJaegeuk Kim do { \ 19370dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 193803e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 19390dbdc2aeSJaegeuk Kim } while (0) 19403289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 19413289c061SJaegeuk Kim do { \ 19423289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 194303e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 19443289c061SJaegeuk Kim } while (0) 19453289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 19463289c061SJaegeuk Kim do { \ 19473289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 194803e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 19493289c061SJaegeuk Kim } while (0) 1950dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1951dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1952dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1953dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 1954b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 1955b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 1956e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 195739a53e0cSJaegeuk Kim do { \ 1958963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 195939a53e0cSJaegeuk Kim (si)->tot_segs++; \ 1960e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 196139a53e0cSJaegeuk Kim si->data_segs++; \ 1962e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 1963e1235983SChangman Lee } else { \ 196439a53e0cSJaegeuk Kim si->node_segs++; \ 1965e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 1966e1235983SChangman Lee } \ 196739a53e0cSJaegeuk Kim } while (0) 196839a53e0cSJaegeuk Kim 196939a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 197039a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 197139a53e0cSJaegeuk Kim 1972e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 197339a53e0cSJaegeuk Kim do { \ 1974963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 197539a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 197639a53e0cSJaegeuk Kim si->data_blks += (blks); \ 1977e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 197839a53e0cSJaegeuk Kim } while (0) 197939a53e0cSJaegeuk Kim 1980e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 198139a53e0cSJaegeuk Kim do { \ 1982963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 198339a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 198439a53e0cSJaegeuk Kim si->node_blks += (blks); \ 1985e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 198639a53e0cSJaegeuk Kim } while (0) 198739a53e0cSJaegeuk Kim 198839a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 198939a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 1990*787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 19914589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 199239a53e0cSJaegeuk Kim #else 1993942e0be6SChangman Lee #define stat_inc_cp_count(si) 199439a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 1995dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 1996dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) 1997dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) 1998dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 1999029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 200091c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 200191c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 2002d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 2003d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 20040dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 20050dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 20063289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 20073289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 2008dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 2009dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 2010b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 2011e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 201239a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 2013e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 2014e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 201539a53e0cSJaegeuk Kim 201639a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 201739a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2018*787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 20194589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 202039a53e0cSJaegeuk Kim #endif 202139a53e0cSJaegeuk Kim 202239a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 202339a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 202439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 202539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 202639a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 202739a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 202839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 202939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2030cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 203139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 203229e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 20331001b347SHuajun Li 2034e18c65b2SHuajun Li /* 2035e18c65b2SHuajun Li * inline.c 2036e18c65b2SHuajun Li */ 203701b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 203801b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 2039b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 20400bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 2041e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 2042b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 2043b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 2044b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 20450342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 20466e22c691SJaegeuk Kim struct f2fs_dir_entry *find_in_inline_dir(struct inode *, 20476e22c691SJaegeuk Kim struct f2fs_filename *, struct page **); 2048201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 2049201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 2050510022a8SJaegeuk Kim int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 2051510022a8SJaegeuk Kim nid_t, umode_t); 2052201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 2053201a05beSChao Yu struct inode *, struct inode *); 2054201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 2055d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *, struct dir_context *, 2056d8c6822aSJaegeuk Kim struct f2fs_str *); 205767f8cf3cSJaegeuk Kim int f2fs_inline_data_fiemap(struct inode *, 205867f8cf3cSJaegeuk Kim struct fiemap_extent_info *, __u64, __u64); 2059cde4de12SJaegeuk Kim 2060cde4de12SJaegeuk Kim /* 20612658e50dSJaegeuk Kim * shrinker.c 20622658e50dSJaegeuk Kim */ 20632658e50dSJaegeuk Kim unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *); 20642658e50dSJaegeuk Kim unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *); 20652658e50dSJaegeuk Kim void f2fs_join_shrinker(struct f2fs_sb_info *); 20662658e50dSJaegeuk Kim void f2fs_leave_shrinker(struct f2fs_sb_info *); 20672658e50dSJaegeuk Kim 20682658e50dSJaegeuk Kim /* 2069a28ef1f5SChao Yu * extent_cache.c 2070a28ef1f5SChao Yu */ 2071a28ef1f5SChao Yu unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 2072a28ef1f5SChao Yu void f2fs_drop_largest_extent(struct inode *, pgoff_t); 2073a28ef1f5SChao Yu void f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 2074a28ef1f5SChao Yu unsigned int f2fs_destroy_extent_node(struct inode *); 2075a28ef1f5SChao Yu void f2fs_destroy_extent_tree(struct inode *); 2076a28ef1f5SChao Yu bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *); 2077a28ef1f5SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 207819b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 207919b2c30dSChao Yu pgoff_t, block_t, unsigned int); 2080a28ef1f5SChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 2081a28ef1f5SChao Yu int __init create_extent_cache(void); 2082a28ef1f5SChao Yu void destroy_extent_cache(void); 2083a28ef1f5SChao Yu 2084a28ef1f5SChao Yu /* 2085cde4de12SJaegeuk Kim * crypto support 2086cde4de12SJaegeuk Kim */ 2087cde4de12SJaegeuk Kim static inline int f2fs_encrypted_inode(struct inode *inode) 2088cde4de12SJaegeuk Kim { 2089cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2090cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2091cde4de12SJaegeuk Kim #else 2092cde4de12SJaegeuk Kim return 0; 2093cde4de12SJaegeuk Kim #endif 2094cde4de12SJaegeuk Kim } 2095cde4de12SJaegeuk Kim 2096cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2097cde4de12SJaegeuk Kim { 2098cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2099cde4de12SJaegeuk Kim file_set_encrypt(inode); 2100cde4de12SJaegeuk Kim #endif 2101cde4de12SJaegeuk Kim } 2102cde4de12SJaegeuk Kim 2103cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2104cde4de12SJaegeuk Kim { 2105cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2106cde4de12SJaegeuk Kim return unlikely(bio->bi_private != NULL); 2107cde4de12SJaegeuk Kim #else 2108cde4de12SJaegeuk Kim return false; 2109cde4de12SJaegeuk Kim #endif 2110cde4de12SJaegeuk Kim } 2111cde4de12SJaegeuk Kim 2112cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2113cde4de12SJaegeuk Kim { 2114cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2115cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2116cde4de12SJaegeuk Kim #else 2117cde4de12SJaegeuk Kim return 0; 2118cde4de12SJaegeuk Kim #endif 2119cde4de12SJaegeuk Kim } 2120f424f664SJaegeuk Kim 2121fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2122fcc85a4dSJaegeuk Kim { 2123fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2124fcc85a4dSJaegeuk Kim mode_t mode = inode->i_mode; 2125fcc85a4dSJaegeuk Kim 2126fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2127fcc85a4dSJaegeuk Kim #else 2128fcc85a4dSJaegeuk Kim return 0; 2129fcc85a4dSJaegeuk Kim #endif 2130fcc85a4dSJaegeuk Kim } 2131fcc85a4dSJaegeuk Kim 2132f424f664SJaegeuk Kim /* crypto_policy.c */ 2133f424f664SJaegeuk Kim int f2fs_is_child_context_consistent_with_parent(struct inode *, 2134f424f664SJaegeuk Kim struct inode *); 2135f424f664SJaegeuk Kim int f2fs_inherit_context(struct inode *, struct inode *, struct page *); 2136f424f664SJaegeuk Kim int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *); 2137f424f664SJaegeuk Kim int f2fs_get_policy(struct inode *, struct f2fs_encryption_policy *); 213857e5055bSJaegeuk Kim 213957e5055bSJaegeuk Kim /* crypt.c */ 21408bacf6deSJaegeuk Kim extern struct kmem_cache *f2fs_crypt_info_cachep; 214157e5055bSJaegeuk Kim bool f2fs_valid_contents_enc_mode(uint32_t); 214257e5055bSJaegeuk Kim uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t); 214357e5055bSJaegeuk Kim struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *); 214457e5055bSJaegeuk Kim void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *); 214557e5055bSJaegeuk Kim struct page *f2fs_encrypt(struct inode *, struct page *); 214657e5055bSJaegeuk Kim int f2fs_decrypt(struct f2fs_crypto_ctx *, struct page *); 214757e5055bSJaegeuk Kim int f2fs_decrypt_one(struct inode *, struct page *); 214857e5055bSJaegeuk Kim void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *); 214957e5055bSJaegeuk Kim 21500adda907SJaegeuk Kim /* crypto_key.c */ 215126bf3dc7SJaegeuk Kim void f2fs_free_encryption_info(struct inode *, struct f2fs_crypt_info *); 21520adda907SJaegeuk Kim int _f2fs_get_encryption_info(struct inode *inode); 21530adda907SJaegeuk Kim 21546b3bd08fSJaegeuk Kim /* crypto_fname.c */ 21556b3bd08fSJaegeuk Kim bool f2fs_valid_filenames_enc_mode(uint32_t); 21566b3bd08fSJaegeuk Kim u32 f2fs_fname_crypto_round_up(u32, u32); 21576b3bd08fSJaegeuk Kim int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *); 21586b3bd08fSJaegeuk Kim int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *, 21596b3bd08fSJaegeuk Kim const struct f2fs_str *, struct f2fs_str *); 21606b3bd08fSJaegeuk Kim int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *, 21616b3bd08fSJaegeuk Kim struct f2fs_str *); 21626b3bd08fSJaegeuk Kim 216357e5055bSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 216457e5055bSJaegeuk Kim void f2fs_restore_and_release_control_page(struct page **); 216557e5055bSJaegeuk Kim void f2fs_restore_control_page(struct page *); 216657e5055bSJaegeuk Kim 2167cfc4d971SJaegeuk Kim int __init f2fs_init_crypto(void); 2168cfc4d971SJaegeuk Kim int f2fs_crypto_initialize(void); 216957e5055bSJaegeuk Kim void f2fs_exit_crypto(void); 21700adda907SJaegeuk Kim 21710adda907SJaegeuk Kim int f2fs_has_encryption_key(struct inode *); 21720adda907SJaegeuk Kim 21730adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *inode) 21740adda907SJaegeuk Kim { 21750adda907SJaegeuk Kim struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info; 21760adda907SJaegeuk Kim 21770adda907SJaegeuk Kim if (!ci || 21780adda907SJaegeuk Kim (ci->ci_keyring_key && 21790adda907SJaegeuk Kim (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | 21800adda907SJaegeuk Kim (1 << KEY_FLAG_REVOKED) | 21810adda907SJaegeuk Kim (1 << KEY_FLAG_DEAD))))) 21820adda907SJaegeuk Kim return _f2fs_get_encryption_info(inode); 21830adda907SJaegeuk Kim return 0; 21840adda907SJaegeuk Kim } 21856b3bd08fSJaegeuk Kim 21866b3bd08fSJaegeuk Kim void f2fs_fname_crypto_free_buffer(struct f2fs_str *); 21876b3bd08fSJaegeuk Kim int f2fs_fname_setup_filename(struct inode *, const struct qstr *, 21886b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *); 21896b3bd08fSJaegeuk Kim void f2fs_fname_free_filename(struct f2fs_filename *); 219057e5055bSJaegeuk Kim #else 219157e5055bSJaegeuk Kim static inline void f2fs_restore_and_release_control_page(struct page **p) { } 219257e5055bSJaegeuk Kim static inline void f2fs_restore_control_page(struct page *p) { } 219357e5055bSJaegeuk Kim 2194cfc4d971SJaegeuk Kim static inline int __init f2fs_init_crypto(void) { return 0; } 219557e5055bSJaegeuk Kim static inline void f2fs_exit_crypto(void) { } 21960adda907SJaegeuk Kim 21970adda907SJaegeuk Kim static inline int f2fs_has_encryption_key(struct inode *i) { return 0; } 21980adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *i) { return 0; } 21996b3bd08fSJaegeuk Kim static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { } 22006b3bd08fSJaegeuk Kim 22016b3bd08fSJaegeuk Kim static inline int f2fs_fname_setup_filename(struct inode *dir, 22026b3bd08fSJaegeuk Kim const struct qstr *iname, 22036b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *fname) 22046b3bd08fSJaegeuk Kim { 22056b3bd08fSJaegeuk Kim memset(fname, 0, sizeof(struct f2fs_filename)); 22066b3bd08fSJaegeuk Kim fname->usr_fname = iname; 22076b3bd08fSJaegeuk Kim fname->disk_name.name = (unsigned char *)iname->name; 22086b3bd08fSJaegeuk Kim fname->disk_name.len = iname->len; 22096b3bd08fSJaegeuk Kim return 0; 22106b3bd08fSJaegeuk Kim } 22116b3bd08fSJaegeuk Kim 22126b3bd08fSJaegeuk Kim static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { } 221357e5055bSJaegeuk Kim #endif 221439a53e0cSJaegeuk Kim #endif 2215