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> 22740432f8SJaegeuk Kim #include <linux/bio.h> 2339a53e0cSJaegeuk Kim 245d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 259850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 260daaad97SJaegeuk Kim #define f2fs_down_write(x, y) down_write_nest_lock(x, y) 275d56b671SJaegeuk Kim #else 289850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 299850cf4aSJaegeuk Kim do { \ 309850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 319850cf4aSJaegeuk Kim WARN_ON(1); \ 32caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 339850cf4aSJaegeuk Kim } \ 349850cf4aSJaegeuk Kim } while (0) 350daaad97SJaegeuk Kim #define f2fs_down_write(x, y) down_write(x) 365d56b671SJaegeuk Kim #endif 375d56b671SJaegeuk Kim 3839a53e0cSJaegeuk Kim /* 3939a53e0cSJaegeuk Kim * For mount options 4039a53e0cSJaegeuk Kim */ 4139a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 4239a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 4339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 4439a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 4539a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 4639a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 4739a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 48444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 491001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 5034d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 5134d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 5234d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 53d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 5489672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 5539a53e0cSJaegeuk Kim 5639a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 5739a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 5839a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 5939a53e0cSJaegeuk Kim 6039a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 6139a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 6239a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 6339a53e0cSJaegeuk Kim 64a9841c4dSJaegeuk Kim typedef u32 block_t; /* 65a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 66a9841c4dSJaegeuk Kim * address format, __le32. 67a9841c4dSJaegeuk Kim */ 6839a53e0cSJaegeuk Kim typedef u32 nid_t; 6939a53e0cSJaegeuk Kim 7039a53e0cSJaegeuk Kim struct f2fs_mount_info { 7139a53e0cSJaegeuk Kim unsigned int opt; 7239a53e0cSJaegeuk Kim }; 7339a53e0cSJaegeuk Kim 74cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 75cde4de12SJaegeuk Kim 7676f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 7776f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 7876f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 7976f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) 8076f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 8176f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) 8276f105a2SJaegeuk Kim 837e586fa0SJaegeuk Kim #define CRCPOLY_LE 0xedb88320 847e586fa0SJaegeuk Kim 857e586fa0SJaegeuk Kim static inline __u32 f2fs_crc32(void *buf, size_t len) 8639a53e0cSJaegeuk Kim { 877e586fa0SJaegeuk Kim unsigned char *p = (unsigned char *)buf; 887e586fa0SJaegeuk Kim __u32 crc = F2FS_SUPER_MAGIC; 897e586fa0SJaegeuk Kim int i; 907e586fa0SJaegeuk Kim 917e586fa0SJaegeuk Kim while (len--) { 927e586fa0SJaegeuk Kim crc ^= *p++; 937e586fa0SJaegeuk Kim for (i = 0; i < 8; i++) 947e586fa0SJaegeuk Kim crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); 957e586fa0SJaegeuk Kim } 967e586fa0SJaegeuk Kim return crc; 9739a53e0cSJaegeuk Kim } 9839a53e0cSJaegeuk Kim 997e586fa0SJaegeuk Kim static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size) 10039a53e0cSJaegeuk Kim { 1017e586fa0SJaegeuk Kim return f2fs_crc32(buf, buf_size) == blk_crc; 10239a53e0cSJaegeuk Kim } 10339a53e0cSJaegeuk Kim 10439a53e0cSJaegeuk Kim /* 10539a53e0cSJaegeuk Kim * For checkpoint manager 10639a53e0cSJaegeuk Kim */ 10739a53e0cSJaegeuk Kim enum { 10839a53e0cSJaegeuk Kim NAT_BITMAP, 10939a53e0cSJaegeuk Kim SIT_BITMAP 11039a53e0cSJaegeuk Kim }; 11139a53e0cSJaegeuk Kim 11275ab4cb8SJaegeuk Kim enum { 11375ab4cb8SJaegeuk Kim CP_UMOUNT, 114119ee914SJaegeuk Kim CP_FASTBOOT, 11575ab4cb8SJaegeuk Kim CP_SYNC, 11610027551SJaegeuk Kim CP_RECOVERY, 1174b2fecc8SJaegeuk Kim CP_DISCARD, 11875ab4cb8SJaegeuk Kim }; 11975ab4cb8SJaegeuk Kim 120bba681cbSJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 32 121bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 122bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 123a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 124a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 125bba681cbSJaegeuk Kim 12675ab4cb8SJaegeuk Kim struct cp_control { 12775ab4cb8SJaegeuk Kim int reason; 1284b2fecc8SJaegeuk Kim __u64 trim_start; 1294b2fecc8SJaegeuk Kim __u64 trim_end; 1304b2fecc8SJaegeuk Kim __u64 trim_minlen; 1314b2fecc8SJaegeuk Kim __u64 trimmed; 13275ab4cb8SJaegeuk Kim }; 13375ab4cb8SJaegeuk Kim 134662befdaSChao Yu /* 13581c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 136662befdaSChao Yu */ 137662befdaSChao Yu enum { 138662befdaSChao Yu META_CP, 139662befdaSChao Yu META_NAT, 14081c1a0f1SChao Yu META_SIT, 1414c521f49SJaegeuk Kim META_SSA, 1424c521f49SJaegeuk Kim META_POR, 143662befdaSChao Yu }; 144662befdaSChao Yu 1456451e041SJaegeuk Kim /* for the list of ino */ 1466451e041SJaegeuk Kim enum { 1476451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 148fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 149fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1506451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1516451e041SJaegeuk Kim }; 1526451e041SJaegeuk Kim 1536451e041SJaegeuk Kim struct ino_entry { 15439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 15539a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 15639a53e0cSJaegeuk Kim }; 15739a53e0cSJaegeuk Kim 15806292073SChao Yu /* 15906292073SChao Yu * for the list of directory inodes or gc inodes. 16006292073SChao Yu * NOTE: there are two slab users for this structure, if we add/modify/delete 16106292073SChao Yu * fields in structure for one of slab users, it may affect fields or size of 16206292073SChao Yu * other one, in this condition, it's better to split both of slab and related 16306292073SChao Yu * data structure. 16406292073SChao Yu */ 16506292073SChao Yu struct inode_entry { 16639a53e0cSJaegeuk Kim struct list_head list; /* list head */ 16739a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 16839a53e0cSJaegeuk Kim }; 16939a53e0cSJaegeuk Kim 1707fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1717fd9e544SJaegeuk Kim struct discard_entry { 1727fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1737fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1747fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1757fd9e544SJaegeuk Kim }; 1767fd9e544SJaegeuk Kim 17739a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 17839a53e0cSJaegeuk Kim struct fsync_inode_entry { 17939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18039a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 181c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 182c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 183c52e1b10SJaegeuk Kim block_t last_inode; /* block address locating the last inode */ 18439a53e0cSJaegeuk Kim }; 18539a53e0cSJaegeuk Kim 18639a53e0cSJaegeuk Kim #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats)) 18739a53e0cSJaegeuk Kim #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits)) 18839a53e0cSJaegeuk Kim 18939a53e0cSJaegeuk Kim #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne) 19039a53e0cSJaegeuk Kim #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid) 19139a53e0cSJaegeuk Kim #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se) 19239a53e0cSJaegeuk Kim #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno) 19339a53e0cSJaegeuk Kim 194309cc2b6SJaegeuk Kim #define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum)) 195309cc2b6SJaegeuk Kim #define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum)) 196309cc2b6SJaegeuk Kim 19739a53e0cSJaegeuk Kim static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i) 19839a53e0cSJaegeuk Kim { 19939a53e0cSJaegeuk Kim int before = nats_in_cursum(rs); 20039a53e0cSJaegeuk Kim rs->n_nats = cpu_to_le16(before + i); 20139a53e0cSJaegeuk Kim return before; 20239a53e0cSJaegeuk Kim } 20339a53e0cSJaegeuk Kim 20439a53e0cSJaegeuk Kim static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i) 20539a53e0cSJaegeuk Kim { 20639a53e0cSJaegeuk Kim int before = sits_in_cursum(rs); 20739a53e0cSJaegeuk Kim rs->n_sits = cpu_to_le16(before + i); 20839a53e0cSJaegeuk Kim return before; 20939a53e0cSJaegeuk Kim } 21039a53e0cSJaegeuk Kim 211184a5cd2SChao Yu static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size, 212184a5cd2SChao Yu int type) 213184a5cd2SChao Yu { 214184a5cd2SChao Yu if (type == NAT_JOURNAL) 215309cc2b6SJaegeuk Kim return size <= MAX_NAT_JENTRIES(sum); 216309cc2b6SJaegeuk Kim return size <= MAX_SIT_JENTRIES(sum); 217184a5cd2SChao Yu } 218184a5cd2SChao Yu 21939a53e0cSJaegeuk Kim /* 220e9750824SNamjae Jeon * ioctl commands 221e9750824SNamjae Jeon */ 222e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 223e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 224d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 225e9750824SNamjae Jeon 22688b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 22788b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 22888b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 22902a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2301e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2311e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 232c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 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 */ 2491abff93dSJaegeuk Kim 250e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 251e9750824SNamjae Jeon /* 252e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 253e9750824SNamjae Jeon */ 254e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 255e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 256e9750824SNamjae Jeon #endif 257e9750824SNamjae Jeon 258e9750824SNamjae Jeon /* 25939a53e0cSJaegeuk Kim * For INODE and NODE manager 26039a53e0cSJaegeuk Kim */ 2617b3cd7d6SJaegeuk Kim /* for directory operations */ 2626b3bd08fSJaegeuk Kim struct f2fs_str { 2636b3bd08fSJaegeuk Kim unsigned char *name; 2646b3bd08fSJaegeuk Kim u32 len; 2656b3bd08fSJaegeuk Kim }; 2666b3bd08fSJaegeuk Kim 2676b3bd08fSJaegeuk Kim struct f2fs_filename { 2686b3bd08fSJaegeuk Kim const struct qstr *usr_fname; 2696b3bd08fSJaegeuk Kim struct f2fs_str disk_name; 2706b3bd08fSJaegeuk Kim f2fs_hash_t hash; 2716b3bd08fSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2726b3bd08fSJaegeuk Kim struct f2fs_str crypto_buf; 2736b3bd08fSJaegeuk Kim #endif 2746b3bd08fSJaegeuk Kim }; 2756b3bd08fSJaegeuk Kim 2766b3bd08fSJaegeuk Kim #define FSTR_INIT(n, l) { .name = n, .len = l } 2776b3bd08fSJaegeuk Kim #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len) 2786b3bd08fSJaegeuk Kim #define fname_name(p) ((p)->disk_name.name) 2796b3bd08fSJaegeuk Kim #define fname_len(p) ((p)->disk_name.len) 2806b3bd08fSJaegeuk Kim 2817b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 282d8c6822aSJaegeuk Kim struct inode *inode; 2837b3cd7d6SJaegeuk Kim const void *bitmap; 2847b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 2857b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 2867b3cd7d6SJaegeuk Kim int max; 2877b3cd7d6SJaegeuk Kim }; 2887b3cd7d6SJaegeuk Kim 289d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode, 290d8c6822aSJaegeuk Kim struct f2fs_dentry_ptr *d, void *src, int type) 2917b3cd7d6SJaegeuk Kim { 292d8c6822aSJaegeuk Kim d->inode = inode; 293d8c6822aSJaegeuk Kim 2947b3cd7d6SJaegeuk Kim if (type == 1) { 2957b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 2967b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 2977b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2987b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 2997b3cd7d6SJaegeuk Kim d->filename = t->filename; 3007b3cd7d6SJaegeuk Kim } else { 3017b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 3027b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3037b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3047b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3057b3cd7d6SJaegeuk Kim d->filename = t->filename; 3067b3cd7d6SJaegeuk Kim } 3077b3cd7d6SJaegeuk Kim } 3087b3cd7d6SJaegeuk Kim 309dbe6a5ffSJaegeuk Kim /* 310dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 311dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 312dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 31339a53e0cSJaegeuk Kim */ 314dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 315dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 316266e97a8SJaegeuk Kim enum { 317266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 318266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 319266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 320266e97a8SJaegeuk Kim * look up a node with readahead called 3214f4124d0SChao Yu * by get_data_block. 32239a53e0cSJaegeuk Kim */ 323266e97a8SJaegeuk Kim }; 324266e97a8SJaegeuk Kim 325a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 32639a53e0cSJaegeuk Kim 327817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 328817202d9SChao Yu 32913054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 33013054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 33113054c54SChao Yu 33239a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 33313054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 33413054c54SChao Yu 33513054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 33613054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 337c11abd1aSJaegeuk Kim 33839a53e0cSJaegeuk Kim struct extent_info { 33939a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3404d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 341111d2495SMasanari Iida unsigned int len; /* length of the extent */ 34239a53e0cSJaegeuk Kim }; 34339a53e0cSJaegeuk Kim 34413054c54SChao Yu struct extent_node { 34513054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 34613054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 34713054c54SChao Yu struct extent_info ei; /* extent info */ 34813054c54SChao Yu }; 34913054c54SChao Yu 35013054c54SChao Yu struct extent_tree { 35113054c54SChao Yu nid_t ino; /* inode number */ 35213054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 35362c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 3543e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 35513054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 35613054c54SChao Yu atomic_t refcount; /* reference count of rb-tree */ 35713054c54SChao Yu unsigned int count; /* # of extent node in rb-tree*/ 35813054c54SChao Yu }; 35913054c54SChao Yu 36039a53e0cSJaegeuk Kim /* 361003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 362003a3e1dSJaegeuk Kim * 363003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 364003a3e1dSJaegeuk Kim */ 365003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 366003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 3677f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 3687f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 3697f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 370003a3e1dSJaegeuk Kim 371003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 372003a3e1dSJaegeuk Kim block_t m_pblk; 373003a3e1dSJaegeuk Kim block_t m_lblk; 374003a3e1dSJaegeuk Kim unsigned int m_len; 375003a3e1dSJaegeuk Kim unsigned int m_flags; 376003a3e1dSJaegeuk Kim }; 377003a3e1dSJaegeuk Kim 378e2b4e2bcSChao Yu /* for flag in get_data_block */ 379e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 380e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 381e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 382e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 383e2b4e2bcSChao Yu 384003a3e1dSJaegeuk Kim /* 38539a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 38639a53e0cSJaegeuk Kim */ 38739a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 388354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 389cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 390e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 39139a53e0cSJaegeuk Kim 392b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 393b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 394b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 395b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 396b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 397b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 398cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 399cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 400cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 401e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 402e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 403cde4de12SJaegeuk Kim 404cde4de12SJaegeuk Kim /* Encryption algorithms */ 405cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_INVALID 0 406cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_XTS 1 407cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_GCM 2 408cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CBC 3 409cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CTS 4 410b5492af7SJaegeuk Kim 411f424f664SJaegeuk Kim #include "f2fs_crypto.h" 412f424f664SJaegeuk Kim 413ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 414ab9fa662SJaegeuk Kim 41539a53e0cSJaegeuk Kim struct f2fs_inode_info { 41639a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 41739a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 41839a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 41938431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 42039a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4216666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 42239a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 42339a53e0cSJaegeuk Kim 42439a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 42539a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 426d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 427a7ffdbe2SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 42839a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 42939a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 43039a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 431e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 43206292073SChao Yu struct inode_entry *dirty_dir; /* the pointer of dirty dir */ 43388b88a66SJaegeuk Kim 43488b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 43588b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 436cde4de12SJaegeuk Kim 4373e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 4383e72f721SJaegeuk Kim 439cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 440cde4de12SJaegeuk Kim /* Encryption params */ 441cde4de12SJaegeuk Kim struct f2fs_crypt_info *i_crypt_info; 442cde4de12SJaegeuk Kim #endif 44339a53e0cSJaegeuk Kim }; 44439a53e0cSJaegeuk Kim 44539a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 44639a53e0cSJaegeuk Kim struct f2fs_extent i_ext) 44739a53e0cSJaegeuk Kim { 44839a53e0cSJaegeuk Kim ext->fofs = le32_to_cpu(i_ext.fofs); 4494d0b0bd4SChao Yu ext->blk = le32_to_cpu(i_ext.blk); 45039a53e0cSJaegeuk Kim ext->len = le32_to_cpu(i_ext.len); 45139a53e0cSJaegeuk Kim } 45239a53e0cSJaegeuk Kim 45339a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 45439a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 45539a53e0cSJaegeuk Kim { 45639a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4574d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 45839a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 45939a53e0cSJaegeuk Kim } 46039a53e0cSJaegeuk Kim 461429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 462429511cdSChao Yu u32 blk, unsigned int len) 463429511cdSChao Yu { 464429511cdSChao Yu ei->fofs = fofs; 465429511cdSChao Yu ei->blk = blk; 466429511cdSChao Yu ei->len = len; 467429511cdSChao Yu } 468429511cdSChao Yu 4690bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1, 4700bdee482SChao Yu struct extent_info *ei2) 4710bdee482SChao Yu { 4720bdee482SChao Yu return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 4730bdee482SChao Yu ei1->len == ei2->len); 4740bdee482SChao Yu } 4750bdee482SChao Yu 476429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 477429511cdSChao Yu struct extent_info *front) 478429511cdSChao Yu { 479429511cdSChao Yu return (back->fofs + back->len == front->fofs && 480429511cdSChao Yu back->blk + back->len == front->blk); 481429511cdSChao Yu } 482429511cdSChao Yu 483429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 484429511cdSChao Yu struct extent_info *back) 485429511cdSChao Yu { 486429511cdSChao Yu return __is_extent_mergeable(back, cur); 487429511cdSChao Yu } 488429511cdSChao Yu 489429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 490429511cdSChao Yu struct extent_info *front) 491429511cdSChao Yu { 492429511cdSChao Yu return __is_extent_mergeable(cur, front); 493429511cdSChao Yu } 494429511cdSChao Yu 495*4abd3f5aSChao Yu static inline void __try_update_largest_extent(struct extent_tree *et, 496*4abd3f5aSChao Yu struct extent_node *en) 497*4abd3f5aSChao Yu { 498*4abd3f5aSChao Yu if (en->ei.len > et->largest.len) 499*4abd3f5aSChao Yu et->largest = en->ei; 500*4abd3f5aSChao Yu } 501*4abd3f5aSChao Yu 50239a53e0cSJaegeuk Kim struct f2fs_nm_info { 50339a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 50439a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 5057ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 50639a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 507cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 50839a53e0cSJaegeuk Kim 50939a53e0cSJaegeuk Kim /* NAT cache management */ 51039a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 511309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 5128b26ef98SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 51339a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 514309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 515aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 51639a53e0cSJaegeuk Kim 51739a53e0cSJaegeuk Kim /* free node ids management */ 5188a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 51939a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 52039a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 52139a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 52239a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 52339a53e0cSJaegeuk Kim 52439a53e0cSJaegeuk Kim /* for checkpoint */ 52539a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 52639a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 52739a53e0cSJaegeuk Kim }; 52839a53e0cSJaegeuk Kim 52939a53e0cSJaegeuk Kim /* 53039a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 53139a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 53239a53e0cSJaegeuk Kim * by the data offset in a file. 53339a53e0cSJaegeuk Kim */ 53439a53e0cSJaegeuk Kim struct dnode_of_data { 53539a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 53639a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 53739a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 53839a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 53939a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 54039a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 54139a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 54239a53e0cSJaegeuk Kim }; 54339a53e0cSJaegeuk Kim 54439a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 54539a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 54639a53e0cSJaegeuk Kim { 547d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 54839a53e0cSJaegeuk Kim dn->inode = inode; 54939a53e0cSJaegeuk Kim dn->inode_page = ipage; 55039a53e0cSJaegeuk Kim dn->node_page = npage; 55139a53e0cSJaegeuk Kim dn->nid = nid; 55239a53e0cSJaegeuk Kim } 55339a53e0cSJaegeuk Kim 55439a53e0cSJaegeuk Kim /* 55539a53e0cSJaegeuk Kim * For SIT manager 55639a53e0cSJaegeuk Kim * 55739a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 55839a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 55939a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 56039a53e0cSJaegeuk Kim * respectively. 56139a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 56239a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 56339a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 56439a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 56539a53e0cSJaegeuk Kim * data and 8 for node logs. 56639a53e0cSJaegeuk Kim */ 56739a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 56839a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 56939a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 57039a53e0cSJaegeuk Kim 57139a53e0cSJaegeuk Kim enum { 57239a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 57339a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 57439a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 57539a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 57639a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 57739a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 57838aa0889SJaegeuk Kim NO_CHECK_TYPE, 57938aa0889SJaegeuk Kim CURSEG_DIRECT_IO, /* to use for the direct IO path */ 58039a53e0cSJaegeuk Kim }; 58139a53e0cSJaegeuk Kim 5826b4afdd7SJaegeuk Kim struct flush_cmd { 5836b4afdd7SJaegeuk Kim struct completion wait; 584721bd4d5SGu Zheng struct llist_node llnode; 5856b4afdd7SJaegeuk Kim int ret; 5866b4afdd7SJaegeuk Kim }; 5876b4afdd7SJaegeuk Kim 588a688b9d9SGu Zheng struct flush_cmd_control { 589a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 590a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 591721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 592721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 593a688b9d9SGu Zheng }; 594a688b9d9SGu Zheng 59539a53e0cSJaegeuk Kim struct f2fs_sm_info { 59639a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 59739a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 59839a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 59939a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 60039a53e0cSJaegeuk Kim 60139a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 60239a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 60339a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 60439a53e0cSJaegeuk Kim 60539a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 60639a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 60739a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 60839a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 60981eb8d6eSJaegeuk Kim 61081eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 61181eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 6127fd9e544SJaegeuk Kim 6137fd9e544SJaegeuk Kim /* for small discard management */ 6147fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 6157fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 6167fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 617216fbd64SJaegeuk Kim 618bba681cbSJaegeuk Kim /* for batched trimming */ 619bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 620bba681cbSJaegeuk Kim 621184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 622184a5cd2SChao Yu 623216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 624216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 625c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 6266b4afdd7SJaegeuk Kim 6276b4afdd7SJaegeuk Kim /* for flush command control */ 628a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 629a688b9d9SGu Zheng 63039a53e0cSJaegeuk Kim }; 63139a53e0cSJaegeuk Kim 63239a53e0cSJaegeuk Kim /* 63339a53e0cSJaegeuk Kim * For superblock 63439a53e0cSJaegeuk Kim */ 63539a53e0cSJaegeuk Kim /* 63639a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 63739a53e0cSJaegeuk Kim * 63839a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 63939a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 64039a53e0cSJaegeuk Kim */ 64139a53e0cSJaegeuk Kim enum count_type { 64239a53e0cSJaegeuk Kim F2FS_WRITEBACK, 64339a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 64439a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 64539a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6468dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 64739a53e0cSJaegeuk Kim NR_COUNT_TYPE, 64839a53e0cSJaegeuk Kim }; 64939a53e0cSJaegeuk Kim 65039a53e0cSJaegeuk Kim /* 651e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 65239a53e0cSJaegeuk Kim * The available types are: 65339a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 65439a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 65539a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 65639a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 65739a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 65839a53e0cSJaegeuk Kim * with waiting the bio's completion 65939a53e0cSJaegeuk Kim * ... Only can be used with META. 66039a53e0cSJaegeuk Kim */ 6617d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 66239a53e0cSJaegeuk Kim enum page_type { 66339a53e0cSJaegeuk Kim DATA, 66439a53e0cSJaegeuk Kim NODE, 66539a53e0cSJaegeuk Kim META, 66639a53e0cSJaegeuk Kim NR_PAGE_TYPE, 66739a53e0cSJaegeuk Kim META_FLUSH, 6688ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 6698ce67cb0SJaegeuk Kim INMEM_DROP, 6708ce67cb0SJaegeuk Kim IPU, 6718ce67cb0SJaegeuk Kim OPU, 67239a53e0cSJaegeuk Kim }; 67339a53e0cSJaegeuk Kim 674458e6197SJaegeuk Kim struct f2fs_io_info { 67505ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 676458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 6777e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 678cf04e8ebSJaegeuk Kim block_t blk_addr; /* block address to be written */ 67905ca3632SJaegeuk Kim struct page *page; /* page to be written */ 6804375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 681458e6197SJaegeuk Kim }; 682458e6197SJaegeuk Kim 68393dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 6841ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 685458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 6861ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 6871ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 688458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 689df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 6901ff7bd3bSJaegeuk Kim }; 6911ff7bd3bSJaegeuk Kim 69267298804SChao Yu /* for inner inode cache management */ 69367298804SChao Yu struct inode_management { 69467298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 69567298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 69667298804SChao Yu struct list_head ino_list; /* inode list head */ 69767298804SChao Yu unsigned long ino_num; /* number of entries */ 69867298804SChao Yu }; 69967298804SChao Yu 700caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 701caf0047eSChao Yu enum { 702caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 703caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 704caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 705caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 706caf0047eSChao Yu }; 707caf0047eSChao Yu 70839a53e0cSJaegeuk Kim struct f2fs_sb_info { 70939a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 7105e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 71139a53e0cSJaegeuk Kim struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 71239a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 713caf0047eSChao Yu int s_flag; /* flags for sbi */ 71439a53e0cSJaegeuk Kim 71539a53e0cSJaegeuk Kim /* for node-related operations */ 71639a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 71739a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 71839a53e0cSJaegeuk Kim 71939a53e0cSJaegeuk Kim /* for segment-related operations */ 72039a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 7211ff7bd3bSJaegeuk Kim 7221ff7bd3bSJaegeuk Kim /* for bio operations */ 723924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 7241ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 72539a53e0cSJaegeuk Kim 72639a53e0cSJaegeuk Kim /* for checkpoint */ 72739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 72839a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 72939936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 730e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 731b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 7325463e7c1SJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 733fb51b5efSChangman Lee wait_queue_head_t cp_wait; 73439a53e0cSJaegeuk Kim 73567298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 7366451e041SJaegeuk Kim 7376451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 7380d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 73939a53e0cSJaegeuk Kim 74039a53e0cSJaegeuk Kim /* for directory inode management */ 74139a53e0cSJaegeuk Kim struct list_head dir_inode_list; /* dir inode list */ 74239a53e0cSJaegeuk Kim spinlock_t dir_inode_lock; /* for dir inode list lock */ 74339a53e0cSJaegeuk Kim 74413054c54SChao Yu /* for extent tree cache */ 74513054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 74613054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 74713054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 74813054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 74913054c54SChao Yu int total_ext_tree; /* extent tree count */ 75013054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 75113054c54SChao Yu 75239a53e0cSJaegeuk Kim /* basic filesystem units */ 75339a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 75439a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 75539a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 75639a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 75739a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 75839a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 75939a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 76039a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 76139a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 76239a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 76339a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 76439a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 76539a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 76639a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 76739a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 768ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 76939a53e0cSJaegeuk Kim 77039a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 77139a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 77239a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 773a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 77439a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 77539a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 77639a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 77739a53e0cSJaegeuk Kim 77839a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 77939a53e0cSJaegeuk Kim 78039a53e0cSJaegeuk Kim /* for cleaning operations */ 78139a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 78239a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 7835ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 78439a53e0cSJaegeuk Kim 785b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 786b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 787b1c57c1cSJaegeuk Kim 78839a53e0cSJaegeuk Kim /* 78939a53e0cSJaegeuk Kim * for stat information. 79039a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 79139a53e0cSJaegeuk Kim */ 79235b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 79339a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 79439a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 79539a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 796b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 797727edac5SChao Yu atomic_t total_hit_ext; /* # of lookup extent cache */ 798029e13ccSChao Yu atomic_t read_hit_rbtree; /* # of hit rbtree extent node */ 79991c481ffSChao Yu atomic_t read_hit_largest; /* # of hit largest extent node */ 80091c481ffSChao Yu atomic_t read_hit_cached; /* # of hit cached extent node */ 801d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 80203e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 80303e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 80439a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 80535b09d82SNamjae Jeon unsigned int n_dirty_dirs; /* # of dir inodes */ 80635b09d82SNamjae Jeon #endif 80735b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 80839a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 809b59d0baeSNamjae Jeon 810b59d0baeSNamjae Jeon /* For sysfs suppport */ 811b59d0baeSNamjae Jeon struct kobject s_kobj; 812b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 8132658e50dSJaegeuk Kim 8142658e50dSJaegeuk Kim /* For shrinker support */ 8152658e50dSJaegeuk Kim struct list_head s_list; 8162658e50dSJaegeuk Kim struct mutex umount_mutex; 8172658e50dSJaegeuk Kim unsigned int shrinker_run_no; 81839a53e0cSJaegeuk Kim }; 81939a53e0cSJaegeuk Kim 82039a53e0cSJaegeuk Kim /* 82139a53e0cSJaegeuk Kim * Inline functions 82239a53e0cSJaegeuk Kim */ 82339a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 82439a53e0cSJaegeuk Kim { 82539a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 82639a53e0cSJaegeuk Kim } 82739a53e0cSJaegeuk Kim 82839a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 82939a53e0cSJaegeuk Kim { 83039a53e0cSJaegeuk Kim return sb->s_fs_info; 83139a53e0cSJaegeuk Kim } 83239a53e0cSJaegeuk Kim 8334081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 8344081363fSJaegeuk Kim { 8354081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 8364081363fSJaegeuk Kim } 8374081363fSJaegeuk Kim 8384081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 8394081363fSJaegeuk Kim { 8404081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 8414081363fSJaegeuk Kim } 8424081363fSJaegeuk Kim 8434081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 8444081363fSJaegeuk Kim { 8454081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 8464081363fSJaegeuk Kim } 8474081363fSJaegeuk Kim 84839a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 84939a53e0cSJaegeuk Kim { 85039a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 85139a53e0cSJaegeuk Kim } 85239a53e0cSJaegeuk Kim 85339a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 85439a53e0cSJaegeuk Kim { 85539a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 85639a53e0cSJaegeuk Kim } 85739a53e0cSJaegeuk Kim 85845590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 85945590710SGu Zheng { 86045590710SGu Zheng return (struct f2fs_node *)page_address(page); 86145590710SGu Zheng } 86245590710SGu Zheng 86358bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 86458bfaf44SJaegeuk Kim { 86558bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 86658bfaf44SJaegeuk Kim } 86758bfaf44SJaegeuk Kim 86839a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 86939a53e0cSJaegeuk Kim { 87039a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 87139a53e0cSJaegeuk Kim } 87239a53e0cSJaegeuk Kim 87339a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 87439a53e0cSJaegeuk Kim { 87539a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 87639a53e0cSJaegeuk Kim } 87739a53e0cSJaegeuk Kim 87839a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 87939a53e0cSJaegeuk Kim { 88039a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 88139a53e0cSJaegeuk Kim } 88239a53e0cSJaegeuk Kim 88339a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 88439a53e0cSJaegeuk Kim { 88539a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 88639a53e0cSJaegeuk Kim } 88739a53e0cSJaegeuk Kim 88839a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 88939a53e0cSJaegeuk Kim { 89039a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 89139a53e0cSJaegeuk Kim } 89239a53e0cSJaegeuk Kim 8939df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 8949df27d98SGu Zheng { 8959df27d98SGu Zheng return sbi->meta_inode->i_mapping; 8969df27d98SGu Zheng } 8979df27d98SGu Zheng 8984ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 8994ef51a8fSJaegeuk Kim { 9004ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 9014ef51a8fSJaegeuk Kim } 9024ef51a8fSJaegeuk Kim 903caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 90439a53e0cSJaegeuk Kim { 905caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 90639a53e0cSJaegeuk Kim } 90739a53e0cSJaegeuk Kim 908caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 90939a53e0cSJaegeuk Kim { 910caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 911caf0047eSChao Yu } 912caf0047eSChao Yu 913caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 914caf0047eSChao Yu { 915caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 91639a53e0cSJaegeuk Kim } 91739a53e0cSJaegeuk Kim 918d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 919d71b5564SJaegeuk Kim { 920d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 921d71b5564SJaegeuk Kim } 922d71b5564SJaegeuk Kim 92325ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 92425ca923bSJaegeuk Kim { 92525ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 92625ca923bSJaegeuk Kim return ckpt_flags & f; 92725ca923bSJaegeuk Kim } 92825ca923bSJaegeuk Kim 92925ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 93025ca923bSJaegeuk Kim { 93125ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 93225ca923bSJaegeuk Kim ckpt_flags |= f; 93325ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 93425ca923bSJaegeuk Kim } 93525ca923bSJaegeuk Kim 93625ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 93725ca923bSJaegeuk Kim { 93825ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 93925ca923bSJaegeuk Kim ckpt_flags &= (~f); 94025ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 94125ca923bSJaegeuk Kim } 94225ca923bSJaegeuk Kim 943e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 94439a53e0cSJaegeuk Kim { 945e479556bSGu Zheng down_read(&sbi->cp_rwsem); 94639a53e0cSJaegeuk Kim } 94739a53e0cSJaegeuk Kim 948e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 94939a53e0cSJaegeuk Kim { 950e479556bSGu Zheng up_read(&sbi->cp_rwsem); 95139936837SJaegeuk Kim } 95239936837SJaegeuk Kim 953e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 95439936837SJaegeuk Kim { 9550daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 95639936837SJaegeuk Kim } 95739936837SJaegeuk Kim 958e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 95939936837SJaegeuk Kim { 960e479556bSGu Zheng up_write(&sbi->cp_rwsem); 96139a53e0cSJaegeuk Kim } 96239a53e0cSJaegeuk Kim 963119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 964119ee914SJaegeuk Kim { 965119ee914SJaegeuk Kim int reason = CP_SYNC; 966119ee914SJaegeuk Kim 967119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 968119ee914SJaegeuk Kim reason = CP_FASTBOOT; 969119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 970119ee914SJaegeuk Kim reason = CP_UMOUNT; 971119ee914SJaegeuk Kim return reason; 972119ee914SJaegeuk Kim } 973119ee914SJaegeuk Kim 974119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 975119ee914SJaegeuk Kim { 976119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 977119ee914SJaegeuk Kim } 978119ee914SJaegeuk Kim 979119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 980119ee914SJaegeuk Kim { 981119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 982119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 983119ee914SJaegeuk Kim } 984119ee914SJaegeuk Kim 98539a53e0cSJaegeuk Kim /* 98639a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 98739a53e0cSJaegeuk Kim */ 988064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 98939a53e0cSJaegeuk Kim { 990d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 991d6b7d4b3SChao Yu return -EINVAL; 992cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 993064e0823SNamjae Jeon return -EINVAL; 994064e0823SNamjae Jeon return 0; 99539a53e0cSJaegeuk Kim } 99639a53e0cSJaegeuk Kim 99739a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 99839a53e0cSJaegeuk Kim 99939a53e0cSJaegeuk Kim /* 100039a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 100139a53e0cSJaegeuk Kim */ 100239a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 100339a53e0cSJaegeuk Kim { 100439a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 10056c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 100639a53e0cSJaegeuk Kim else 10076c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 100839a53e0cSJaegeuk Kim } 100939a53e0cSJaegeuk Kim 10104bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 10114bc8e9bcSChao Yu { 10124bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 10134bc8e9bcSChao Yu } 10144bc8e9bcSChao Yu 101539a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 101639a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 101739a53e0cSJaegeuk Kim { 101839a53e0cSJaegeuk Kim block_t valid_block_count; 101939a53e0cSJaegeuk Kim 102039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 102139a53e0cSJaegeuk Kim valid_block_count = 102239a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 1023cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 102439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 102539a53e0cSJaegeuk Kim return false; 102639a53e0cSJaegeuk Kim } 102739a53e0cSJaegeuk Kim inode->i_blocks += count; 102839a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 102939a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 103039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 103139a53e0cSJaegeuk Kim return true; 103239a53e0cSJaegeuk Kim } 103339a53e0cSJaegeuk Kim 1034da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 103539a53e0cSJaegeuk Kim struct inode *inode, 103639a53e0cSJaegeuk Kim blkcnt_t count) 103739a53e0cSJaegeuk Kim { 103839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 10399850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 10409850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 104139a53e0cSJaegeuk Kim inode->i_blocks -= count; 104239a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 104339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 104439a53e0cSJaegeuk Kim } 104539a53e0cSJaegeuk Kim 104639a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 104739a53e0cSJaegeuk Kim { 104839a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 1049caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 105039a53e0cSJaegeuk Kim } 105139a53e0cSJaegeuk Kim 1052a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 105339a53e0cSJaegeuk Kim { 1054a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1055a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10564081363fSJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 105739a53e0cSJaegeuk Kim } 105839a53e0cSJaegeuk Kim 105939a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 106039a53e0cSJaegeuk Kim { 106139a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 106239a53e0cSJaegeuk Kim } 106339a53e0cSJaegeuk Kim 1064a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 106539a53e0cSJaegeuk Kim { 10665ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 10675ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 10681fe54f9dSJaegeuk Kim return; 10691fe54f9dSJaegeuk Kim 1070a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1071a7ffdbe2SJaegeuk Kim 1072a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10734081363fSJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 107439a53e0cSJaegeuk Kim } 107539a53e0cSJaegeuk Kim 107639a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 107739a53e0cSJaegeuk Kim { 107839a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 107939a53e0cSJaegeuk Kim } 108039a53e0cSJaegeuk Kim 1081a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1082f8b2c1f9SJaegeuk Kim { 1083a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1084f8b2c1f9SJaegeuk Kim } 1085f8b2c1f9SJaegeuk Kim 10865ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 10875ac206cfSNamjae Jeon { 10885ac206cfSNamjae Jeon unsigned int pages_per_sec = sbi->segs_per_sec * 10895ac206cfSNamjae Jeon (1 << sbi->log_blocks_per_seg); 10905ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 10915ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 10925ac206cfSNamjae Jeon } 10935ac206cfSNamjae Jeon 109439a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 109539a53e0cSJaegeuk Kim { 10968b8343faSJaegeuk Kim return sbi->total_valid_block_count; 109739a53e0cSJaegeuk Kim } 109839a53e0cSJaegeuk Kim 109939a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 110039a53e0cSJaegeuk Kim { 110139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 110239a53e0cSJaegeuk Kim 110339a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 110439a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 110539a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 110639a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 110739a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 110839a53e0cSJaegeuk Kim 110939a53e0cSJaegeuk Kim return 0; 111039a53e0cSJaegeuk Kim } 111139a53e0cSJaegeuk Kim 111255141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 111355141486SWanpeng Li { 111455141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 111555141486SWanpeng Li } 111655141486SWanpeng Li 111739a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 111839a53e0cSJaegeuk Kim { 111939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 11201dbe4152SChangman Lee int offset; 11211dbe4152SChangman Lee 112255141486SWanpeng Li if (__cp_payload(sbi) > 0) { 11231dbe4152SChangman Lee if (flag == NAT_BITMAP) 11241dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 11251dbe4152SChangman Lee else 112665b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 11271dbe4152SChangman Lee } else { 11281dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 112925ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 113039a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 113139a53e0cSJaegeuk Kim } 11321dbe4152SChangman Lee } 113339a53e0cSJaegeuk Kim 113439a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 113539a53e0cSJaegeuk Kim { 113639a53e0cSJaegeuk Kim block_t start_addr; 113739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1138d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 113939a53e0cSJaegeuk Kim 114025ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 114139a53e0cSJaegeuk Kim 114239a53e0cSJaegeuk Kim /* 114339a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1144e1c42045Sarter97 * and even segment must be at cp segment 1 114539a53e0cSJaegeuk Kim */ 114639a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 114739a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 114839a53e0cSJaegeuk Kim 114939a53e0cSJaegeuk Kim return start_addr; 115039a53e0cSJaegeuk Kim } 115139a53e0cSJaegeuk Kim 115239a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 115339a53e0cSJaegeuk Kim { 115439a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 115539a53e0cSJaegeuk Kim } 115639a53e0cSJaegeuk Kim 115739a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1158ef86d709SGu Zheng struct inode *inode) 115939a53e0cSJaegeuk Kim { 116039a53e0cSJaegeuk Kim block_t valid_block_count; 116139a53e0cSJaegeuk Kim unsigned int valid_node_count; 116239a53e0cSJaegeuk Kim 116339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 116439a53e0cSJaegeuk Kim 1165ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1166cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 116739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 116839a53e0cSJaegeuk Kim return false; 116939a53e0cSJaegeuk Kim } 117039a53e0cSJaegeuk Kim 1171ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1172cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 117339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 117439a53e0cSJaegeuk Kim return false; 117539a53e0cSJaegeuk Kim } 117639a53e0cSJaegeuk Kim 117739a53e0cSJaegeuk Kim if (inode) 1178ef86d709SGu Zheng inode->i_blocks++; 1179ef86d709SGu Zheng 1180ef86d709SGu Zheng sbi->alloc_valid_block_count++; 1181ef86d709SGu Zheng sbi->total_valid_node_count++; 1182ef86d709SGu Zheng sbi->total_valid_block_count++; 118339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 118439a53e0cSJaegeuk Kim 118539a53e0cSJaegeuk Kim return true; 118639a53e0cSJaegeuk Kim } 118739a53e0cSJaegeuk Kim 118839a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1189ef86d709SGu Zheng struct inode *inode) 119039a53e0cSJaegeuk Kim { 119139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 119239a53e0cSJaegeuk Kim 11939850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 11949850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 11959850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 119639a53e0cSJaegeuk Kim 1197ef86d709SGu Zheng inode->i_blocks--; 1198ef86d709SGu Zheng sbi->total_valid_node_count--; 1199ef86d709SGu Zheng sbi->total_valid_block_count--; 120039a53e0cSJaegeuk Kim 120139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 120239a53e0cSJaegeuk Kim } 120339a53e0cSJaegeuk Kim 120439a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 120539a53e0cSJaegeuk Kim { 12068b8343faSJaegeuk Kim return sbi->total_valid_node_count; 120739a53e0cSJaegeuk Kim } 120839a53e0cSJaegeuk Kim 120939a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 121039a53e0cSJaegeuk Kim { 121139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12129850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 121339a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 121439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 121539a53e0cSJaegeuk Kim } 121639a53e0cSJaegeuk Kim 12170e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 121839a53e0cSJaegeuk Kim { 121939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12209850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 122139a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 122239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 122339a53e0cSJaegeuk Kim } 122439a53e0cSJaegeuk Kim 122539a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 122639a53e0cSJaegeuk Kim { 12278b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 122839a53e0cSJaegeuk Kim } 122939a53e0cSJaegeuk Kim 123039a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 123139a53e0cSJaegeuk Kim { 1232031fa8ccSJaegeuk Kim if (!page) 123339a53e0cSJaegeuk Kim return; 123439a53e0cSJaegeuk Kim 123539a53e0cSJaegeuk Kim if (unlock) { 12369850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 123739a53e0cSJaegeuk Kim unlock_page(page); 123839a53e0cSJaegeuk Kim } 123939a53e0cSJaegeuk Kim page_cache_release(page); 124039a53e0cSJaegeuk Kim } 124139a53e0cSJaegeuk Kim 124239a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 124339a53e0cSJaegeuk Kim { 124439a53e0cSJaegeuk Kim if (dn->node_page) 124539a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 124639a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 124739a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 124839a53e0cSJaegeuk Kim dn->node_page = NULL; 124939a53e0cSJaegeuk Kim dn->inode_page = NULL; 125039a53e0cSJaegeuk Kim } 125139a53e0cSJaegeuk Kim 125239a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1253e8512d2eSGu Zheng size_t size) 125439a53e0cSJaegeuk Kim { 1255e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 125639a53e0cSJaegeuk Kim } 125739a53e0cSJaegeuk Kim 12587bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 12597bd59381SGu Zheng gfp_t flags) 12607bd59381SGu Zheng { 12617bd59381SGu Zheng void *entry; 12627bd59381SGu Zheng 126380c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 126480c54505SJaegeuk Kim if (!entry) 126580c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 12667bd59381SGu Zheng return entry; 12677bd59381SGu Zheng } 12687bd59381SGu Zheng 1269740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1270740432f8SJaegeuk Kim { 1271740432f8SJaegeuk Kim struct bio *bio; 1272740432f8SJaegeuk Kim 1273740432f8SJaegeuk Kim /* No failure on bio allocation */ 1274740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 127580c54505SJaegeuk Kim if (!bio) 127680c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1277740432f8SJaegeuk Kim return bio; 1278740432f8SJaegeuk Kim } 1279740432f8SJaegeuk Kim 12809be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 12819be32d72SJaegeuk Kim unsigned long index, void *item) 12829be32d72SJaegeuk Kim { 12839be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 12849be32d72SJaegeuk Kim cond_resched(); 12859be32d72SJaegeuk Kim } 12869be32d72SJaegeuk Kim 128739a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 128839a53e0cSJaegeuk Kim 128939a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 129039a53e0cSJaegeuk Kim { 129145590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 129239a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 129339a53e0cSJaegeuk Kim } 129439a53e0cSJaegeuk Kim 129539a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 129639a53e0cSJaegeuk Kim { 129739a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 129839a53e0cSJaegeuk Kim } 129939a53e0cSJaegeuk Kim 130039a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 130139a53e0cSJaegeuk Kim unsigned int offset) 130239a53e0cSJaegeuk Kim { 130339a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 130439a53e0cSJaegeuk Kim __le32 *addr_array; 130545590710SGu Zheng raw_node = F2FS_NODE(node_page); 130639a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 130739a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 130839a53e0cSJaegeuk Kim } 130939a53e0cSJaegeuk Kim 131039a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 131139a53e0cSJaegeuk Kim { 131239a53e0cSJaegeuk Kim int mask; 131339a53e0cSJaegeuk Kim 131439a53e0cSJaegeuk Kim addr += (nr >> 3); 131539a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 131639a53e0cSJaegeuk Kim return mask & *addr; 131739a53e0cSJaegeuk Kim } 131839a53e0cSJaegeuk Kim 1319a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1320a66cdd98SJaegeuk Kim { 1321a66cdd98SJaegeuk Kim int mask; 1322a66cdd98SJaegeuk Kim 1323a66cdd98SJaegeuk Kim addr += (nr >> 3); 1324a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1325a66cdd98SJaegeuk Kim *addr |= mask; 1326a66cdd98SJaegeuk Kim } 1327a66cdd98SJaegeuk Kim 1328a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1329a66cdd98SJaegeuk Kim { 1330a66cdd98SJaegeuk Kim int mask; 1331a66cdd98SJaegeuk Kim 1332a66cdd98SJaegeuk Kim addr += (nr >> 3); 1333a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1334a66cdd98SJaegeuk Kim *addr &= ~mask; 1335a66cdd98SJaegeuk Kim } 1336a66cdd98SJaegeuk Kim 133752aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 133839a53e0cSJaegeuk Kim { 133939a53e0cSJaegeuk Kim int mask; 134039a53e0cSJaegeuk Kim int ret; 134139a53e0cSJaegeuk Kim 134239a53e0cSJaegeuk Kim addr += (nr >> 3); 134339a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 134439a53e0cSJaegeuk Kim ret = mask & *addr; 134539a53e0cSJaegeuk Kim *addr |= mask; 134639a53e0cSJaegeuk Kim return ret; 134739a53e0cSJaegeuk Kim } 134839a53e0cSJaegeuk Kim 134952aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 135039a53e0cSJaegeuk Kim { 135139a53e0cSJaegeuk Kim int mask; 135239a53e0cSJaegeuk Kim int ret; 135339a53e0cSJaegeuk Kim 135439a53e0cSJaegeuk Kim addr += (nr >> 3); 135539a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 135639a53e0cSJaegeuk Kim ret = mask & *addr; 135739a53e0cSJaegeuk Kim *addr &= ~mask; 135839a53e0cSJaegeuk Kim return ret; 135939a53e0cSJaegeuk Kim } 136039a53e0cSJaegeuk Kim 1361c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1362c6ac4c0eSGu Zheng { 1363c6ac4c0eSGu Zheng int mask; 1364c6ac4c0eSGu Zheng 1365c6ac4c0eSGu Zheng addr += (nr >> 3); 1366c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1367c6ac4c0eSGu Zheng *addr ^= mask; 1368c6ac4c0eSGu Zheng } 1369c6ac4c0eSGu Zheng 137039a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 137139a53e0cSJaegeuk Kim enum { 137239a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1373b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1374ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 137539a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 137639a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 137739a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1378c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1379699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 138074d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1381c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1382444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 13831001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 138434d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1385fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1386fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 138788b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 138888b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 138902a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 13903c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 13911e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1392b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1393510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 139439a53e0cSJaegeuk Kim }; 139539a53e0cSJaegeuk Kim 139639a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 139739a53e0cSJaegeuk Kim { 139861e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 139939a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 140039a53e0cSJaegeuk Kim } 140139a53e0cSJaegeuk Kim 140239a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 140339a53e0cSJaegeuk Kim { 140439a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 140539a53e0cSJaegeuk Kim } 140639a53e0cSJaegeuk Kim 140739a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 140839a53e0cSJaegeuk Kim { 140961e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 141039a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 141139a53e0cSJaegeuk Kim } 141239a53e0cSJaegeuk Kim 141339a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 141439a53e0cSJaegeuk Kim { 141539a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 141639a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 141739a53e0cSJaegeuk Kim } 141839a53e0cSJaegeuk Kim 1419444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1420444c580fSJaegeuk Kim struct f2fs_inode *ri) 1421444c580fSJaegeuk Kim { 1422444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1423444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 14241001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 14251001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 142634d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 142734d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1428b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1429b3d208f9SJaegeuk Kim set_inode_flag(fi, FI_DATA_EXIST); 1430510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1431510022a8SJaegeuk Kim set_inode_flag(fi, FI_INLINE_DOTS); 1432444c580fSJaegeuk Kim } 1433444c580fSJaegeuk Kim 1434444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1435444c580fSJaegeuk Kim struct f2fs_inode *ri) 1436444c580fSJaegeuk Kim { 1437444c580fSJaegeuk Kim ri->i_inline = 0; 1438444c580fSJaegeuk Kim 1439444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1440444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 14411001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 14421001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 144334d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 144434d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1445b3d208f9SJaegeuk Kim if (is_inode_flag_set(fi, FI_DATA_EXIST)) 1446b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1447510022a8SJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_DOTS)) 1448510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1449444c580fSJaegeuk Kim } 1450444c580fSJaegeuk Kim 1451987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1452987c7c31SChao Yu { 1453987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1454987c7c31SChao Yu } 1455987c7c31SChao Yu 1456de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1457de93653fSJaegeuk Kim { 1458987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1459de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1460de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1461de93653fSJaegeuk Kim } 1462de93653fSJaegeuk Kim 146365985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 146465985d93SJaegeuk Kim { 1465695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 146665985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 146765985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 146865985d93SJaegeuk Kim } 146965985d93SJaegeuk Kim 147065985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 147165985d93SJaegeuk Kim { 1472987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 147365985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 147465985d93SJaegeuk Kim else 147565985d93SJaegeuk Kim return 0; 147665985d93SJaegeuk Kim } 147765985d93SJaegeuk Kim 14780dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 14790dbdc2aeSJaegeuk Kim { 14800dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 14810dbdc2aeSJaegeuk Kim } 14820dbdc2aeSJaegeuk Kim 1483b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1484b3d208f9SJaegeuk Kim { 1485b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 1486b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1487b3d208f9SJaegeuk Kim } 1488b3d208f9SJaegeuk Kim 1489b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1490b3d208f9SJaegeuk Kim { 1491b3d208f9SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST); 1492b3d208f9SJaegeuk Kim } 1493b3d208f9SJaegeuk Kim 1494510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1495510022a8SJaegeuk Kim { 1496510022a8SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS); 1497510022a8SJaegeuk Kim } 1498510022a8SJaegeuk Kim 149988b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 150088b88a66SJaegeuk Kim { 150188b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 150288b88a66SJaegeuk Kim } 150388b88a66SJaegeuk Kim 150402a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 150502a1335fSJaegeuk Kim { 150602a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 150702a1335fSJaegeuk Kim } 150802a1335fSJaegeuk Kim 15093c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 15103c6c2bebSJaegeuk Kim { 15113c6c2bebSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); 15123c6c2bebSJaegeuk Kim } 15133c6c2bebSJaegeuk Kim 15141e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 15151e84371fSJaegeuk Kim { 15161e84371fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE); 15171e84371fSJaegeuk Kim } 15181e84371fSJaegeuk Kim 15191001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 15201001b347SHuajun Li { 1521695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 15221001b347SHuajun Li return (void *)&(ri->i_addr[1]); 15231001b347SHuajun Li } 15241001b347SHuajun Li 152534d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 152634d67debSChao Yu { 152734d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 152834d67debSChao Yu } 152934d67debSChao Yu 15309486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 15319486ba44SJaegeuk Kim { 15329486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 15339486ba44SJaegeuk Kim kunmap(page); 15349486ba44SJaegeuk Kim } 15359486ba44SJaegeuk Kim 1536b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1537b5492af7SJaegeuk Kim { 1538b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1539b5492af7SJaegeuk Kim } 1540b5492af7SJaegeuk Kim 1541b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1542b5492af7SJaegeuk Kim { 1543b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1544b5492af7SJaegeuk Kim } 1545b5492af7SJaegeuk Kim 1546b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1547b5492af7SJaegeuk Kim { 1548b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1549b5492af7SJaegeuk Kim } 1550b5492af7SJaegeuk Kim 155177888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 155277888c1eSJaegeuk Kim { 155377888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 155477888c1eSJaegeuk Kim } 155577888c1eSJaegeuk Kim 15561e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 15571e968fdfSJaegeuk Kim { 15581e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 15591e968fdfSJaegeuk Kim } 15601e968fdfSJaegeuk Kim 1561744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1562744602cfSJaegeuk Kim { 1563744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1564744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1565744602cfSJaegeuk Kim } 1566744602cfSJaegeuk Kim 1567eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1568eaa693f4SJaegeuk Kim { 1569eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1570eaa693f4SJaegeuk Kim return true; 1571eaa693f4SJaegeuk Kim 1572eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1573eaa693f4SJaegeuk Kim return true; 1574eaa693f4SJaegeuk Kim 1575eaa693f4SJaegeuk Kim return false; 1576eaa693f4SJaegeuk Kim } 1577eaa693f4SJaegeuk Kim 15783e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 15793e72f721SJaegeuk Kim { 15803e72f721SJaegeuk Kim mode_t mode = inode->i_mode; 15813e72f721SJaegeuk Kim 15823e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 15833e72f721SJaegeuk Kim is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT)) 15843e72f721SJaegeuk Kim return false; 15853e72f721SJaegeuk Kim 15863e72f721SJaegeuk Kim return S_ISREG(mode); 15873e72f721SJaegeuk Kim } 15883e72f721SJaegeuk Kim 1589a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1590a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1591a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1592a6dda0e6SChristoph Hellwig 1593267378d4SChao Yu /* get offset of first page in next direct node */ 1594267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1595267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1596267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1597267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1598267378d4SChao Yu 159939a53e0cSJaegeuk Kim /* 160039a53e0cSJaegeuk Kim * file.c 160139a53e0cSJaegeuk Kim */ 160239a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 160339a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1604764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 1605b0154891SChao Yu int f2fs_truncate(struct inode *, bool); 16062d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 160739a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 160839a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1609b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 161039a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1611e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 161239a53e0cSJaegeuk Kim 161339a53e0cSJaegeuk Kim /* 161439a53e0cSJaegeuk Kim * inode.c 161539a53e0cSJaegeuk Kim */ 161639a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 161739a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 16184660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 161939a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *); 1620744602cfSJaegeuk Kim void update_inode_page(struct inode *); 162139a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 162239a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 162344c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 162439a53e0cSJaegeuk Kim 162539a53e0cSJaegeuk Kim /* 162639a53e0cSJaegeuk Kim * namei.c 162739a53e0cSJaegeuk Kim */ 162839a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 162939a53e0cSJaegeuk Kim 163039a53e0cSJaegeuk Kim /* 163139a53e0cSJaegeuk Kim * dir.c 163239a53e0cSJaegeuk Kim */ 1633dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1634510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 16356e22c691SJaegeuk Kim 16366e22c691SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct f2fs_filename *, 16376e22c691SJaegeuk Kim f2fs_hash_t, int *, struct f2fs_dentry_ptr *); 16387b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 1639d8c6822aSJaegeuk Kim unsigned int, struct f2fs_str *); 1640062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1641062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1642dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1643bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1644dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1645a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1646dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 164739a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 164839a53e0cSJaegeuk Kim struct page **); 164939a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 165039a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 165139a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 165239a53e0cSJaegeuk Kim struct page *, struct inode *); 1653e7d55452SJaegeuk Kim int update_dent_inode(struct inode *, struct inode *, const struct qstr *); 1654510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 16553b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1656510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1657510022a8SJaegeuk Kim umode_t); 1658dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1659dbeacf02SChao Yu struct inode *); 1660b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 166139a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 166239a53e0cSJaegeuk Kim 1663b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1664b7f7a5e0SAl Viro { 16652b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1666510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1667b7f7a5e0SAl Viro } 1668b7f7a5e0SAl Viro 166939a53e0cSJaegeuk Kim /* 167039a53e0cSJaegeuk Kim * super.c 167139a53e0cSJaegeuk Kim */ 1672c5bda1c8SChao Yu int f2fs_commit_super(struct f2fs_sb_info *, bool); 167339a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1674a07ef784SNamjae Jeon extern __printf(3, 4) 1675a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 167639a53e0cSJaegeuk Kim 167739a53e0cSJaegeuk Kim /* 167839a53e0cSJaegeuk Kim * hash.c 167939a53e0cSJaegeuk Kim */ 1680eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 168139a53e0cSJaegeuk Kim 168239a53e0cSJaegeuk Kim /* 168339a53e0cSJaegeuk Kim * node.c 168439a53e0cSJaegeuk Kim */ 168539a53e0cSJaegeuk Kim struct dnode_of_data; 168639a53e0cSJaegeuk Kim struct node_info; 168739a53e0cSJaegeuk Kim 16886fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 16892dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t); 169088bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 169188bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 169239a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 169339a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 169439a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 16954f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1696cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 169713ec7297SChao Yu int remove_inode_page(struct inode *); 1698a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 16998ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 170039a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 170139a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 170239a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 170339a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 170439a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 170539a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 170639a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 170739a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 170831696580SChao Yu int try_to_free_nids(struct f2fs_sb_info *, int); 170970cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 17101c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 171139a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 171239a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 171339a53e0cSJaegeuk Kim struct f2fs_summary_block *); 171439a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 171539a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 171639a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 17176e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 171839a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 171939a53e0cSJaegeuk Kim 172039a53e0cSJaegeuk Kim /* 172139a53e0cSJaegeuk Kim * segment.c 172239a53e0cSJaegeuk Kim */ 172388b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 1724edb27deeSJaegeuk Kim int commit_inmem_pages(struct inode *, bool); 172539a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *); 17264660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 17276b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 17282163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 17292163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 173039a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 17315e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 1732836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 17334b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1734e90c2d28SChao Yu bool discard_next_dnode(struct f2fs_sb_info *, block_t); 17353fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 173639a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 17374b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 173839a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1739381722d2SChao Yu void update_meta_page(struct f2fs_sb_info *, void *, block_t); 1740577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 174105ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 174205ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 174305ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 1744528e3459SChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *, 1745528e3459SChao Yu block_t, block_t, unsigned char, bool); 1746bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1747bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 17485514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 174939a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 175039a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 175139a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 175239a53e0cSJaegeuk Kim int, unsigned int, int); 17534b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 175439a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 175539a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 17567fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 17577fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 175839a53e0cSJaegeuk Kim 175939a53e0cSJaegeuk Kim /* 176039a53e0cSJaegeuk Kim * checkpoint.c 176139a53e0cSJaegeuk Kim */ 176239a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 176339a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 1764f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 17654c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int); 1766635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 176739a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1768fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1769fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 17706f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *); 1771fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1772cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1773cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 177439a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 177539a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 17768c14bfadSChao Yu int recover_orphan_inodes(struct f2fs_sb_info *); 177739a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1778a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 17795deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 178039a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *); 178139a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *); 178275ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 17836451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 17846e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 178539a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 178639a53e0cSJaegeuk Kim 178739a53e0cSJaegeuk Kim /* 178839a53e0cSJaegeuk Kim * data.c 178939a53e0cSJaegeuk Kim */ 1790458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 179105ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 179205ca3632SJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_io_info *); 1793216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 179439a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1795759af1c9SFan Li int f2fs_get_block(struct dnode_of_data *, pgoff_t); 1796b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 179743f3eae1SJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int); 179843f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t); 179939a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t); 180064aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 180105ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 18029ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1803487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1804487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 180539a53e0cSJaegeuk Kim 180639a53e0cSJaegeuk Kim /* 180739a53e0cSJaegeuk Kim * gc.c 180839a53e0cSJaegeuk Kim */ 180939a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 181039a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1811de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1812408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *); 181339a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 181439a53e0cSJaegeuk Kim 181539a53e0cSJaegeuk Kim /* 181639a53e0cSJaegeuk Kim * recovery.c 181739a53e0cSJaegeuk Kim */ 18186ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 181939a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 182039a53e0cSJaegeuk Kim 182139a53e0cSJaegeuk Kim /* 182239a53e0cSJaegeuk Kim * debug.c 182339a53e0cSJaegeuk Kim */ 182439a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 182539a53e0cSJaegeuk Kim struct f2fs_stat_info { 182639a53e0cSJaegeuk Kim struct list_head stat_list; 182739a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 182839a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 182939a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 1830029e13ccSChao Yu int hit_largest, hit_cached, hit_rbtree, hit_total, total_ext; 1831029e13ccSChao Yu int ext_tree, ext_node; 183239a53e0cSJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 1833dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 183439a53e0cSJaegeuk Kim int total_count, utilization; 1835d5e8f6c9SChao Yu int bg_gc, inmem_pages, wb_pages; 1836d5e8f6c9SChao Yu int inline_xattr, inline_inode, inline_dir; 183739a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 183839a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 183939a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 184039a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 184139a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1842942e0be6SChangman Lee int prefree_count, call_count, cp_count; 184339a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 1844e1235983SChangman Lee int bg_node_segs, bg_data_segs; 184539a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 1846e1235983SChangman Lee int bg_data_blks, bg_node_blks; 184739a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 184839a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 184939a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 185039a53e0cSJaegeuk Kim 185139a53e0cSJaegeuk Kim unsigned int segment_count[2]; 185239a53e0cSJaegeuk Kim unsigned int block_count[2]; 1853b9a2c252SChangman Lee unsigned int inplace_count; 18549edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 185539a53e0cSJaegeuk Kim }; 185639a53e0cSJaegeuk Kim 1857963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1858963d4f7dSGu Zheng { 1859963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1860963d4f7dSGu Zheng } 1861963d4f7dSGu Zheng 1862942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 186339a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1864dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1865dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1866dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 1867727edac5SChao Yu #define stat_inc_total_hit(sbi) (atomic_inc(&(sbi)->total_hit_ext)) 1868029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic_inc(&(sbi)->read_hit_rbtree)) 186991c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) (atomic_inc(&(sbi)->read_hit_largest)) 187091c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) (atomic_inc(&(sbi)->read_hit_cached)) 1871d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 1872d5e8f6c9SChao Yu do { \ 1873d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1874d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 1875d5e8f6c9SChao Yu } while (0) 1876d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 1877d5e8f6c9SChao Yu do { \ 1878d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1879d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 1880d5e8f6c9SChao Yu } while (0) 18810dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 18820dbdc2aeSJaegeuk Kim do { \ 18830dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 188403e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 18850dbdc2aeSJaegeuk Kim } while (0) 18860dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 18870dbdc2aeSJaegeuk Kim do { \ 18880dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 188903e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 18900dbdc2aeSJaegeuk Kim } while (0) 18913289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 18923289c061SJaegeuk Kim do { \ 18933289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 189403e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 18953289c061SJaegeuk Kim } while (0) 18963289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 18973289c061SJaegeuk Kim do { \ 18983289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 189903e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 19003289c061SJaegeuk Kim } while (0) 1901dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1902dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1903dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1904dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 1905b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 1906b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 1907e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 190839a53e0cSJaegeuk Kim do { \ 1909963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 191039a53e0cSJaegeuk Kim (si)->tot_segs++; \ 1911e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 191239a53e0cSJaegeuk Kim si->data_segs++; \ 1913e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 1914e1235983SChangman Lee } else { \ 191539a53e0cSJaegeuk Kim si->node_segs++; \ 1916e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 1917e1235983SChangman Lee } \ 191839a53e0cSJaegeuk Kim } while (0) 191939a53e0cSJaegeuk Kim 192039a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 192139a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 192239a53e0cSJaegeuk Kim 1923e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 192439a53e0cSJaegeuk Kim do { \ 1925963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 192639a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 192739a53e0cSJaegeuk Kim si->data_blks += (blks); \ 1928e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 192939a53e0cSJaegeuk Kim } while (0) 193039a53e0cSJaegeuk Kim 1931e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 193239a53e0cSJaegeuk Kim do { \ 1933963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 193439a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 193539a53e0cSJaegeuk Kim si->node_blks += (blks); \ 1936e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 193739a53e0cSJaegeuk Kim } while (0) 193839a53e0cSJaegeuk Kim 193939a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 194039a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 19416e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void); 19424589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 194339a53e0cSJaegeuk Kim #else 1944942e0be6SChangman Lee #define stat_inc_cp_count(si) 194539a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 1946dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 1947dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) 1948dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) 1949dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 1950029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 195191c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 195291c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 1953d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 1954d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 19550dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 19560dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 19573289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 19583289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 1959dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 1960dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 1961b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 1962e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 196339a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 1964e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 1965e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 196639a53e0cSJaegeuk Kim 196739a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 196839a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 19696e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { } 19704589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 197139a53e0cSJaegeuk Kim #endif 197239a53e0cSJaegeuk Kim 197339a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 197439a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 197539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 197639a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 197739a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 197839a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 197939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 198039a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 1981cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 198239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 198329e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 19841001b347SHuajun Li 1985e18c65b2SHuajun Li /* 1986e18c65b2SHuajun Li * inline.c 1987e18c65b2SHuajun Li */ 198801b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 198901b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 1990b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 19910bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 1992e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 1993b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 1994b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 1995b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 19960342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 19976e22c691SJaegeuk Kim struct f2fs_dir_entry *find_in_inline_dir(struct inode *, 19986e22c691SJaegeuk Kim struct f2fs_filename *, struct page **); 1999201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 2000201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 2001510022a8SJaegeuk Kim int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 2002510022a8SJaegeuk Kim nid_t, umode_t); 2003201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 2004201a05beSChao Yu struct inode *, struct inode *); 2005201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 2006d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *, struct dir_context *, 2007d8c6822aSJaegeuk Kim struct f2fs_str *); 2008cde4de12SJaegeuk Kim 2009cde4de12SJaegeuk Kim /* 20102658e50dSJaegeuk Kim * shrinker.c 20112658e50dSJaegeuk Kim */ 20122658e50dSJaegeuk Kim unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *); 20132658e50dSJaegeuk Kim unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *); 20142658e50dSJaegeuk Kim void f2fs_join_shrinker(struct f2fs_sb_info *); 20152658e50dSJaegeuk Kim void f2fs_leave_shrinker(struct f2fs_sb_info *); 20162658e50dSJaegeuk Kim 20172658e50dSJaegeuk Kim /* 2018a28ef1f5SChao Yu * extent_cache.c 2019a28ef1f5SChao Yu */ 2020a28ef1f5SChao Yu unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 2021a28ef1f5SChao Yu void f2fs_drop_largest_extent(struct inode *, pgoff_t); 2022a28ef1f5SChao Yu void f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 2023a28ef1f5SChao Yu unsigned int f2fs_destroy_extent_node(struct inode *); 2024a28ef1f5SChao Yu void f2fs_destroy_extent_tree(struct inode *); 2025a28ef1f5SChao Yu bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *); 2026a28ef1f5SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 202719b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 202819b2c30dSChao Yu pgoff_t, block_t, unsigned int); 2029a28ef1f5SChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 2030a28ef1f5SChao Yu int __init create_extent_cache(void); 2031a28ef1f5SChao Yu void destroy_extent_cache(void); 2032a28ef1f5SChao Yu 2033a28ef1f5SChao Yu /* 2034cde4de12SJaegeuk Kim * crypto support 2035cde4de12SJaegeuk Kim */ 2036cde4de12SJaegeuk Kim static inline int f2fs_encrypted_inode(struct inode *inode) 2037cde4de12SJaegeuk Kim { 2038cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2039cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2040cde4de12SJaegeuk Kim #else 2041cde4de12SJaegeuk Kim return 0; 2042cde4de12SJaegeuk Kim #endif 2043cde4de12SJaegeuk Kim } 2044cde4de12SJaegeuk Kim 2045cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2046cde4de12SJaegeuk Kim { 2047cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2048cde4de12SJaegeuk Kim file_set_encrypt(inode); 2049cde4de12SJaegeuk Kim #endif 2050cde4de12SJaegeuk Kim } 2051cde4de12SJaegeuk Kim 2052cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2053cde4de12SJaegeuk Kim { 2054cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2055cde4de12SJaegeuk Kim return unlikely(bio->bi_private != NULL); 2056cde4de12SJaegeuk Kim #else 2057cde4de12SJaegeuk Kim return false; 2058cde4de12SJaegeuk Kim #endif 2059cde4de12SJaegeuk Kim } 2060cde4de12SJaegeuk Kim 2061cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2062cde4de12SJaegeuk Kim { 2063cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2064cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2065cde4de12SJaegeuk Kim #else 2066cde4de12SJaegeuk Kim return 0; 2067cde4de12SJaegeuk Kim #endif 2068cde4de12SJaegeuk Kim } 2069f424f664SJaegeuk Kim 2070fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2071fcc85a4dSJaegeuk Kim { 2072fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2073fcc85a4dSJaegeuk Kim mode_t mode = inode->i_mode; 2074fcc85a4dSJaegeuk Kim 2075fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2076fcc85a4dSJaegeuk Kim #else 2077fcc85a4dSJaegeuk Kim return 0; 2078fcc85a4dSJaegeuk Kim #endif 2079fcc85a4dSJaegeuk Kim } 2080fcc85a4dSJaegeuk Kim 2081f424f664SJaegeuk Kim /* crypto_policy.c */ 2082f424f664SJaegeuk Kim int f2fs_is_child_context_consistent_with_parent(struct inode *, 2083f424f664SJaegeuk Kim struct inode *); 2084f424f664SJaegeuk Kim int f2fs_inherit_context(struct inode *, struct inode *, struct page *); 2085f424f664SJaegeuk Kim int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *); 2086f424f664SJaegeuk Kim int f2fs_get_policy(struct inode *, struct f2fs_encryption_policy *); 208757e5055bSJaegeuk Kim 208857e5055bSJaegeuk Kim /* crypt.c */ 20898bacf6deSJaegeuk Kim extern struct kmem_cache *f2fs_crypt_info_cachep; 209057e5055bSJaegeuk Kim bool f2fs_valid_contents_enc_mode(uint32_t); 209157e5055bSJaegeuk Kim uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t); 209257e5055bSJaegeuk Kim struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *); 209357e5055bSJaegeuk Kim void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *); 209457e5055bSJaegeuk Kim struct page *f2fs_encrypt(struct inode *, struct page *); 209557e5055bSJaegeuk Kim int f2fs_decrypt(struct f2fs_crypto_ctx *, struct page *); 209657e5055bSJaegeuk Kim int f2fs_decrypt_one(struct inode *, struct page *); 209757e5055bSJaegeuk Kim void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *); 209857e5055bSJaegeuk Kim 20990adda907SJaegeuk Kim /* crypto_key.c */ 210026bf3dc7SJaegeuk Kim void f2fs_free_encryption_info(struct inode *, struct f2fs_crypt_info *); 21010adda907SJaegeuk Kim int _f2fs_get_encryption_info(struct inode *inode); 21020adda907SJaegeuk Kim 21036b3bd08fSJaegeuk Kim /* crypto_fname.c */ 21046b3bd08fSJaegeuk Kim bool f2fs_valid_filenames_enc_mode(uint32_t); 21056b3bd08fSJaegeuk Kim u32 f2fs_fname_crypto_round_up(u32, u32); 21066b3bd08fSJaegeuk Kim int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *); 21076b3bd08fSJaegeuk Kim int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *, 21086b3bd08fSJaegeuk Kim const struct f2fs_str *, struct f2fs_str *); 21096b3bd08fSJaegeuk Kim int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *, 21106b3bd08fSJaegeuk Kim struct f2fs_str *); 21116b3bd08fSJaegeuk Kim 211257e5055bSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 211357e5055bSJaegeuk Kim void f2fs_restore_and_release_control_page(struct page **); 211457e5055bSJaegeuk Kim void f2fs_restore_control_page(struct page *); 211557e5055bSJaegeuk Kim 2116cfc4d971SJaegeuk Kim int __init f2fs_init_crypto(void); 2117cfc4d971SJaegeuk Kim int f2fs_crypto_initialize(void); 211857e5055bSJaegeuk Kim void f2fs_exit_crypto(void); 21190adda907SJaegeuk Kim 21200adda907SJaegeuk Kim int f2fs_has_encryption_key(struct inode *); 21210adda907SJaegeuk Kim 21220adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *inode) 21230adda907SJaegeuk Kim { 21240adda907SJaegeuk Kim struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info; 21250adda907SJaegeuk Kim 21260adda907SJaegeuk Kim if (!ci || 21270adda907SJaegeuk Kim (ci->ci_keyring_key && 21280adda907SJaegeuk Kim (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | 21290adda907SJaegeuk Kim (1 << KEY_FLAG_REVOKED) | 21300adda907SJaegeuk Kim (1 << KEY_FLAG_DEAD))))) 21310adda907SJaegeuk Kim return _f2fs_get_encryption_info(inode); 21320adda907SJaegeuk Kim return 0; 21330adda907SJaegeuk Kim } 21346b3bd08fSJaegeuk Kim 21356b3bd08fSJaegeuk Kim void f2fs_fname_crypto_free_buffer(struct f2fs_str *); 21366b3bd08fSJaegeuk Kim int f2fs_fname_setup_filename(struct inode *, const struct qstr *, 21376b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *); 21386b3bd08fSJaegeuk Kim void f2fs_fname_free_filename(struct f2fs_filename *); 213957e5055bSJaegeuk Kim #else 214057e5055bSJaegeuk Kim static inline void f2fs_restore_and_release_control_page(struct page **p) { } 214157e5055bSJaegeuk Kim static inline void f2fs_restore_control_page(struct page *p) { } 214257e5055bSJaegeuk Kim 2143cfc4d971SJaegeuk Kim static inline int __init f2fs_init_crypto(void) { return 0; } 214457e5055bSJaegeuk Kim static inline void f2fs_exit_crypto(void) { } 21450adda907SJaegeuk Kim 21460adda907SJaegeuk Kim static inline int f2fs_has_encryption_key(struct inode *i) { return 0; } 21470adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *i) { return 0; } 21486b3bd08fSJaegeuk Kim static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { } 21496b3bd08fSJaegeuk Kim 21506b3bd08fSJaegeuk Kim static inline int f2fs_fname_setup_filename(struct inode *dir, 21516b3bd08fSJaegeuk Kim const struct qstr *iname, 21526b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *fname) 21536b3bd08fSJaegeuk Kim { 21546b3bd08fSJaegeuk Kim memset(fname, 0, sizeof(struct f2fs_filename)); 21556b3bd08fSJaegeuk Kim fname->usr_fname = iname; 21566b3bd08fSJaegeuk Kim fname->disk_name.name = (unsigned char *)iname->name; 21576b3bd08fSJaegeuk Kim fname->disk_name.len = iname->len; 21586b3bd08fSJaegeuk Kim return 0; 21596b3bd08fSJaegeuk Kim } 21606b3bd08fSJaegeuk Kim 21616b3bd08fSJaegeuk Kim static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { } 216257e5055bSJaegeuk Kim #endif 216339a53e0cSJaegeuk Kim #endif 2164