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 57343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 5839a53e0cSJaegeuk Kim 5939a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 6039a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 6139a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 6239a53e0cSJaegeuk Kim 6339a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 6439a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 6539a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 6639a53e0cSJaegeuk Kim 67a9841c4dSJaegeuk Kim typedef u32 block_t; /* 68a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 69a9841c4dSJaegeuk Kim * address format, __le32. 70a9841c4dSJaegeuk Kim */ 7139a53e0cSJaegeuk Kim typedef u32 nid_t; 7239a53e0cSJaegeuk Kim 7339a53e0cSJaegeuk Kim struct f2fs_mount_info { 7439a53e0cSJaegeuk Kim unsigned int opt; 7539a53e0cSJaegeuk Kim }; 7639a53e0cSJaegeuk Kim 77cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 78cde4de12SJaegeuk Kim 7976f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 8076f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 8176f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 8276f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) 8376f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 8476f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) 8576f105a2SJaegeuk Kim 867e586fa0SJaegeuk Kim #define CRCPOLY_LE 0xedb88320 877e586fa0SJaegeuk Kim 887e586fa0SJaegeuk Kim static inline __u32 f2fs_crc32(void *buf, size_t len) 8939a53e0cSJaegeuk Kim { 907e586fa0SJaegeuk Kim unsigned char *p = (unsigned char *)buf; 917e586fa0SJaegeuk Kim __u32 crc = F2FS_SUPER_MAGIC; 927e586fa0SJaegeuk Kim int i; 937e586fa0SJaegeuk Kim 947e586fa0SJaegeuk Kim while (len--) { 957e586fa0SJaegeuk Kim crc ^= *p++; 967e586fa0SJaegeuk Kim for (i = 0; i < 8; i++) 977e586fa0SJaegeuk Kim crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); 987e586fa0SJaegeuk Kim } 997e586fa0SJaegeuk Kim return crc; 10039a53e0cSJaegeuk Kim } 10139a53e0cSJaegeuk Kim 1027e586fa0SJaegeuk Kim static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size) 10339a53e0cSJaegeuk Kim { 1047e586fa0SJaegeuk Kim return f2fs_crc32(buf, buf_size) == blk_crc; 10539a53e0cSJaegeuk Kim } 10639a53e0cSJaegeuk Kim 10739a53e0cSJaegeuk Kim /* 10839a53e0cSJaegeuk Kim * For checkpoint manager 10939a53e0cSJaegeuk Kim */ 11039a53e0cSJaegeuk Kim enum { 11139a53e0cSJaegeuk Kim NAT_BITMAP, 11239a53e0cSJaegeuk Kim SIT_BITMAP 11339a53e0cSJaegeuk Kim }; 11439a53e0cSJaegeuk Kim 11575ab4cb8SJaegeuk Kim enum { 11675ab4cb8SJaegeuk Kim CP_UMOUNT, 117119ee914SJaegeuk Kim CP_FASTBOOT, 11875ab4cb8SJaegeuk Kim CP_SYNC, 11910027551SJaegeuk Kim CP_RECOVERY, 1204b2fecc8SJaegeuk Kim CP_DISCARD, 12175ab4cb8SJaegeuk Kim }; 12275ab4cb8SJaegeuk Kim 123bba681cbSJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 32 124bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 125bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 126a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 127a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 12860b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 129bba681cbSJaegeuk Kim 13075ab4cb8SJaegeuk Kim struct cp_control { 13175ab4cb8SJaegeuk Kim int reason; 1324b2fecc8SJaegeuk Kim __u64 trim_start; 1334b2fecc8SJaegeuk Kim __u64 trim_end; 1344b2fecc8SJaegeuk Kim __u64 trim_minlen; 1354b2fecc8SJaegeuk Kim __u64 trimmed; 13675ab4cb8SJaegeuk Kim }; 13775ab4cb8SJaegeuk Kim 138662befdaSChao Yu /* 13981c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 140662befdaSChao Yu */ 141662befdaSChao Yu enum { 142662befdaSChao Yu META_CP, 143662befdaSChao Yu META_NAT, 14481c1a0f1SChao Yu META_SIT, 1454c521f49SJaegeuk Kim META_SSA, 1464c521f49SJaegeuk Kim META_POR, 147662befdaSChao Yu }; 148662befdaSChao Yu 1496451e041SJaegeuk Kim /* for the list of ino */ 1506451e041SJaegeuk Kim enum { 1516451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 152fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 153fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1546451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1556451e041SJaegeuk Kim }; 1566451e041SJaegeuk Kim 1576451e041SJaegeuk Kim struct ino_entry { 15839a53e0cSJaegeuk Kim struct list_head list; /* list head */ 15939a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 16039a53e0cSJaegeuk Kim }; 16139a53e0cSJaegeuk Kim 1622710fd7eSChao Yu /* for the list of inodes to be GCed */ 16306292073SChao Yu struct inode_entry { 16439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 16539a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 16639a53e0cSJaegeuk Kim }; 16739a53e0cSJaegeuk Kim 1687fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1697fd9e544SJaegeuk Kim struct discard_entry { 1707fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1717fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1727fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1737fd9e544SJaegeuk Kim }; 1747fd9e544SJaegeuk Kim 17539a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 17639a53e0cSJaegeuk Kim struct fsync_inode_entry { 17739a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17839a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 179c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 180c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 181c52e1b10SJaegeuk Kim block_t last_inode; /* block address locating the last inode */ 18239a53e0cSJaegeuk Kim }; 18339a53e0cSJaegeuk Kim 18439a53e0cSJaegeuk Kim #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats)) 18539a53e0cSJaegeuk Kim #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits)) 18639a53e0cSJaegeuk Kim 18739a53e0cSJaegeuk Kim #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne) 18839a53e0cSJaegeuk Kim #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid) 18939a53e0cSJaegeuk Kim #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se) 19039a53e0cSJaegeuk Kim #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno) 19139a53e0cSJaegeuk Kim 192309cc2b6SJaegeuk Kim #define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum)) 193309cc2b6SJaegeuk Kim #define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum)) 194309cc2b6SJaegeuk Kim 19539a53e0cSJaegeuk Kim static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i) 19639a53e0cSJaegeuk Kim { 19739a53e0cSJaegeuk Kim int before = nats_in_cursum(rs); 19839a53e0cSJaegeuk Kim rs->n_nats = cpu_to_le16(before + i); 19939a53e0cSJaegeuk Kim return before; 20039a53e0cSJaegeuk Kim } 20139a53e0cSJaegeuk Kim 20239a53e0cSJaegeuk Kim static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i) 20339a53e0cSJaegeuk Kim { 20439a53e0cSJaegeuk Kim int before = sits_in_cursum(rs); 20539a53e0cSJaegeuk Kim rs->n_sits = cpu_to_le16(before + i); 20639a53e0cSJaegeuk Kim return before; 20739a53e0cSJaegeuk Kim } 20839a53e0cSJaegeuk Kim 209184a5cd2SChao Yu static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size, 210184a5cd2SChao Yu int type) 211184a5cd2SChao Yu { 212184a5cd2SChao Yu if (type == NAT_JOURNAL) 213309cc2b6SJaegeuk Kim return size <= MAX_NAT_JENTRIES(sum); 214309cc2b6SJaegeuk Kim return size <= MAX_SIT_JENTRIES(sum); 215184a5cd2SChao Yu } 216184a5cd2SChao Yu 21739a53e0cSJaegeuk Kim /* 218e9750824SNamjae Jeon * ioctl commands 219e9750824SNamjae Jeon */ 220e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 221e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 222d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 223e9750824SNamjae Jeon 22488b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 22588b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 22688b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 22702a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2281e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2291e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 230c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 231456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 232d323d005SChao Yu #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) 23388b88a66SJaegeuk Kim 234f424f664SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY \ 235f424f664SJaegeuk Kim _IOR('f', 19, struct f2fs_encryption_policy) 236f424f664SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT \ 237f424f664SJaegeuk Kim _IOW('f', 20, __u8[16]) 238f424f664SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY \ 239f424f664SJaegeuk Kim _IOW('f', 21, struct f2fs_encryption_policy) 240f424f664SJaegeuk Kim 2411abff93dSJaegeuk Kim /* 2421abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2431abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2441abff93dSJaegeuk Kim */ 2451abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2461abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2471abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2481abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 249c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 2501abff93dSJaegeuk Kim 251e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 252e9750824SNamjae Jeon /* 253e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 254e9750824SNamjae Jeon */ 255e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 256e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 25704ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 258e9750824SNamjae Jeon #endif 259e9750824SNamjae Jeon 260d323d005SChao Yu struct f2fs_defragment { 261d323d005SChao Yu u64 start; 262d323d005SChao Yu u64 len; 263d323d005SChao Yu }; 264d323d005SChao Yu 265e9750824SNamjae Jeon /* 26639a53e0cSJaegeuk Kim * For INODE and NODE manager 26739a53e0cSJaegeuk Kim */ 2687b3cd7d6SJaegeuk Kim /* for directory operations */ 2696b3bd08fSJaegeuk Kim struct f2fs_str { 2706b3bd08fSJaegeuk Kim unsigned char *name; 2716b3bd08fSJaegeuk Kim u32 len; 2726b3bd08fSJaegeuk Kim }; 2736b3bd08fSJaegeuk Kim 2746b3bd08fSJaegeuk Kim struct f2fs_filename { 2756b3bd08fSJaegeuk Kim const struct qstr *usr_fname; 2766b3bd08fSJaegeuk Kim struct f2fs_str disk_name; 2776b3bd08fSJaegeuk Kim f2fs_hash_t hash; 2786b3bd08fSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2796b3bd08fSJaegeuk Kim struct f2fs_str crypto_buf; 2806b3bd08fSJaegeuk Kim #endif 2816b3bd08fSJaegeuk Kim }; 2826b3bd08fSJaegeuk Kim 2836b3bd08fSJaegeuk Kim #define FSTR_INIT(n, l) { .name = n, .len = l } 2846b3bd08fSJaegeuk Kim #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len) 2856b3bd08fSJaegeuk Kim #define fname_name(p) ((p)->disk_name.name) 2866b3bd08fSJaegeuk Kim #define fname_len(p) ((p)->disk_name.len) 2876b3bd08fSJaegeuk Kim 2887b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 289d8c6822aSJaegeuk Kim struct inode *inode; 2907b3cd7d6SJaegeuk Kim const void *bitmap; 2917b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 2927b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 2937b3cd7d6SJaegeuk Kim int max; 2947b3cd7d6SJaegeuk Kim }; 2957b3cd7d6SJaegeuk Kim 296d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode, 297d8c6822aSJaegeuk Kim struct f2fs_dentry_ptr *d, void *src, int type) 2987b3cd7d6SJaegeuk Kim { 299d8c6822aSJaegeuk Kim d->inode = inode; 300d8c6822aSJaegeuk Kim 3017b3cd7d6SJaegeuk Kim if (type == 1) { 3027b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 3037b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 3047b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3057b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3067b3cd7d6SJaegeuk Kim d->filename = t->filename; 3077b3cd7d6SJaegeuk Kim } else { 3087b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 3097b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3107b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3117b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3127b3cd7d6SJaegeuk Kim d->filename = t->filename; 3137b3cd7d6SJaegeuk Kim } 3147b3cd7d6SJaegeuk Kim } 3157b3cd7d6SJaegeuk Kim 316dbe6a5ffSJaegeuk Kim /* 317dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 318dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 319dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 32039a53e0cSJaegeuk Kim */ 321dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 322dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 323266e97a8SJaegeuk Kim enum { 324266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 325266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 326266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 327266e97a8SJaegeuk Kim * look up a node with readahead called 3284f4124d0SChao Yu * by get_data_block. 32939a53e0cSJaegeuk Kim */ 330266e97a8SJaegeuk Kim }; 331266e97a8SJaegeuk Kim 332a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 33339a53e0cSJaegeuk Kim 334817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 335817202d9SChao Yu 33613054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 33713054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 33813054c54SChao Yu 33939a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 34013054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 34113054c54SChao Yu 34213054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 34313054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 344c11abd1aSJaegeuk Kim 34539a53e0cSJaegeuk Kim struct extent_info { 34639a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3474d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 348111d2495SMasanari Iida unsigned int len; /* length of the extent */ 34939a53e0cSJaegeuk Kim }; 35039a53e0cSJaegeuk Kim 35113054c54SChao Yu struct extent_node { 35213054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 35313054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 35413054c54SChao Yu struct extent_info ei; /* extent info */ 35513054c54SChao Yu }; 35613054c54SChao Yu 35713054c54SChao Yu struct extent_tree { 35813054c54SChao Yu nid_t ino; /* inode number */ 35913054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 36062c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 3613e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 362137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 36313054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 36468e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 36513054c54SChao Yu }; 36613054c54SChao Yu 36739a53e0cSJaegeuk Kim /* 368003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 369003a3e1dSJaegeuk Kim * 370003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 371003a3e1dSJaegeuk Kim */ 372003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 373003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 3747f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 3757f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 3767f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 377003a3e1dSJaegeuk Kim 378003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 379003a3e1dSJaegeuk Kim block_t m_pblk; 380003a3e1dSJaegeuk Kim block_t m_lblk; 381003a3e1dSJaegeuk Kim unsigned int m_len; 382003a3e1dSJaegeuk Kim unsigned int m_flags; 383003a3e1dSJaegeuk Kim }; 384003a3e1dSJaegeuk Kim 385e2b4e2bcSChao Yu /* for flag in get_data_block */ 386e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 387e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 388e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 389e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 390e2b4e2bcSChao Yu 391003a3e1dSJaegeuk Kim /* 39239a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 39339a53e0cSJaegeuk Kim */ 39439a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 395354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 396cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 397e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 39839a53e0cSJaegeuk Kim 399b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 400b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 401b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 402b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 403b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 404b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 405cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 406cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 407cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 408e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 409e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 410cde4de12SJaegeuk Kim 411cde4de12SJaegeuk Kim /* Encryption algorithms */ 412cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_INVALID 0 413cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_XTS 1 414cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_GCM 2 415cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CBC 3 416cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CTS 4 417b5492af7SJaegeuk Kim 418f424f664SJaegeuk Kim #include "f2fs_crypto.h" 419f424f664SJaegeuk Kim 420ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 421ab9fa662SJaegeuk Kim 42239a53e0cSJaegeuk Kim struct f2fs_inode_info { 42339a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 42439a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 42539a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 42638431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 42739a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4286666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 42939a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 43039a53e0cSJaegeuk Kim 43139a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 43239a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 433d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 434a7ffdbe2SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 43539a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 43639a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 43739a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 438e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 43988b88a66SJaegeuk Kim 4402710fd7eSChao Yu struct list_head dirty_list; /* linked in global dirty list */ 44188b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 44288b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 443cde4de12SJaegeuk Kim 4443e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 4453e72f721SJaegeuk Kim 446cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 447cde4de12SJaegeuk Kim /* Encryption params */ 448cde4de12SJaegeuk Kim struct f2fs_crypt_info *i_crypt_info; 449cde4de12SJaegeuk Kim #endif 45039a53e0cSJaegeuk Kim }; 45139a53e0cSJaegeuk Kim 45239a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 45339a53e0cSJaegeuk Kim struct f2fs_extent i_ext) 45439a53e0cSJaegeuk Kim { 45539a53e0cSJaegeuk Kim ext->fofs = le32_to_cpu(i_ext.fofs); 4564d0b0bd4SChao Yu ext->blk = le32_to_cpu(i_ext.blk); 45739a53e0cSJaegeuk Kim ext->len = le32_to_cpu(i_ext.len); 45839a53e0cSJaegeuk Kim } 45939a53e0cSJaegeuk Kim 46039a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 46139a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 46239a53e0cSJaegeuk Kim { 46339a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4644d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 46539a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 46639a53e0cSJaegeuk Kim } 46739a53e0cSJaegeuk Kim 468429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 469429511cdSChao Yu u32 blk, unsigned int len) 470429511cdSChao Yu { 471429511cdSChao Yu ei->fofs = fofs; 472429511cdSChao Yu ei->blk = blk; 473429511cdSChao Yu ei->len = len; 474429511cdSChao Yu } 475429511cdSChao Yu 4760bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1, 4770bdee482SChao Yu struct extent_info *ei2) 4780bdee482SChao Yu { 4790bdee482SChao Yu return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 4800bdee482SChao Yu ei1->len == ei2->len); 4810bdee482SChao Yu } 4820bdee482SChao Yu 483429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 484429511cdSChao Yu struct extent_info *front) 485429511cdSChao Yu { 486429511cdSChao Yu return (back->fofs + back->len == front->fofs && 487429511cdSChao Yu back->blk + back->len == front->blk); 488429511cdSChao Yu } 489429511cdSChao Yu 490429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 491429511cdSChao Yu struct extent_info *back) 492429511cdSChao Yu { 493429511cdSChao Yu return __is_extent_mergeable(back, cur); 494429511cdSChao Yu } 495429511cdSChao Yu 496429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 497429511cdSChao Yu struct extent_info *front) 498429511cdSChao Yu { 499429511cdSChao Yu return __is_extent_mergeable(cur, front); 500429511cdSChao Yu } 501429511cdSChao Yu 5024abd3f5aSChao Yu static inline void __try_update_largest_extent(struct extent_tree *et, 5034abd3f5aSChao Yu struct extent_node *en) 5044abd3f5aSChao Yu { 5054abd3f5aSChao Yu if (en->ei.len > et->largest.len) 5064abd3f5aSChao Yu et->largest = en->ei; 5074abd3f5aSChao Yu } 5084abd3f5aSChao Yu 50939a53e0cSJaegeuk Kim struct f2fs_nm_info { 51039a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 51139a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 5127ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 51339a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 514cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 515ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 51639a53e0cSJaegeuk Kim 51739a53e0cSJaegeuk Kim /* NAT cache management */ 51839a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 519309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 5208b26ef98SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 52139a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 522309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 523aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 52439a53e0cSJaegeuk Kim 52539a53e0cSJaegeuk Kim /* free node ids management */ 5268a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 52739a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 52839a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 52939a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 53039a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 53139a53e0cSJaegeuk Kim 53239a53e0cSJaegeuk Kim /* for checkpoint */ 53339a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 53439a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 53539a53e0cSJaegeuk Kim }; 53639a53e0cSJaegeuk Kim 53739a53e0cSJaegeuk Kim /* 53839a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 53939a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 54039a53e0cSJaegeuk Kim * by the data offset in a file. 54139a53e0cSJaegeuk Kim */ 54239a53e0cSJaegeuk Kim struct dnode_of_data { 54339a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 54439a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 54539a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 54639a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 54739a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 54839a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 54993bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 55039a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 55139a53e0cSJaegeuk Kim }; 55239a53e0cSJaegeuk Kim 55339a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 55439a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 55539a53e0cSJaegeuk Kim { 556d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 55739a53e0cSJaegeuk Kim dn->inode = inode; 55839a53e0cSJaegeuk Kim dn->inode_page = ipage; 55939a53e0cSJaegeuk Kim dn->node_page = npage; 56039a53e0cSJaegeuk Kim dn->nid = nid; 56139a53e0cSJaegeuk Kim } 56239a53e0cSJaegeuk Kim 56339a53e0cSJaegeuk Kim /* 56439a53e0cSJaegeuk Kim * For SIT manager 56539a53e0cSJaegeuk Kim * 56639a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 56739a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 56839a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 56939a53e0cSJaegeuk Kim * respectively. 57039a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 57139a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 57239a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 57339a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 57439a53e0cSJaegeuk Kim * data and 8 for node logs. 57539a53e0cSJaegeuk Kim */ 57639a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 57739a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 57839a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 57939a53e0cSJaegeuk Kim 58039a53e0cSJaegeuk Kim enum { 58139a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 58239a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 58339a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 58439a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 58539a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 58639a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 58738aa0889SJaegeuk Kim NO_CHECK_TYPE, 58838aa0889SJaegeuk Kim CURSEG_DIRECT_IO, /* to use for the direct IO path */ 58939a53e0cSJaegeuk Kim }; 59039a53e0cSJaegeuk Kim 5916b4afdd7SJaegeuk Kim struct flush_cmd { 5926b4afdd7SJaegeuk Kim struct completion wait; 593721bd4d5SGu Zheng struct llist_node llnode; 5946b4afdd7SJaegeuk Kim int ret; 5956b4afdd7SJaegeuk Kim }; 5966b4afdd7SJaegeuk Kim 597a688b9d9SGu Zheng struct flush_cmd_control { 598a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 599a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 600721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 601721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 602a688b9d9SGu Zheng }; 603a688b9d9SGu Zheng 60439a53e0cSJaegeuk Kim struct f2fs_sm_info { 60539a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 60639a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 60739a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 60839a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 60939a53e0cSJaegeuk Kim 61039a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 61139a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 61239a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 61339a53e0cSJaegeuk Kim 61439a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 61539a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 61639a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 61739a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 61881eb8d6eSJaegeuk Kim 61981eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 62081eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 6217fd9e544SJaegeuk Kim 6227fd9e544SJaegeuk Kim /* for small discard management */ 6237fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 6247fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 6257fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 626216fbd64SJaegeuk Kim 627bba681cbSJaegeuk Kim /* for batched trimming */ 628bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 629bba681cbSJaegeuk Kim 630184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 631184a5cd2SChao Yu 632216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 633216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 634c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 6356b4afdd7SJaegeuk Kim 6366b4afdd7SJaegeuk Kim /* for flush command control */ 637a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 638a688b9d9SGu Zheng 63939a53e0cSJaegeuk Kim }; 64039a53e0cSJaegeuk Kim 64139a53e0cSJaegeuk Kim /* 64239a53e0cSJaegeuk Kim * For superblock 64339a53e0cSJaegeuk Kim */ 64439a53e0cSJaegeuk Kim /* 64539a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 64639a53e0cSJaegeuk Kim * 64739a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 64839a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 64939a53e0cSJaegeuk Kim */ 65039a53e0cSJaegeuk Kim enum count_type { 65139a53e0cSJaegeuk Kim F2FS_WRITEBACK, 65239a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 653c227f912SChao Yu F2FS_DIRTY_DATA, 65439a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 65539a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6568dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 65739a53e0cSJaegeuk Kim NR_COUNT_TYPE, 65839a53e0cSJaegeuk Kim }; 65939a53e0cSJaegeuk Kim 66039a53e0cSJaegeuk Kim /* 661e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 66239a53e0cSJaegeuk Kim * The available types are: 66339a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 66439a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 66539a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 66639a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 66739a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 66839a53e0cSJaegeuk Kim * with waiting the bio's completion 66939a53e0cSJaegeuk Kim * ... Only can be used with META. 67039a53e0cSJaegeuk Kim */ 6717d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 67239a53e0cSJaegeuk Kim enum page_type { 67339a53e0cSJaegeuk Kim DATA, 67439a53e0cSJaegeuk Kim NODE, 67539a53e0cSJaegeuk Kim META, 67639a53e0cSJaegeuk Kim NR_PAGE_TYPE, 67739a53e0cSJaegeuk Kim META_FLUSH, 6788ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 6798ce67cb0SJaegeuk Kim INMEM_DROP, 6808ce67cb0SJaegeuk Kim IPU, 6818ce67cb0SJaegeuk Kim OPU, 68239a53e0cSJaegeuk Kim }; 68339a53e0cSJaegeuk Kim 684458e6197SJaegeuk Kim struct f2fs_io_info { 68505ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 686458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 6877e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 688cf04e8ebSJaegeuk Kim block_t blk_addr; /* block address to be written */ 68905ca3632SJaegeuk Kim struct page *page; /* page to be written */ 6904375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 691458e6197SJaegeuk Kim }; 692458e6197SJaegeuk Kim 69393dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 6941ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 695458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 6961ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 6971ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 698458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 699df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 7001ff7bd3bSJaegeuk Kim }; 7011ff7bd3bSJaegeuk Kim 702c227f912SChao Yu enum inode_type { 703c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 704c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 705c227f912SChao Yu NR_INODE_TYPE, 706c227f912SChao Yu }; 707c227f912SChao Yu 70867298804SChao Yu /* for inner inode cache management */ 70967298804SChao Yu struct inode_management { 71067298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 71167298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 71267298804SChao Yu struct list_head ino_list; /* inode list head */ 71367298804SChao Yu unsigned long ino_num; /* number of entries */ 71467298804SChao Yu }; 71567298804SChao Yu 716caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 717caf0047eSChao Yu enum { 718caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 719caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 720caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 721caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 722caf0047eSChao Yu }; 723caf0047eSChao Yu 724*6beceb54SJaegeuk Kim enum { 725*6beceb54SJaegeuk Kim CP_TIME, 726*6beceb54SJaegeuk Kim MAX_TIME, 727*6beceb54SJaegeuk Kim }; 728*6beceb54SJaegeuk Kim 72939a53e0cSJaegeuk Kim struct f2fs_sb_info { 73039a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 7315e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 73239a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 733e8240f65SChao Yu int valid_super_block; /* valid super block no */ 734caf0047eSChao Yu int s_flag; /* flags for sbi */ 73539a53e0cSJaegeuk Kim 73639a53e0cSJaegeuk Kim /* for node-related operations */ 73739a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 73839a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 73939a53e0cSJaegeuk Kim 74039a53e0cSJaegeuk Kim /* for segment-related operations */ 74139a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 7421ff7bd3bSJaegeuk Kim 7431ff7bd3bSJaegeuk Kim /* for bio operations */ 744924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 7451ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 74639a53e0cSJaegeuk Kim 74739a53e0cSJaegeuk Kim /* for checkpoint */ 74839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 74939a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 75039936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 751e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 752b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 7535463e7c1SJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 754fb51b5efSChangman Lee wait_queue_head_t cp_wait; 755*6beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 756*6beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 75739a53e0cSJaegeuk Kim 75867298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 7596451e041SJaegeuk Kim 7606451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 7610d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 76239a53e0cSJaegeuk Kim 763c227f912SChao Yu /* for inode management */ 764c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 765c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 76639a53e0cSJaegeuk Kim 76713054c54SChao Yu /* for extent tree cache */ 76813054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 76913054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 77013054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 77113054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 7727441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 773137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 77474fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 77513054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 77613054c54SChao Yu 77739a53e0cSJaegeuk Kim /* basic filesystem units */ 77839a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 77939a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 78039a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 78139a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 78239a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 78339a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 78439a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 78539a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 78639a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 78739a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 78839a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 78939a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 79039a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 79139a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 792e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 79339a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 794ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 79539a53e0cSJaegeuk Kim 79639a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 79739a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 79839a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 799a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 80039a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 80139a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 80239a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 80339a53e0cSJaegeuk Kim 80439a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 80539a53e0cSJaegeuk Kim 80639a53e0cSJaegeuk Kim /* for cleaning operations */ 80739a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 80839a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 8095ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 81039a53e0cSJaegeuk Kim 811b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 812b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 813b1c57c1cSJaegeuk Kim 81439a53e0cSJaegeuk Kim /* 81539a53e0cSJaegeuk Kim * for stat information. 81639a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 81739a53e0cSJaegeuk Kim */ 81835b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 81939a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 82039a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 82139a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 822b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 8235b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 8245b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 8255b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 8265b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 827d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 82803e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 82903e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 83039a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 83133fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 83235b09d82SNamjae Jeon #endif 83335b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 83439a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 835b59d0baeSNamjae Jeon 836b59d0baeSNamjae Jeon /* For sysfs suppport */ 837b59d0baeSNamjae Jeon struct kobject s_kobj; 838b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 8392658e50dSJaegeuk Kim 8402658e50dSJaegeuk Kim /* For shrinker support */ 8412658e50dSJaegeuk Kim struct list_head s_list; 8422658e50dSJaegeuk Kim struct mutex umount_mutex; 8432658e50dSJaegeuk Kim unsigned int shrinker_run_no; 84439a53e0cSJaegeuk Kim }; 84539a53e0cSJaegeuk Kim 846*6beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 847*6beceb54SJaegeuk Kim { 848*6beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 849*6beceb54SJaegeuk Kim } 850*6beceb54SJaegeuk Kim 851*6beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 852*6beceb54SJaegeuk Kim { 853*6beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 854*6beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 855*6beceb54SJaegeuk Kim 856*6beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 857*6beceb54SJaegeuk Kim } 858*6beceb54SJaegeuk Kim 85939a53e0cSJaegeuk Kim /* 86039a53e0cSJaegeuk Kim * Inline functions 86139a53e0cSJaegeuk Kim */ 86239a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 86339a53e0cSJaegeuk Kim { 86439a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 86539a53e0cSJaegeuk Kim } 86639a53e0cSJaegeuk Kim 86739a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 86839a53e0cSJaegeuk Kim { 86939a53e0cSJaegeuk Kim return sb->s_fs_info; 87039a53e0cSJaegeuk Kim } 87139a53e0cSJaegeuk Kim 8724081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 8734081363fSJaegeuk Kim { 8744081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 8754081363fSJaegeuk Kim } 8764081363fSJaegeuk Kim 8774081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 8784081363fSJaegeuk Kim { 8794081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 8804081363fSJaegeuk Kim } 8814081363fSJaegeuk Kim 8824081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 8834081363fSJaegeuk Kim { 8844081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 8854081363fSJaegeuk Kim } 8864081363fSJaegeuk Kim 88739a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 88839a53e0cSJaegeuk Kim { 88939a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 89039a53e0cSJaegeuk Kim } 89139a53e0cSJaegeuk Kim 89239a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 89339a53e0cSJaegeuk Kim { 89439a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 89539a53e0cSJaegeuk Kim } 89639a53e0cSJaegeuk Kim 89745590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 89845590710SGu Zheng { 89945590710SGu Zheng return (struct f2fs_node *)page_address(page); 90045590710SGu Zheng } 90145590710SGu Zheng 90258bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 90358bfaf44SJaegeuk Kim { 90458bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 90558bfaf44SJaegeuk Kim } 90658bfaf44SJaegeuk Kim 90739a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 90839a53e0cSJaegeuk Kim { 90939a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 91039a53e0cSJaegeuk Kim } 91139a53e0cSJaegeuk Kim 91239a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 91339a53e0cSJaegeuk Kim { 91439a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 91539a53e0cSJaegeuk Kim } 91639a53e0cSJaegeuk Kim 91739a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 91839a53e0cSJaegeuk Kim { 91939a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 92039a53e0cSJaegeuk Kim } 92139a53e0cSJaegeuk Kim 92239a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 92339a53e0cSJaegeuk Kim { 92439a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 92539a53e0cSJaegeuk Kim } 92639a53e0cSJaegeuk Kim 92739a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 92839a53e0cSJaegeuk Kim { 92939a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 93039a53e0cSJaegeuk Kim } 93139a53e0cSJaegeuk Kim 9329df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 9339df27d98SGu Zheng { 9349df27d98SGu Zheng return sbi->meta_inode->i_mapping; 9359df27d98SGu Zheng } 9369df27d98SGu Zheng 9374ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 9384ef51a8fSJaegeuk Kim { 9394ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 9404ef51a8fSJaegeuk Kim } 9414ef51a8fSJaegeuk Kim 942caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 94339a53e0cSJaegeuk Kim { 944caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 94539a53e0cSJaegeuk Kim } 94639a53e0cSJaegeuk Kim 947caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 94839a53e0cSJaegeuk Kim { 949caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 950caf0047eSChao Yu } 951caf0047eSChao Yu 952caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 953caf0047eSChao Yu { 954caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 95539a53e0cSJaegeuk Kim } 95639a53e0cSJaegeuk Kim 957d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 958d71b5564SJaegeuk Kim { 959d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 960d71b5564SJaegeuk Kim } 961d71b5564SJaegeuk Kim 96225ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 96325ca923bSJaegeuk Kim { 96425ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 96525ca923bSJaegeuk Kim return ckpt_flags & f; 96625ca923bSJaegeuk Kim } 96725ca923bSJaegeuk Kim 96825ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 96925ca923bSJaegeuk Kim { 97025ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 97125ca923bSJaegeuk Kim ckpt_flags |= f; 97225ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 97325ca923bSJaegeuk Kim } 97425ca923bSJaegeuk Kim 97525ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 97625ca923bSJaegeuk Kim { 97725ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 97825ca923bSJaegeuk Kim ckpt_flags &= (~f); 97925ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 98025ca923bSJaegeuk Kim } 98125ca923bSJaegeuk Kim 982e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 98339a53e0cSJaegeuk Kim { 984e479556bSGu Zheng down_read(&sbi->cp_rwsem); 98539a53e0cSJaegeuk Kim } 98639a53e0cSJaegeuk Kim 987e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 98839a53e0cSJaegeuk Kim { 989e479556bSGu Zheng up_read(&sbi->cp_rwsem); 99039936837SJaegeuk Kim } 99139936837SJaegeuk Kim 992e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 99339936837SJaegeuk Kim { 9940daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 99539936837SJaegeuk Kim } 99639936837SJaegeuk Kim 997e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 99839936837SJaegeuk Kim { 999e479556bSGu Zheng up_write(&sbi->cp_rwsem); 100039a53e0cSJaegeuk Kim } 100139a53e0cSJaegeuk Kim 1002119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1003119ee914SJaegeuk Kim { 1004119ee914SJaegeuk Kim int reason = CP_SYNC; 1005119ee914SJaegeuk Kim 1006119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1007119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1008119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1009119ee914SJaegeuk Kim reason = CP_UMOUNT; 1010119ee914SJaegeuk Kim return reason; 1011119ee914SJaegeuk Kim } 1012119ee914SJaegeuk Kim 1013119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1014119ee914SJaegeuk Kim { 1015119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 1016119ee914SJaegeuk Kim } 1017119ee914SJaegeuk Kim 1018119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1019119ee914SJaegeuk Kim { 1020119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 1021119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 1022119ee914SJaegeuk Kim } 1023119ee914SJaegeuk Kim 102439a53e0cSJaegeuk Kim /* 102539a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 102639a53e0cSJaegeuk Kim */ 1027064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 102839a53e0cSJaegeuk Kim { 1029d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1030d6b7d4b3SChao Yu return -EINVAL; 1031cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1032064e0823SNamjae Jeon return -EINVAL; 1033064e0823SNamjae Jeon return 0; 103439a53e0cSJaegeuk Kim } 103539a53e0cSJaegeuk Kim 103639a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 103739a53e0cSJaegeuk Kim 103839a53e0cSJaegeuk Kim /* 103939a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 104039a53e0cSJaegeuk Kim */ 104139a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 104239a53e0cSJaegeuk Kim { 104339a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 10446c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 104539a53e0cSJaegeuk Kim else 10466c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 104739a53e0cSJaegeuk Kim } 104839a53e0cSJaegeuk Kim 10494bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 10504bc8e9bcSChao Yu { 10514bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 10524bc8e9bcSChao Yu } 10534bc8e9bcSChao Yu 105439a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 105539a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 105639a53e0cSJaegeuk Kim { 105739a53e0cSJaegeuk Kim block_t valid_block_count; 105839a53e0cSJaegeuk Kim 105939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 106039a53e0cSJaegeuk Kim valid_block_count = 106139a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 1062cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 106339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 106439a53e0cSJaegeuk Kim return false; 106539a53e0cSJaegeuk Kim } 106639a53e0cSJaegeuk Kim inode->i_blocks += count; 106739a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 106839a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 106939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 107039a53e0cSJaegeuk Kim return true; 107139a53e0cSJaegeuk Kim } 107239a53e0cSJaegeuk Kim 1073da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 107439a53e0cSJaegeuk Kim struct inode *inode, 107539a53e0cSJaegeuk Kim blkcnt_t count) 107639a53e0cSJaegeuk Kim { 107739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 10789850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 10799850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 108039a53e0cSJaegeuk Kim inode->i_blocks -= count; 108139a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 108239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 108339a53e0cSJaegeuk Kim } 108439a53e0cSJaegeuk Kim 108539a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 108639a53e0cSJaegeuk Kim { 108739a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 1088caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 108939a53e0cSJaegeuk Kim } 109039a53e0cSJaegeuk Kim 1091a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 109239a53e0cSJaegeuk Kim { 1093a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1094c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1095c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 109639a53e0cSJaegeuk Kim } 109739a53e0cSJaegeuk Kim 109839a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 109939a53e0cSJaegeuk Kim { 110039a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 110139a53e0cSJaegeuk Kim } 110239a53e0cSJaegeuk Kim 1103a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 110439a53e0cSJaegeuk Kim { 11055ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 11065ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 11071fe54f9dSJaegeuk Kim return; 11081fe54f9dSJaegeuk Kim 1109a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1110c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1111c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 111239a53e0cSJaegeuk Kim } 111339a53e0cSJaegeuk Kim 111439a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 111539a53e0cSJaegeuk Kim { 111639a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 111739a53e0cSJaegeuk Kim } 111839a53e0cSJaegeuk Kim 1119a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1120f8b2c1f9SJaegeuk Kim { 1121a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1122f8b2c1f9SJaegeuk Kim } 1123f8b2c1f9SJaegeuk Kim 11245ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 11255ac206cfSNamjae Jeon { 11263519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 11275ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 11285ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 11295ac206cfSNamjae Jeon } 11305ac206cfSNamjae Jeon 113139a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 113239a53e0cSJaegeuk Kim { 11338b8343faSJaegeuk Kim return sbi->total_valid_block_count; 113439a53e0cSJaegeuk Kim } 113539a53e0cSJaegeuk Kim 113639a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 113739a53e0cSJaegeuk Kim { 113839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 113939a53e0cSJaegeuk Kim 114039a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 114139a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 114239a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 114339a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 114439a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 114539a53e0cSJaegeuk Kim 114639a53e0cSJaegeuk Kim return 0; 114739a53e0cSJaegeuk Kim } 114839a53e0cSJaegeuk Kim 114955141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 115055141486SWanpeng Li { 115155141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 115255141486SWanpeng Li } 115355141486SWanpeng Li 115439a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 115539a53e0cSJaegeuk Kim { 115639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 11571dbe4152SChangman Lee int offset; 11581dbe4152SChangman Lee 115955141486SWanpeng Li if (__cp_payload(sbi) > 0) { 11601dbe4152SChangman Lee if (flag == NAT_BITMAP) 11611dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 11621dbe4152SChangman Lee else 116365b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 11641dbe4152SChangman Lee } else { 11651dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 116625ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 116739a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 116839a53e0cSJaegeuk Kim } 11691dbe4152SChangman Lee } 117039a53e0cSJaegeuk Kim 117139a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 117239a53e0cSJaegeuk Kim { 117339a53e0cSJaegeuk Kim block_t start_addr; 117439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1175d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 117639a53e0cSJaegeuk Kim 117725ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 117839a53e0cSJaegeuk Kim 117939a53e0cSJaegeuk Kim /* 118039a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1181e1c42045Sarter97 * and even segment must be at cp segment 1 118239a53e0cSJaegeuk Kim */ 118339a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 118439a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 118539a53e0cSJaegeuk Kim 118639a53e0cSJaegeuk Kim return start_addr; 118739a53e0cSJaegeuk Kim } 118839a53e0cSJaegeuk Kim 118939a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 119039a53e0cSJaegeuk Kim { 119139a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 119239a53e0cSJaegeuk Kim } 119339a53e0cSJaegeuk Kim 119439a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1195ef86d709SGu Zheng struct inode *inode) 119639a53e0cSJaegeuk Kim { 119739a53e0cSJaegeuk Kim block_t valid_block_count; 119839a53e0cSJaegeuk Kim unsigned int valid_node_count; 119939a53e0cSJaegeuk Kim 120039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 120139a53e0cSJaegeuk Kim 1202ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1203cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 120439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 120539a53e0cSJaegeuk Kim return false; 120639a53e0cSJaegeuk Kim } 120739a53e0cSJaegeuk Kim 1208ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1209cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 121039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 121139a53e0cSJaegeuk Kim return false; 121239a53e0cSJaegeuk Kim } 121339a53e0cSJaegeuk Kim 121439a53e0cSJaegeuk Kim if (inode) 1215ef86d709SGu Zheng inode->i_blocks++; 1216ef86d709SGu Zheng 1217ef86d709SGu Zheng sbi->alloc_valid_block_count++; 1218ef86d709SGu Zheng sbi->total_valid_node_count++; 1219ef86d709SGu Zheng sbi->total_valid_block_count++; 122039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 122139a53e0cSJaegeuk Kim 122239a53e0cSJaegeuk Kim return true; 122339a53e0cSJaegeuk Kim } 122439a53e0cSJaegeuk Kim 122539a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1226ef86d709SGu Zheng struct inode *inode) 122739a53e0cSJaegeuk Kim { 122839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 122939a53e0cSJaegeuk Kim 12309850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 12319850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 12329850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 123339a53e0cSJaegeuk Kim 1234ef86d709SGu Zheng inode->i_blocks--; 1235ef86d709SGu Zheng sbi->total_valid_node_count--; 1236ef86d709SGu Zheng sbi->total_valid_block_count--; 123739a53e0cSJaegeuk Kim 123839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 123939a53e0cSJaegeuk Kim } 124039a53e0cSJaegeuk Kim 124139a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 124239a53e0cSJaegeuk Kim { 12438b8343faSJaegeuk Kim return sbi->total_valid_node_count; 124439a53e0cSJaegeuk Kim } 124539a53e0cSJaegeuk Kim 124639a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 124739a53e0cSJaegeuk Kim { 124839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12499850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 125039a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 125139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 125239a53e0cSJaegeuk Kim } 125339a53e0cSJaegeuk Kim 12540e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 125539a53e0cSJaegeuk Kim { 125639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12579850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 125839a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 125939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 126039a53e0cSJaegeuk Kim } 126139a53e0cSJaegeuk Kim 126239a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 126339a53e0cSJaegeuk Kim { 12648b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 126539a53e0cSJaegeuk Kim } 126639a53e0cSJaegeuk Kim 1267a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1268a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1269a56c7c6fSJaegeuk Kim { 1270a56c7c6fSJaegeuk Kim if (!for_write) 1271a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1272a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1273a56c7c6fSJaegeuk Kim } 1274a56c7c6fSJaegeuk Kim 12756e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 12766e2c64adSJaegeuk Kim { 12776e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 12786e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 12796e2c64adSJaegeuk Kim 12806e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 12816e2c64adSJaegeuk Kim kunmap(dst); 12826e2c64adSJaegeuk Kim kunmap(src); 12836e2c64adSJaegeuk Kim } 12846e2c64adSJaegeuk Kim 128539a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 128639a53e0cSJaegeuk Kim { 1287031fa8ccSJaegeuk Kim if (!page) 128839a53e0cSJaegeuk Kim return; 128939a53e0cSJaegeuk Kim 129039a53e0cSJaegeuk Kim if (unlock) { 12919850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 129239a53e0cSJaegeuk Kim unlock_page(page); 129339a53e0cSJaegeuk Kim } 129439a53e0cSJaegeuk Kim page_cache_release(page); 129539a53e0cSJaegeuk Kim } 129639a53e0cSJaegeuk Kim 129739a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 129839a53e0cSJaegeuk Kim { 129939a53e0cSJaegeuk Kim if (dn->node_page) 130039a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 130139a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 130239a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 130339a53e0cSJaegeuk Kim dn->node_page = NULL; 130439a53e0cSJaegeuk Kim dn->inode_page = NULL; 130539a53e0cSJaegeuk Kim } 130639a53e0cSJaegeuk Kim 130739a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1308e8512d2eSGu Zheng size_t size) 130939a53e0cSJaegeuk Kim { 1310e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 131139a53e0cSJaegeuk Kim } 131239a53e0cSJaegeuk Kim 13137bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 13147bd59381SGu Zheng gfp_t flags) 13157bd59381SGu Zheng { 13167bd59381SGu Zheng void *entry; 13177bd59381SGu Zheng 131880c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 131980c54505SJaegeuk Kim if (!entry) 132080c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 13217bd59381SGu Zheng return entry; 13227bd59381SGu Zheng } 13237bd59381SGu Zheng 1324740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1325740432f8SJaegeuk Kim { 1326740432f8SJaegeuk Kim struct bio *bio; 1327740432f8SJaegeuk Kim 1328740432f8SJaegeuk Kim /* No failure on bio allocation */ 1329740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 133080c54505SJaegeuk Kim if (!bio) 133180c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1332740432f8SJaegeuk Kim return bio; 1333740432f8SJaegeuk Kim } 1334740432f8SJaegeuk Kim 13359be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 13369be32d72SJaegeuk Kim unsigned long index, void *item) 13379be32d72SJaegeuk Kim { 13389be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 13399be32d72SJaegeuk Kim cond_resched(); 13409be32d72SJaegeuk Kim } 13419be32d72SJaegeuk Kim 134239a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 134339a53e0cSJaegeuk Kim 134439a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 134539a53e0cSJaegeuk Kim { 134645590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 134739a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 134839a53e0cSJaegeuk Kim } 134939a53e0cSJaegeuk Kim 135039a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 135139a53e0cSJaegeuk Kim { 135239a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 135339a53e0cSJaegeuk Kim } 135439a53e0cSJaegeuk Kim 135539a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 135639a53e0cSJaegeuk Kim unsigned int offset) 135739a53e0cSJaegeuk Kim { 135839a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 135939a53e0cSJaegeuk Kim __le32 *addr_array; 136045590710SGu Zheng raw_node = F2FS_NODE(node_page); 136139a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 136239a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 136339a53e0cSJaegeuk Kim } 136439a53e0cSJaegeuk Kim 136539a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 136639a53e0cSJaegeuk Kim { 136739a53e0cSJaegeuk Kim int mask; 136839a53e0cSJaegeuk Kim 136939a53e0cSJaegeuk Kim addr += (nr >> 3); 137039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 137139a53e0cSJaegeuk Kim return mask & *addr; 137239a53e0cSJaegeuk Kim } 137339a53e0cSJaegeuk Kim 1374a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1375a66cdd98SJaegeuk Kim { 1376a66cdd98SJaegeuk Kim int mask; 1377a66cdd98SJaegeuk Kim 1378a66cdd98SJaegeuk Kim addr += (nr >> 3); 1379a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1380a66cdd98SJaegeuk Kim *addr |= mask; 1381a66cdd98SJaegeuk Kim } 1382a66cdd98SJaegeuk Kim 1383a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1384a66cdd98SJaegeuk Kim { 1385a66cdd98SJaegeuk Kim int mask; 1386a66cdd98SJaegeuk Kim 1387a66cdd98SJaegeuk Kim addr += (nr >> 3); 1388a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1389a66cdd98SJaegeuk Kim *addr &= ~mask; 1390a66cdd98SJaegeuk Kim } 1391a66cdd98SJaegeuk Kim 139252aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 139339a53e0cSJaegeuk Kim { 139439a53e0cSJaegeuk Kim int mask; 139539a53e0cSJaegeuk Kim int ret; 139639a53e0cSJaegeuk Kim 139739a53e0cSJaegeuk Kim addr += (nr >> 3); 139839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 139939a53e0cSJaegeuk Kim ret = mask & *addr; 140039a53e0cSJaegeuk Kim *addr |= mask; 140139a53e0cSJaegeuk Kim return ret; 140239a53e0cSJaegeuk Kim } 140339a53e0cSJaegeuk Kim 140452aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 140539a53e0cSJaegeuk Kim { 140639a53e0cSJaegeuk Kim int mask; 140739a53e0cSJaegeuk Kim int ret; 140839a53e0cSJaegeuk Kim 140939a53e0cSJaegeuk Kim addr += (nr >> 3); 141039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 141139a53e0cSJaegeuk Kim ret = mask & *addr; 141239a53e0cSJaegeuk Kim *addr &= ~mask; 141339a53e0cSJaegeuk Kim return ret; 141439a53e0cSJaegeuk Kim } 141539a53e0cSJaegeuk Kim 1416c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1417c6ac4c0eSGu Zheng { 1418c6ac4c0eSGu Zheng int mask; 1419c6ac4c0eSGu Zheng 1420c6ac4c0eSGu Zheng addr += (nr >> 3); 1421c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1422c6ac4c0eSGu Zheng *addr ^= mask; 1423c6ac4c0eSGu Zheng } 1424c6ac4c0eSGu Zheng 142539a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 142639a53e0cSJaegeuk Kim enum { 142739a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1428b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1429ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 143039a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 143139a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 143239a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1433c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1434699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 143574d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1436c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1437444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 14381001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 143934d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1440fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1441fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 144288b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 144388b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 144402a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 14453c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 14461e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1447b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1448510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1449d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1450c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 145139a53e0cSJaegeuk Kim }; 145239a53e0cSJaegeuk Kim 145339a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 145439a53e0cSJaegeuk Kim { 145561e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 145639a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 145739a53e0cSJaegeuk Kim } 145839a53e0cSJaegeuk Kim 145939a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 146039a53e0cSJaegeuk Kim { 146139a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 146239a53e0cSJaegeuk Kim } 146339a53e0cSJaegeuk Kim 146439a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 146539a53e0cSJaegeuk Kim { 146661e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 146739a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 146839a53e0cSJaegeuk Kim } 146939a53e0cSJaegeuk Kim 147039a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 147139a53e0cSJaegeuk Kim { 147239a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 147339a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 147439a53e0cSJaegeuk Kim } 147539a53e0cSJaegeuk Kim 1476444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1477444c580fSJaegeuk Kim struct f2fs_inode *ri) 1478444c580fSJaegeuk Kim { 1479444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1480444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 14811001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 14821001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 148334d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 148434d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1485b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1486b3d208f9SJaegeuk Kim set_inode_flag(fi, FI_DATA_EXIST); 1487510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1488510022a8SJaegeuk Kim set_inode_flag(fi, FI_INLINE_DOTS); 1489444c580fSJaegeuk Kim } 1490444c580fSJaegeuk Kim 1491444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1492444c580fSJaegeuk Kim struct f2fs_inode *ri) 1493444c580fSJaegeuk Kim { 1494444c580fSJaegeuk Kim ri->i_inline = 0; 1495444c580fSJaegeuk Kim 1496444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1497444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 14981001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 14991001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 150034d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 150134d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1502b3d208f9SJaegeuk Kim if (is_inode_flag_set(fi, FI_DATA_EXIST)) 1503b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1504510022a8SJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_DOTS)) 1505510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1506444c580fSJaegeuk Kim } 1507444c580fSJaegeuk Kim 1508987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1509987c7c31SChao Yu { 1510987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1511987c7c31SChao Yu } 1512987c7c31SChao Yu 1513de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1514de93653fSJaegeuk Kim { 1515987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1516de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1517de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1518de93653fSJaegeuk Kim } 1519de93653fSJaegeuk Kim 152065985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 152165985d93SJaegeuk Kim { 1522695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 152365985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 152465985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 152565985d93SJaegeuk Kim } 152665985d93SJaegeuk Kim 152765985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 152865985d93SJaegeuk Kim { 1529987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 153065985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 153165985d93SJaegeuk Kim else 153265985d93SJaegeuk Kim return 0; 153365985d93SJaegeuk Kim } 153465985d93SJaegeuk Kim 15350dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 15360dbdc2aeSJaegeuk Kim { 15370dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 15380dbdc2aeSJaegeuk Kim } 15390dbdc2aeSJaegeuk Kim 1540b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1541b3d208f9SJaegeuk Kim { 1542b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 1543b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1544b3d208f9SJaegeuk Kim } 1545b3d208f9SJaegeuk Kim 1546b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1547b3d208f9SJaegeuk Kim { 1548b3d208f9SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST); 1549b3d208f9SJaegeuk Kim } 1550b3d208f9SJaegeuk Kim 1551510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1552510022a8SJaegeuk Kim { 1553510022a8SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS); 1554510022a8SJaegeuk Kim } 1555510022a8SJaegeuk Kim 155688b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 155788b88a66SJaegeuk Kim { 155888b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 155988b88a66SJaegeuk Kim } 156088b88a66SJaegeuk Kim 156102a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 156202a1335fSJaegeuk Kim { 156302a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 156402a1335fSJaegeuk Kim } 156502a1335fSJaegeuk Kim 15663c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 15673c6c2bebSJaegeuk Kim { 15683c6c2bebSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); 15693c6c2bebSJaegeuk Kim } 15703c6c2bebSJaegeuk Kim 15711e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 15721e84371fSJaegeuk Kim { 15731e84371fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE); 15741e84371fSJaegeuk Kim } 15751e84371fSJaegeuk Kim 15761001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 15771001b347SHuajun Li { 1578695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 15791001b347SHuajun Li return (void *)&(ri->i_addr[1]); 15801001b347SHuajun Li } 15811001b347SHuajun Li 158234d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 158334d67debSChao Yu { 158434d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 158534d67debSChao Yu } 158634d67debSChao Yu 15879486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 15889486ba44SJaegeuk Kim { 15899486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 15909486ba44SJaegeuk Kim kunmap(page); 15919486ba44SJaegeuk Kim } 15929486ba44SJaegeuk Kim 1593b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1594b5492af7SJaegeuk Kim { 1595b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1596b5492af7SJaegeuk Kim } 1597b5492af7SJaegeuk Kim 1598b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1599b5492af7SJaegeuk Kim { 1600b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1601b5492af7SJaegeuk Kim } 1602b5492af7SJaegeuk Kim 1603b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1604b5492af7SJaegeuk Kim { 1605b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1606b5492af7SJaegeuk Kim } 1607b5492af7SJaegeuk Kim 160877888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 160977888c1eSJaegeuk Kim { 161077888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 161177888c1eSJaegeuk Kim } 161277888c1eSJaegeuk Kim 16131e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 16141e968fdfSJaegeuk Kim { 16151e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 16161e968fdfSJaegeuk Kim } 16171e968fdfSJaegeuk Kim 1618744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1619744602cfSJaegeuk Kim { 1620744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1621744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1622744602cfSJaegeuk Kim } 1623744602cfSJaegeuk Kim 1624eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1625eaa693f4SJaegeuk Kim { 1626eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1627eaa693f4SJaegeuk Kim return true; 1628eaa693f4SJaegeuk Kim 1629eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1630eaa693f4SJaegeuk Kim return true; 1631eaa693f4SJaegeuk Kim 1632eaa693f4SJaegeuk Kim return false; 1633eaa693f4SJaegeuk Kim } 1634eaa693f4SJaegeuk Kim 16353e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 16363e72f721SJaegeuk Kim { 16373e72f721SJaegeuk Kim mode_t mode = inode->i_mode; 16383e72f721SJaegeuk Kim 16393e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 16403e72f721SJaegeuk Kim is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT)) 16413e72f721SJaegeuk Kim return false; 16423e72f721SJaegeuk Kim 16433e72f721SJaegeuk Kim return S_ISREG(mode); 16443e72f721SJaegeuk Kim } 16453e72f721SJaegeuk Kim 164639307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 164739307a8eSJaegeuk Kim { 164839307a8eSJaegeuk Kim void *ret; 164939307a8eSJaegeuk Kim 165039307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 165139307a8eSJaegeuk Kim if (!ret) 165239307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 165339307a8eSJaegeuk Kim return ret; 165439307a8eSJaegeuk Kim } 165539307a8eSJaegeuk Kim 165639307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 165739307a8eSJaegeuk Kim { 165839307a8eSJaegeuk Kim void *ret; 165939307a8eSJaegeuk Kim 166039307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 166139307a8eSJaegeuk Kim if (!ret) 166239307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 166339307a8eSJaegeuk Kim return ret; 166439307a8eSJaegeuk Kim } 166539307a8eSJaegeuk Kim 1666a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1667a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1668a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1669a6dda0e6SChristoph Hellwig 1670267378d4SChao Yu /* get offset of first page in next direct node */ 1671267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1672267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1673267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1674267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1675267378d4SChao Yu 167639a53e0cSJaegeuk Kim /* 167739a53e0cSJaegeuk Kim * file.c 167839a53e0cSJaegeuk Kim */ 167939a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 168039a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1681764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 1682b0154891SChao Yu int f2fs_truncate(struct inode *, bool); 16832d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 168439a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 168539a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1686b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 168739a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1688e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 168939a53e0cSJaegeuk Kim 169039a53e0cSJaegeuk Kim /* 169139a53e0cSJaegeuk Kim * inode.c 169239a53e0cSJaegeuk Kim */ 169339a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 169439a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 16954660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 169612719ae1SJaegeuk Kim int update_inode(struct inode *, struct page *); 169712719ae1SJaegeuk Kim int update_inode_page(struct inode *); 169839a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 169939a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 170044c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 170139a53e0cSJaegeuk Kim 170239a53e0cSJaegeuk Kim /* 170339a53e0cSJaegeuk Kim * namei.c 170439a53e0cSJaegeuk Kim */ 170539a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 170639a53e0cSJaegeuk Kim 170739a53e0cSJaegeuk Kim /* 170839a53e0cSJaegeuk Kim * dir.c 170939a53e0cSJaegeuk Kim */ 1710dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1711510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 17126e22c691SJaegeuk Kim 17136e22c691SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct f2fs_filename *, 17146e22c691SJaegeuk Kim f2fs_hash_t, int *, struct f2fs_dentry_ptr *); 17157b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 1716d8c6822aSJaegeuk Kim unsigned int, struct f2fs_str *); 1717062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1718062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1719dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1720bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1721dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1722a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1723dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 172439a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 172539a53e0cSJaegeuk Kim struct page **); 172639a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 172739a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 172839a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 172939a53e0cSJaegeuk Kim struct page *, struct inode *); 1730e7d55452SJaegeuk Kim int update_dent_inode(struct inode *, struct inode *, const struct qstr *); 1731510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 17323b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1733510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1734510022a8SJaegeuk Kim umode_t); 1735dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1736dbeacf02SChao Yu struct inode *); 1737b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 173839a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 173939a53e0cSJaegeuk Kim 1740b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1741b7f7a5e0SAl Viro { 17422b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1743510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1744b7f7a5e0SAl Viro } 1745b7f7a5e0SAl Viro 174639a53e0cSJaegeuk Kim /* 174739a53e0cSJaegeuk Kim * super.c 174839a53e0cSJaegeuk Kim */ 1749c5bda1c8SChao Yu int f2fs_commit_super(struct f2fs_sb_info *, bool); 175039a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1751a07ef784SNamjae Jeon extern __printf(3, 4) 1752a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 175339a53e0cSJaegeuk Kim 175439a53e0cSJaegeuk Kim /* 175539a53e0cSJaegeuk Kim * hash.c 175639a53e0cSJaegeuk Kim */ 1757eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 175839a53e0cSJaegeuk Kim 175939a53e0cSJaegeuk Kim /* 176039a53e0cSJaegeuk Kim * node.c 176139a53e0cSJaegeuk Kim */ 176239a53e0cSJaegeuk Kim struct dnode_of_data; 176339a53e0cSJaegeuk Kim struct node_info; 176439a53e0cSJaegeuk Kim 17656fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 17662dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t); 176788bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 176888bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 176939a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 177039a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 177139a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 17724f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1773cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 177413ec7297SChao Yu int remove_inode_page(struct inode *); 1775a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 17768ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 177739a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 177839a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 177939a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 178039a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 178139a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 178239a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 178339a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 178439a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 178531696580SChao Yu int try_to_free_nids(struct f2fs_sb_info *, int); 178670cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 17871c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 178839a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 178939a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 179039a53e0cSJaegeuk Kim struct f2fs_summary_block *); 179139a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 179239a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 179339a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 17946e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 179539a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 179639a53e0cSJaegeuk Kim 179739a53e0cSJaegeuk Kim /* 179839a53e0cSJaegeuk Kim * segment.c 179939a53e0cSJaegeuk Kim */ 180088b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 1801edb27deeSJaegeuk Kim int commit_inmem_pages(struct inode *, bool); 18022c4db1a6SJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *, bool); 18034660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 18046b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 18052163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 18062163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 180739a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 18086e2c64adSJaegeuk Kim bool is_checkpointed_data(struct f2fs_sb_info *, block_t); 18095e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 1810836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 18114b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1812e90c2d28SChao Yu bool discard_next_dnode(struct f2fs_sb_info *, block_t); 18133fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 181439a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 18154b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 181639a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1817381722d2SChao Yu void update_meta_page(struct f2fs_sb_info *, void *, block_t); 1818577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 181905ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 182005ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 182105ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 1822528e3459SChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *, 1823528e3459SChao Yu block_t, block_t, unsigned char, bool); 1824bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1825bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 18265514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 182708b39fbdSChao Yu void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t); 182839a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 182939a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 183039a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 183139a53e0cSJaegeuk Kim int, unsigned int, int); 18324b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 183339a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 183439a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 18357fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 18367fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 183739a53e0cSJaegeuk Kim 183839a53e0cSJaegeuk Kim /* 183939a53e0cSJaegeuk Kim * checkpoint.c 184039a53e0cSJaegeuk Kim */ 184139a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 184239a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 18432b947003SChao Yu struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t); 1844f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 184526879fb1SChao Yu int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool); 1846635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 184739a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1848a49324f1SChao Yu void add_ino_entry(struct f2fs_sb_info *, nid_t, int type); 1849a49324f1SChao Yu void remove_ino_entry(struct f2fs_sb_info *, nid_t, int type); 1850a49324f1SChao Yu void release_ino_entry(struct f2fs_sb_info *); 1851fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1852cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1853cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 185439a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 185539a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 18568c14bfadSChao Yu int recover_orphan_inodes(struct f2fs_sb_info *); 185739a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1858a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 18595deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 1860c227f912SChao Yu void remove_dirty_inode(struct inode *); 18616d5a1495SChao Yu int sync_dirty_inodes(struct f2fs_sb_info *, enum inode_type); 1862c34f42e2SChao Yu int write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 18636451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 18646e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 186539a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 186639a53e0cSJaegeuk Kim 186739a53e0cSJaegeuk Kim /* 186839a53e0cSJaegeuk Kim * data.c 186939a53e0cSJaegeuk Kim */ 1870458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 187105ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 187205ca3632SJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_io_info *); 1873216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 187439a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1875759af1c9SFan Li int f2fs_get_block(struct dnode_of_data *, pgoff_t); 1876b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 1877a56c7c6fSJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int, bool); 187843f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t); 1879a56c7c6fSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t, bool); 188064aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 188105ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 1882d323d005SChao Yu int f2fs_map_blocks(struct inode *, struct f2fs_map_blocks *, int, int); 18839ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1884487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1885487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 188639a53e0cSJaegeuk Kim 188739a53e0cSJaegeuk Kim /* 188839a53e0cSJaegeuk Kim * gc.c 188939a53e0cSJaegeuk Kim */ 189039a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 189139a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1892de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1893d530d4d8SChao Yu int f2fs_gc(struct f2fs_sb_info *, bool); 189439a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 189539a53e0cSJaegeuk Kim 189639a53e0cSJaegeuk Kim /* 189739a53e0cSJaegeuk Kim * recovery.c 189839a53e0cSJaegeuk Kim */ 18996ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 190039a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 190139a53e0cSJaegeuk Kim 190239a53e0cSJaegeuk Kim /* 190339a53e0cSJaegeuk Kim * debug.c 190439a53e0cSJaegeuk Kim */ 190539a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 190639a53e0cSJaegeuk Kim struct f2fs_stat_info { 190739a53e0cSJaegeuk Kim struct list_head stat_list; 190839a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 190939a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 191039a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 19115b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 19125b7ee374SChao Yu unsigned long long hit_total, total_ext; 1913c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 191433fbd510SChao Yu int ndirty_node, ndirty_meta; 191533fbd510SChao Yu int ndirty_dent, ndirty_dirs, ndirty_data, ndirty_files; 1916dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 191739a53e0cSJaegeuk Kim int total_count, utilization; 1918d5e8f6c9SChao Yu int bg_gc, inmem_pages, wb_pages; 1919d5e8f6c9SChao Yu int inline_xattr, inline_inode, inline_dir; 192039a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 192139a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 192239a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 192339a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 192439a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1925942e0be6SChangman Lee int prefree_count, call_count, cp_count; 192639a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 1927e1235983SChangman Lee int bg_node_segs, bg_data_segs; 192839a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 1929e1235983SChangman Lee int bg_data_blks, bg_node_blks; 193039a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 193139a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 193239a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 193339a53e0cSJaegeuk Kim 193439a53e0cSJaegeuk Kim unsigned int segment_count[2]; 193539a53e0cSJaegeuk Kim unsigned int block_count[2]; 1936b9a2c252SChangman Lee unsigned int inplace_count; 19379edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 193839a53e0cSJaegeuk Kim }; 193939a53e0cSJaegeuk Kim 1940963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1941963d4f7dSGu Zheng { 1942963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1943963d4f7dSGu Zheng } 1944963d4f7dSGu Zheng 1945942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 194639a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1947dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 194833fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 194933fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 19505b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 19515b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 19525b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 19535b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 1954d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 1955d5e8f6c9SChao Yu do { \ 1956d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1957d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 1958d5e8f6c9SChao Yu } while (0) 1959d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 1960d5e8f6c9SChao Yu do { \ 1961d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1962d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 1963d5e8f6c9SChao Yu } while (0) 19640dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 19650dbdc2aeSJaegeuk Kim do { \ 19660dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 196703e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 19680dbdc2aeSJaegeuk Kim } while (0) 19690dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 19700dbdc2aeSJaegeuk Kim do { \ 19710dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 197203e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 19730dbdc2aeSJaegeuk Kim } while (0) 19743289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 19753289c061SJaegeuk Kim do { \ 19763289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 197703e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 19783289c061SJaegeuk Kim } while (0) 19793289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 19803289c061SJaegeuk Kim do { \ 19813289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 198203e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 19833289c061SJaegeuk Kim } while (0) 1984dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1985dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1986dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1987dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 1988b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 1989b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 1990e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 199139a53e0cSJaegeuk Kim do { \ 1992963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 199339a53e0cSJaegeuk Kim (si)->tot_segs++; \ 1994e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 199539a53e0cSJaegeuk Kim si->data_segs++; \ 1996e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 1997e1235983SChangman Lee } else { \ 199839a53e0cSJaegeuk Kim si->node_segs++; \ 1999e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2000e1235983SChangman Lee } \ 200139a53e0cSJaegeuk Kim } while (0) 200239a53e0cSJaegeuk Kim 200339a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 200439a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 200539a53e0cSJaegeuk Kim 2006e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 200739a53e0cSJaegeuk Kim do { \ 2008963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 200939a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 201039a53e0cSJaegeuk Kim si->data_blks += (blks); \ 2011e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 201239a53e0cSJaegeuk Kim } while (0) 201339a53e0cSJaegeuk Kim 2014e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 201539a53e0cSJaegeuk Kim do { \ 2016963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 201739a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 201839a53e0cSJaegeuk Kim si->node_blks += (blks); \ 2019e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 202039a53e0cSJaegeuk Kim } while (0) 202139a53e0cSJaegeuk Kim 202239a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 202339a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 2024787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 20254589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 202639a53e0cSJaegeuk Kim #else 2027942e0be6SChangman Lee #define stat_inc_cp_count(si) 202839a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 2029dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 203033fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) 203133fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) 2032dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 2033029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 203491c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 203591c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 2036d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 2037d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 20380dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 20390dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 20403289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 20413289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 2042dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 2043dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 2044b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 2045e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 204639a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 2047e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 2048e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 204939a53e0cSJaegeuk Kim 205039a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 205139a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2052787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 20534589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 205439a53e0cSJaegeuk Kim #endif 205539a53e0cSJaegeuk Kim 205639a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 205739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 205839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 205939a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 206039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 206139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 206239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 206339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2064cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 206539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 206629e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 20671001b347SHuajun Li 2068e18c65b2SHuajun Li /* 2069e18c65b2SHuajun Li * inline.c 2070e18c65b2SHuajun Li */ 207101b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 207201b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 2073b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 20740bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 2075e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 2076b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 2077b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 2078b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 20790342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 20806e22c691SJaegeuk Kim struct f2fs_dir_entry *find_in_inline_dir(struct inode *, 20816e22c691SJaegeuk Kim struct f2fs_filename *, struct page **); 2082201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 2083201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 2084510022a8SJaegeuk Kim int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 2085510022a8SJaegeuk Kim nid_t, umode_t); 2086201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 2087201a05beSChao Yu struct inode *, struct inode *); 2088201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 2089d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *, struct dir_context *, 2090d8c6822aSJaegeuk Kim struct f2fs_str *); 209167f8cf3cSJaegeuk Kim int f2fs_inline_data_fiemap(struct inode *, 209267f8cf3cSJaegeuk Kim struct fiemap_extent_info *, __u64, __u64); 2093cde4de12SJaegeuk Kim 2094cde4de12SJaegeuk Kim /* 20952658e50dSJaegeuk Kim * shrinker.c 20962658e50dSJaegeuk Kim */ 20972658e50dSJaegeuk Kim unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *); 20982658e50dSJaegeuk Kim unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *); 20992658e50dSJaegeuk Kim void f2fs_join_shrinker(struct f2fs_sb_info *); 21002658e50dSJaegeuk Kim void f2fs_leave_shrinker(struct f2fs_sb_info *); 21012658e50dSJaegeuk Kim 21022658e50dSJaegeuk Kim /* 2103a28ef1f5SChao Yu * extent_cache.c 2104a28ef1f5SChao Yu */ 2105a28ef1f5SChao Yu unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 2106ed3d1256SJaegeuk Kim bool f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 2107a28ef1f5SChao Yu unsigned int f2fs_destroy_extent_node(struct inode *); 2108a28ef1f5SChao Yu void f2fs_destroy_extent_tree(struct inode *); 2109a28ef1f5SChao Yu bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *); 2110a28ef1f5SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 211119b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 211219b2c30dSChao Yu pgoff_t, block_t, unsigned int); 2113a28ef1f5SChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 2114a28ef1f5SChao Yu int __init create_extent_cache(void); 2115a28ef1f5SChao Yu void destroy_extent_cache(void); 2116a28ef1f5SChao Yu 2117a28ef1f5SChao Yu /* 2118cde4de12SJaegeuk Kim * crypto support 2119cde4de12SJaegeuk Kim */ 2120cde4de12SJaegeuk Kim static inline int f2fs_encrypted_inode(struct inode *inode) 2121cde4de12SJaegeuk Kim { 2122cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2123cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2124cde4de12SJaegeuk Kim #else 2125cde4de12SJaegeuk Kim return 0; 2126cde4de12SJaegeuk Kim #endif 2127cde4de12SJaegeuk Kim } 2128cde4de12SJaegeuk Kim 2129cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2130cde4de12SJaegeuk Kim { 2131cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2132cde4de12SJaegeuk Kim file_set_encrypt(inode); 2133cde4de12SJaegeuk Kim #endif 2134cde4de12SJaegeuk Kim } 2135cde4de12SJaegeuk Kim 2136cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2137cde4de12SJaegeuk Kim { 2138cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2139cde4de12SJaegeuk Kim return unlikely(bio->bi_private != NULL); 2140cde4de12SJaegeuk Kim #else 2141cde4de12SJaegeuk Kim return false; 2142cde4de12SJaegeuk Kim #endif 2143cde4de12SJaegeuk Kim } 2144cde4de12SJaegeuk Kim 2145cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2146cde4de12SJaegeuk Kim { 2147cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2148cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2149cde4de12SJaegeuk Kim #else 2150cde4de12SJaegeuk Kim return 0; 2151cde4de12SJaegeuk Kim #endif 2152cde4de12SJaegeuk Kim } 2153f424f664SJaegeuk Kim 2154fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2155fcc85a4dSJaegeuk Kim { 2156fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2157fcc85a4dSJaegeuk Kim mode_t mode = inode->i_mode; 2158fcc85a4dSJaegeuk Kim 2159fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2160fcc85a4dSJaegeuk Kim #else 2161fcc85a4dSJaegeuk Kim return 0; 2162fcc85a4dSJaegeuk Kim #endif 2163fcc85a4dSJaegeuk Kim } 2164fcc85a4dSJaegeuk Kim 2165f424f664SJaegeuk Kim /* crypto_policy.c */ 2166f424f664SJaegeuk Kim int f2fs_is_child_context_consistent_with_parent(struct inode *, 2167f424f664SJaegeuk Kim struct inode *); 2168f424f664SJaegeuk Kim int f2fs_inherit_context(struct inode *, struct inode *, struct page *); 2169f424f664SJaegeuk Kim int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *); 2170f424f664SJaegeuk Kim int f2fs_get_policy(struct inode *, struct f2fs_encryption_policy *); 217157e5055bSJaegeuk Kim 217257e5055bSJaegeuk Kim /* crypt.c */ 21738bacf6deSJaegeuk Kim extern struct kmem_cache *f2fs_crypt_info_cachep; 217457e5055bSJaegeuk Kim bool f2fs_valid_contents_enc_mode(uint32_t); 217557e5055bSJaegeuk Kim uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t); 217657e5055bSJaegeuk Kim struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *); 217757e5055bSJaegeuk Kim void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *); 217857e5055bSJaegeuk Kim struct page *f2fs_encrypt(struct inode *, struct page *); 217957e5055bSJaegeuk Kim int f2fs_decrypt(struct f2fs_crypto_ctx *, struct page *); 218057e5055bSJaegeuk Kim int f2fs_decrypt_one(struct inode *, struct page *); 218157e5055bSJaegeuk Kim void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *); 218257e5055bSJaegeuk Kim 21830adda907SJaegeuk Kim /* crypto_key.c */ 218426bf3dc7SJaegeuk Kim void f2fs_free_encryption_info(struct inode *, struct f2fs_crypt_info *); 21850adda907SJaegeuk Kim int _f2fs_get_encryption_info(struct inode *inode); 21860adda907SJaegeuk Kim 21876b3bd08fSJaegeuk Kim /* crypto_fname.c */ 21886b3bd08fSJaegeuk Kim bool f2fs_valid_filenames_enc_mode(uint32_t); 21896b3bd08fSJaegeuk Kim u32 f2fs_fname_crypto_round_up(u32, u32); 21906b3bd08fSJaegeuk Kim int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *); 21916b3bd08fSJaegeuk Kim int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *, 21926b3bd08fSJaegeuk Kim const struct f2fs_str *, struct f2fs_str *); 21936b3bd08fSJaegeuk Kim int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *, 21946b3bd08fSJaegeuk Kim struct f2fs_str *); 21956b3bd08fSJaegeuk Kim 219657e5055bSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 219757e5055bSJaegeuk Kim void f2fs_restore_and_release_control_page(struct page **); 219857e5055bSJaegeuk Kim void f2fs_restore_control_page(struct page *); 219957e5055bSJaegeuk Kim 2200cfc4d971SJaegeuk Kim int __init f2fs_init_crypto(void); 2201cfc4d971SJaegeuk Kim int f2fs_crypto_initialize(void); 220257e5055bSJaegeuk Kim void f2fs_exit_crypto(void); 22030adda907SJaegeuk Kim 22040adda907SJaegeuk Kim int f2fs_has_encryption_key(struct inode *); 22050adda907SJaegeuk Kim 22060adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *inode) 22070adda907SJaegeuk Kim { 22080adda907SJaegeuk Kim struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info; 22090adda907SJaegeuk Kim 22100adda907SJaegeuk Kim if (!ci || 22110adda907SJaegeuk Kim (ci->ci_keyring_key && 22120adda907SJaegeuk Kim (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | 22130adda907SJaegeuk Kim (1 << KEY_FLAG_REVOKED) | 22140adda907SJaegeuk Kim (1 << KEY_FLAG_DEAD))))) 22150adda907SJaegeuk Kim return _f2fs_get_encryption_info(inode); 22160adda907SJaegeuk Kim return 0; 22170adda907SJaegeuk Kim } 22186b3bd08fSJaegeuk Kim 22196b3bd08fSJaegeuk Kim void f2fs_fname_crypto_free_buffer(struct f2fs_str *); 22206b3bd08fSJaegeuk Kim int f2fs_fname_setup_filename(struct inode *, const struct qstr *, 22216b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *); 22226b3bd08fSJaegeuk Kim void f2fs_fname_free_filename(struct f2fs_filename *); 222357e5055bSJaegeuk Kim #else 222457e5055bSJaegeuk Kim static inline void f2fs_restore_and_release_control_page(struct page **p) { } 222557e5055bSJaegeuk Kim static inline void f2fs_restore_control_page(struct page *p) { } 222657e5055bSJaegeuk Kim 2227cfc4d971SJaegeuk Kim static inline int __init f2fs_init_crypto(void) { return 0; } 222857e5055bSJaegeuk Kim static inline void f2fs_exit_crypto(void) { } 22290adda907SJaegeuk Kim 22300adda907SJaegeuk Kim static inline int f2fs_has_encryption_key(struct inode *i) { return 0; } 22310adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *i) { return 0; } 22326b3bd08fSJaegeuk Kim static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { } 22336b3bd08fSJaegeuk Kim 22346b3bd08fSJaegeuk Kim static inline int f2fs_fname_setup_filename(struct inode *dir, 22356b3bd08fSJaegeuk Kim const struct qstr *iname, 22366b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *fname) 22376b3bd08fSJaegeuk Kim { 22386b3bd08fSJaegeuk Kim memset(fname, 0, sizeof(struct f2fs_filename)); 22396b3bd08fSJaegeuk Kim fname->usr_fname = iname; 22406b3bd08fSJaegeuk Kim fname->disk_name.name = (unsigned char *)iname->name; 22416b3bd08fSJaegeuk Kim fname->disk_name.len = iname->len; 22426b3bd08fSJaegeuk Kim return 0; 22436b3bd08fSJaegeuk Kim } 22446b3bd08fSJaegeuk Kim 22456b3bd08fSJaegeuk Kim static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { } 224657e5055bSJaegeuk Kim #endif 224739a53e0cSJaegeuk Kim #endif 2248