10a8165d7SJaegeuk Kim /* 239a53e0cSJaegeuk Kim * fs/f2fs/f2fs.h 339a53e0cSJaegeuk Kim * 439a53e0cSJaegeuk Kim * Copyright (c) 2012 Samsung Electronics Co., Ltd. 539a53e0cSJaegeuk Kim * http://www.samsung.com/ 639a53e0cSJaegeuk Kim * 739a53e0cSJaegeuk Kim * This program is free software; you can redistribute it and/or modify 839a53e0cSJaegeuk Kim * it under the terms of the GNU General Public License version 2 as 939a53e0cSJaegeuk Kim * published by the Free Software Foundation. 1039a53e0cSJaegeuk Kim */ 1139a53e0cSJaegeuk Kim #ifndef _LINUX_F2FS_H 1239a53e0cSJaegeuk Kim #define _LINUX_F2FS_H 1339a53e0cSJaegeuk Kim 1439a53e0cSJaegeuk Kim #include <linux/types.h> 1539a53e0cSJaegeuk Kim #include <linux/page-flags.h> 1639a53e0cSJaegeuk Kim #include <linux/buffer_head.h> 1739a53e0cSJaegeuk Kim #include <linux/slab.h> 1839a53e0cSJaegeuk Kim #include <linux/crc32.h> 1939a53e0cSJaegeuk Kim #include <linux/magic.h> 20c2d715d1SJaegeuk Kim #include <linux/kobject.h> 217bd59381SGu Zheng #include <linux/sched.h> 2239a53e0cSJaegeuk Kim 235d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 249850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 250daaad97SJaegeuk Kim #define f2fs_down_write(x, y) down_write_nest_lock(x, y) 265d56b671SJaegeuk Kim #else 279850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 289850cf4aSJaegeuk Kim do { \ 299850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 309850cf4aSJaegeuk Kim WARN_ON(1); \ 31caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 329850cf4aSJaegeuk Kim } \ 339850cf4aSJaegeuk Kim } while (0) 340daaad97SJaegeuk Kim #define f2fs_down_write(x, y) down_write(x) 355d56b671SJaegeuk Kim #endif 365d56b671SJaegeuk Kim 3739a53e0cSJaegeuk Kim /* 3839a53e0cSJaegeuk Kim * For mount options 3939a53e0cSJaegeuk Kim */ 4039a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 4139a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 4239a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 4339a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 4439a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 4539a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 4639a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 47444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 481001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 4934d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 5034d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 5134d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 52d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 5389672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 5439a53e0cSJaegeuk Kim 5539a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 5639a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 5739a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 5839a53e0cSJaegeuk Kim 5939a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 6039a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 6139a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 6239a53e0cSJaegeuk Kim 63a9841c4dSJaegeuk Kim typedef u32 block_t; /* 64a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 65a9841c4dSJaegeuk Kim * address format, __le32. 66a9841c4dSJaegeuk Kim */ 6739a53e0cSJaegeuk Kim typedef u32 nid_t; 6839a53e0cSJaegeuk Kim 6939a53e0cSJaegeuk Kim struct f2fs_mount_info { 7039a53e0cSJaegeuk Kim unsigned int opt; 7139a53e0cSJaegeuk Kim }; 7239a53e0cSJaegeuk Kim 73cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 74cde4de12SJaegeuk Kim 7576f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 7676f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 7776f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 7876f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) 7976f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 8076f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) 8176f105a2SJaegeuk Kim 827e586fa0SJaegeuk Kim #define CRCPOLY_LE 0xedb88320 837e586fa0SJaegeuk Kim 847e586fa0SJaegeuk Kim static inline __u32 f2fs_crc32(void *buf, size_t len) 8539a53e0cSJaegeuk Kim { 867e586fa0SJaegeuk Kim unsigned char *p = (unsigned char *)buf; 877e586fa0SJaegeuk Kim __u32 crc = F2FS_SUPER_MAGIC; 887e586fa0SJaegeuk Kim int i; 897e586fa0SJaegeuk Kim 907e586fa0SJaegeuk Kim while (len--) { 917e586fa0SJaegeuk Kim crc ^= *p++; 927e586fa0SJaegeuk Kim for (i = 0; i < 8; i++) 937e586fa0SJaegeuk Kim crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); 947e586fa0SJaegeuk Kim } 957e586fa0SJaegeuk Kim return crc; 9639a53e0cSJaegeuk Kim } 9739a53e0cSJaegeuk Kim 987e586fa0SJaegeuk Kim static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size) 9939a53e0cSJaegeuk Kim { 1007e586fa0SJaegeuk Kim return f2fs_crc32(buf, buf_size) == blk_crc; 10139a53e0cSJaegeuk Kim } 10239a53e0cSJaegeuk Kim 10339a53e0cSJaegeuk Kim /* 10439a53e0cSJaegeuk Kim * For checkpoint manager 10539a53e0cSJaegeuk Kim */ 10639a53e0cSJaegeuk Kim enum { 10739a53e0cSJaegeuk Kim NAT_BITMAP, 10839a53e0cSJaegeuk Kim SIT_BITMAP 10939a53e0cSJaegeuk Kim }; 11039a53e0cSJaegeuk Kim 11175ab4cb8SJaegeuk Kim enum { 11275ab4cb8SJaegeuk Kim CP_UMOUNT, 113119ee914SJaegeuk Kim CP_FASTBOOT, 11475ab4cb8SJaegeuk Kim CP_SYNC, 11510027551SJaegeuk Kim CP_RECOVERY, 1164b2fecc8SJaegeuk Kim CP_DISCARD, 11775ab4cb8SJaegeuk Kim }; 11875ab4cb8SJaegeuk Kim 119bba681cbSJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 32 120bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 121bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 122a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 123a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 124bba681cbSJaegeuk Kim 12575ab4cb8SJaegeuk Kim struct cp_control { 12675ab4cb8SJaegeuk Kim int reason; 1274b2fecc8SJaegeuk Kim __u64 trim_start; 1284b2fecc8SJaegeuk Kim __u64 trim_end; 1294b2fecc8SJaegeuk Kim __u64 trim_minlen; 1304b2fecc8SJaegeuk Kim __u64 trimmed; 13175ab4cb8SJaegeuk Kim }; 13275ab4cb8SJaegeuk Kim 133662befdaSChao Yu /* 13481c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 135662befdaSChao Yu */ 136662befdaSChao Yu enum { 137662befdaSChao Yu META_CP, 138662befdaSChao Yu META_NAT, 13981c1a0f1SChao Yu META_SIT, 1404c521f49SJaegeuk Kim META_SSA, 1414c521f49SJaegeuk Kim META_POR, 142662befdaSChao Yu }; 143662befdaSChao Yu 1446451e041SJaegeuk Kim /* for the list of ino */ 1456451e041SJaegeuk Kim enum { 1466451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 147fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 148fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1496451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1506451e041SJaegeuk Kim }; 1516451e041SJaegeuk Kim 1526451e041SJaegeuk Kim struct ino_entry { 15339a53e0cSJaegeuk Kim struct list_head list; /* list head */ 15439a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 15539a53e0cSJaegeuk Kim }; 15639a53e0cSJaegeuk Kim 15706292073SChao Yu /* 15806292073SChao Yu * for the list of directory inodes or gc inodes. 15906292073SChao Yu * NOTE: there are two slab users for this structure, if we add/modify/delete 16006292073SChao Yu * fields in structure for one of slab users, it may affect fields or size of 16106292073SChao Yu * other one, in this condition, it's better to split both of slab and related 16206292073SChao Yu * data structure. 16306292073SChao Yu */ 16406292073SChao Yu struct inode_entry { 16539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 16639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 16739a53e0cSJaegeuk Kim }; 16839a53e0cSJaegeuk Kim 1697fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1707fd9e544SJaegeuk Kim struct discard_entry { 1717fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1727fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1737fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1747fd9e544SJaegeuk Kim }; 1757fd9e544SJaegeuk Kim 17639a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 17739a53e0cSJaegeuk Kim struct fsync_inode_entry { 17839a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17939a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 180c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 181c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 182c52e1b10SJaegeuk Kim block_t last_inode; /* block address locating the last inode */ 18339a53e0cSJaegeuk Kim }; 18439a53e0cSJaegeuk Kim 18539a53e0cSJaegeuk Kim #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats)) 18639a53e0cSJaegeuk Kim #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits)) 18739a53e0cSJaegeuk Kim 18839a53e0cSJaegeuk Kim #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne) 18939a53e0cSJaegeuk Kim #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid) 19039a53e0cSJaegeuk Kim #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se) 19139a53e0cSJaegeuk Kim #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno) 19239a53e0cSJaegeuk Kim 193309cc2b6SJaegeuk Kim #define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum)) 194309cc2b6SJaegeuk Kim #define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum)) 195309cc2b6SJaegeuk Kim 19639a53e0cSJaegeuk Kim static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i) 19739a53e0cSJaegeuk Kim { 19839a53e0cSJaegeuk Kim int before = nats_in_cursum(rs); 19939a53e0cSJaegeuk Kim rs->n_nats = cpu_to_le16(before + i); 20039a53e0cSJaegeuk Kim return before; 20139a53e0cSJaegeuk Kim } 20239a53e0cSJaegeuk Kim 20339a53e0cSJaegeuk Kim static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i) 20439a53e0cSJaegeuk Kim { 20539a53e0cSJaegeuk Kim int before = sits_in_cursum(rs); 20639a53e0cSJaegeuk Kim rs->n_sits = cpu_to_le16(before + i); 20739a53e0cSJaegeuk Kim return before; 20839a53e0cSJaegeuk Kim } 20939a53e0cSJaegeuk Kim 210184a5cd2SChao Yu static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size, 211184a5cd2SChao Yu int type) 212184a5cd2SChao Yu { 213184a5cd2SChao Yu if (type == NAT_JOURNAL) 214309cc2b6SJaegeuk Kim return size <= MAX_NAT_JENTRIES(sum); 215309cc2b6SJaegeuk Kim return size <= MAX_SIT_JENTRIES(sum); 216184a5cd2SChao Yu } 217184a5cd2SChao Yu 21839a53e0cSJaegeuk Kim /* 219e9750824SNamjae Jeon * ioctl commands 220e9750824SNamjae Jeon */ 221e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 222e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 223d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 224e9750824SNamjae Jeon 22588b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 22688b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 22788b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 22802a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2291e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2301e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 23188b88a66SJaegeuk Kim 232f424f664SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY \ 233f424f664SJaegeuk Kim _IOR('f', 19, struct f2fs_encryption_policy) 234f424f664SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT \ 235f424f664SJaegeuk Kim _IOW('f', 20, __u8[16]) 236f424f664SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY \ 237f424f664SJaegeuk Kim _IOW('f', 21, struct f2fs_encryption_policy) 238f424f664SJaegeuk Kim 2391abff93dSJaegeuk Kim /* 2401abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2411abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2421abff93dSJaegeuk Kim */ 2431abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2441abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2451abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2461abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 2471abff93dSJaegeuk Kim 248e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 249e9750824SNamjae Jeon /* 250e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 251e9750824SNamjae Jeon */ 252e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 253e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 254e9750824SNamjae Jeon #endif 255e9750824SNamjae Jeon 256e9750824SNamjae Jeon /* 25739a53e0cSJaegeuk Kim * For INODE and NODE manager 25839a53e0cSJaegeuk Kim */ 2597b3cd7d6SJaegeuk Kim /* for directory operations */ 2606b3bd08fSJaegeuk Kim struct f2fs_str { 2616b3bd08fSJaegeuk Kim unsigned char *name; 2626b3bd08fSJaegeuk Kim u32 len; 2636b3bd08fSJaegeuk Kim }; 2646b3bd08fSJaegeuk Kim 2656b3bd08fSJaegeuk Kim struct f2fs_filename { 2666b3bd08fSJaegeuk Kim const struct qstr *usr_fname; 2676b3bd08fSJaegeuk Kim struct f2fs_str disk_name; 2686b3bd08fSJaegeuk Kim f2fs_hash_t hash; 2696b3bd08fSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2706b3bd08fSJaegeuk Kim struct f2fs_str crypto_buf; 2716b3bd08fSJaegeuk Kim #endif 2726b3bd08fSJaegeuk Kim }; 2736b3bd08fSJaegeuk Kim 2746b3bd08fSJaegeuk Kim #define FSTR_INIT(n, l) { .name = n, .len = l } 2756b3bd08fSJaegeuk Kim #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len) 2766b3bd08fSJaegeuk Kim #define fname_name(p) ((p)->disk_name.name) 2776b3bd08fSJaegeuk Kim #define fname_len(p) ((p)->disk_name.len) 2786b3bd08fSJaegeuk Kim 2797b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 280*d8c6822aSJaegeuk Kim struct inode *inode; 2817b3cd7d6SJaegeuk Kim const void *bitmap; 2827b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 2837b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 2847b3cd7d6SJaegeuk Kim int max; 2857b3cd7d6SJaegeuk Kim }; 2867b3cd7d6SJaegeuk Kim 287*d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode, 288*d8c6822aSJaegeuk Kim struct f2fs_dentry_ptr *d, void *src, int type) 2897b3cd7d6SJaegeuk Kim { 290*d8c6822aSJaegeuk Kim d->inode = inode; 291*d8c6822aSJaegeuk Kim 2927b3cd7d6SJaegeuk Kim if (type == 1) { 2937b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 2947b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 2957b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2967b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 2977b3cd7d6SJaegeuk Kim d->filename = t->filename; 2987b3cd7d6SJaegeuk Kim } else { 2997b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 3007b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3017b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3027b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3037b3cd7d6SJaegeuk Kim d->filename = t->filename; 3047b3cd7d6SJaegeuk Kim } 3057b3cd7d6SJaegeuk Kim } 3067b3cd7d6SJaegeuk Kim 307dbe6a5ffSJaegeuk Kim /* 308dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 309dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 310dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 31139a53e0cSJaegeuk Kim */ 312dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 313dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 314266e97a8SJaegeuk Kim enum { 315266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 316266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 317266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 318266e97a8SJaegeuk Kim * look up a node with readahead called 3194f4124d0SChao Yu * by get_data_block. 32039a53e0cSJaegeuk Kim */ 321266e97a8SJaegeuk Kim }; 322266e97a8SJaegeuk Kim 32339a53e0cSJaegeuk Kim #define F2FS_LINK_MAX 32000 /* maximum link count per file */ 32439a53e0cSJaegeuk Kim 325817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 326817202d9SChao Yu 32713054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 32813054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 32913054c54SChao Yu 33039a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 33113054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 33213054c54SChao Yu 33313054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 33413054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 335c11abd1aSJaegeuk Kim 33639a53e0cSJaegeuk Kim struct extent_info { 33739a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3384d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 339111d2495SMasanari Iida unsigned int len; /* length of the extent */ 34039a53e0cSJaegeuk Kim }; 34139a53e0cSJaegeuk Kim 34213054c54SChao Yu struct extent_node { 34313054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 34413054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 34513054c54SChao Yu struct extent_info ei; /* extent info */ 34613054c54SChao Yu }; 34713054c54SChao Yu 34813054c54SChao Yu struct extent_tree { 34913054c54SChao Yu nid_t ino; /* inode number */ 35013054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 35162c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 35213054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 35313054c54SChao Yu atomic_t refcount; /* reference count of rb-tree */ 35413054c54SChao Yu unsigned int count; /* # of extent node in rb-tree*/ 35513054c54SChao Yu }; 35613054c54SChao Yu 35739a53e0cSJaegeuk Kim /* 358003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 359003a3e1dSJaegeuk Kim * 360003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 361003a3e1dSJaegeuk Kim */ 362003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 363003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 3647f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 3657f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 3667f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 367003a3e1dSJaegeuk Kim 368003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 369003a3e1dSJaegeuk Kim block_t m_pblk; 370003a3e1dSJaegeuk Kim block_t m_lblk; 371003a3e1dSJaegeuk Kim unsigned int m_len; 372003a3e1dSJaegeuk Kim unsigned int m_flags; 373003a3e1dSJaegeuk Kim }; 374003a3e1dSJaegeuk Kim 375003a3e1dSJaegeuk Kim /* 37639a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 37739a53e0cSJaegeuk Kim */ 37839a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 379354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 380cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 38139a53e0cSJaegeuk Kim 382b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 383b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 384b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 385b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 386b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 387b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 388cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 389cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 390cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 391cde4de12SJaegeuk Kim 392cde4de12SJaegeuk Kim /* Encryption algorithms */ 393cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_INVALID 0 394cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_XTS 1 395cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_GCM 2 396cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CBC 3 397cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CTS 4 398b5492af7SJaegeuk Kim 399f424f664SJaegeuk Kim #include "f2fs_crypto.h" 400f424f664SJaegeuk Kim 401ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 402ab9fa662SJaegeuk Kim 40339a53e0cSJaegeuk Kim struct f2fs_inode_info { 40439a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 40539a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 40639a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 40738431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 40839a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4096666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 41039a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 41139a53e0cSJaegeuk Kim 41239a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 41339a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 414d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 415a7ffdbe2SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 41639a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 41739a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 41839a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 419e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 42039a53e0cSJaegeuk Kim struct extent_info ext; /* in-memory extent cache entry */ 4210c872e2dSChao Yu rwlock_t ext_lock; /* rwlock for single extent cache */ 42206292073SChao Yu struct inode_entry *dirty_dir; /* the pointer of dirty dir */ 42388b88a66SJaegeuk Kim 42434ba94baSJaegeuk Kim struct radix_tree_root inmem_root; /* radix tree for inmem pages */ 42588b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 42688b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 427cde4de12SJaegeuk Kim 428cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 429cde4de12SJaegeuk Kim /* Encryption params */ 430cde4de12SJaegeuk Kim struct f2fs_crypt_info *i_crypt_info; 431cde4de12SJaegeuk Kim #endif 43239a53e0cSJaegeuk Kim }; 43339a53e0cSJaegeuk Kim 43439a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 43539a53e0cSJaegeuk Kim struct f2fs_extent i_ext) 43639a53e0cSJaegeuk Kim { 43739a53e0cSJaegeuk Kim ext->fofs = le32_to_cpu(i_ext.fofs); 4384d0b0bd4SChao Yu ext->blk = le32_to_cpu(i_ext.blk); 43939a53e0cSJaegeuk Kim ext->len = le32_to_cpu(i_ext.len); 44039a53e0cSJaegeuk Kim } 44139a53e0cSJaegeuk Kim 44239a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 44339a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 44439a53e0cSJaegeuk Kim { 44539a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4464d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 44739a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 44839a53e0cSJaegeuk Kim } 44939a53e0cSJaegeuk Kim 450429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 451429511cdSChao Yu u32 blk, unsigned int len) 452429511cdSChao Yu { 453429511cdSChao Yu ei->fofs = fofs; 454429511cdSChao Yu ei->blk = blk; 455429511cdSChao Yu ei->len = len; 456429511cdSChao Yu } 457429511cdSChao Yu 4580bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1, 4590bdee482SChao Yu struct extent_info *ei2) 4600bdee482SChao Yu { 4610bdee482SChao Yu return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 4620bdee482SChao Yu ei1->len == ei2->len); 4630bdee482SChao Yu } 4640bdee482SChao Yu 465429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 466429511cdSChao Yu struct extent_info *front) 467429511cdSChao Yu { 468429511cdSChao Yu return (back->fofs + back->len == front->fofs && 469429511cdSChao Yu back->blk + back->len == front->blk); 470429511cdSChao Yu } 471429511cdSChao Yu 472429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 473429511cdSChao Yu struct extent_info *back) 474429511cdSChao Yu { 475429511cdSChao Yu return __is_extent_mergeable(back, cur); 476429511cdSChao Yu } 477429511cdSChao Yu 478429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 479429511cdSChao Yu struct extent_info *front) 480429511cdSChao Yu { 481429511cdSChao Yu return __is_extent_mergeable(cur, front); 482429511cdSChao Yu } 483429511cdSChao Yu 48439a53e0cSJaegeuk Kim struct f2fs_nm_info { 48539a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 48639a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 4877ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 48839a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 489cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 49039a53e0cSJaegeuk Kim 49139a53e0cSJaegeuk Kim /* NAT cache management */ 49239a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 493309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 4948b26ef98SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 49539a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 496309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 497aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 49839a53e0cSJaegeuk Kim 49939a53e0cSJaegeuk Kim /* free node ids management */ 5008a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 50139a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 50239a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 50339a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 50439a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 50539a53e0cSJaegeuk Kim 50639a53e0cSJaegeuk Kim /* for checkpoint */ 50739a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 50839a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 50939a53e0cSJaegeuk Kim }; 51039a53e0cSJaegeuk Kim 51139a53e0cSJaegeuk Kim /* 51239a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 51339a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 51439a53e0cSJaegeuk Kim * by the data offset in a file. 51539a53e0cSJaegeuk Kim */ 51639a53e0cSJaegeuk Kim struct dnode_of_data { 51739a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 51839a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 51939a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 52039a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 52139a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 52239a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 52339a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 52439a53e0cSJaegeuk Kim }; 52539a53e0cSJaegeuk Kim 52639a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 52739a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 52839a53e0cSJaegeuk Kim { 529d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 53039a53e0cSJaegeuk Kim dn->inode = inode; 53139a53e0cSJaegeuk Kim dn->inode_page = ipage; 53239a53e0cSJaegeuk Kim dn->node_page = npage; 53339a53e0cSJaegeuk Kim dn->nid = nid; 53439a53e0cSJaegeuk Kim } 53539a53e0cSJaegeuk Kim 53639a53e0cSJaegeuk Kim /* 53739a53e0cSJaegeuk Kim * For SIT manager 53839a53e0cSJaegeuk Kim * 53939a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 54039a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 54139a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 54239a53e0cSJaegeuk Kim * respectively. 54339a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 54439a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 54539a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 54639a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 54739a53e0cSJaegeuk Kim * data and 8 for node logs. 54839a53e0cSJaegeuk Kim */ 54939a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 55039a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 55139a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 55239a53e0cSJaegeuk Kim 55339a53e0cSJaegeuk Kim enum { 55439a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 55539a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 55639a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 55739a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 55839a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 55939a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 56038aa0889SJaegeuk Kim NO_CHECK_TYPE, 56138aa0889SJaegeuk Kim CURSEG_DIRECT_IO, /* to use for the direct IO path */ 56239a53e0cSJaegeuk Kim }; 56339a53e0cSJaegeuk Kim 5646b4afdd7SJaegeuk Kim struct flush_cmd { 5656b4afdd7SJaegeuk Kim struct completion wait; 566721bd4d5SGu Zheng struct llist_node llnode; 5676b4afdd7SJaegeuk Kim int ret; 5686b4afdd7SJaegeuk Kim }; 5696b4afdd7SJaegeuk Kim 570a688b9d9SGu Zheng struct flush_cmd_control { 571a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 572a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 573721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 574721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 575a688b9d9SGu Zheng }; 576a688b9d9SGu Zheng 57739a53e0cSJaegeuk Kim struct f2fs_sm_info { 57839a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 57939a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 58039a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 58139a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 58239a53e0cSJaegeuk Kim 58339a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 58439a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 58539a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 58639a53e0cSJaegeuk Kim 58739a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 58839a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 58939a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 59039a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 59181eb8d6eSJaegeuk Kim 59281eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 59381eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 5947fd9e544SJaegeuk Kim 5957fd9e544SJaegeuk Kim /* for small discard management */ 5967fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 5977fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 5987fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 599216fbd64SJaegeuk Kim 600bba681cbSJaegeuk Kim /* for batched trimming */ 601bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 602bba681cbSJaegeuk Kim 603184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 604184a5cd2SChao Yu 605216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 606216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 607c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 6086b4afdd7SJaegeuk Kim 6096b4afdd7SJaegeuk Kim /* for flush command control */ 610a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 611a688b9d9SGu Zheng 61239a53e0cSJaegeuk Kim }; 61339a53e0cSJaegeuk Kim 61439a53e0cSJaegeuk Kim /* 61539a53e0cSJaegeuk Kim * For superblock 61639a53e0cSJaegeuk Kim */ 61739a53e0cSJaegeuk Kim /* 61839a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 61939a53e0cSJaegeuk Kim * 62039a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 62139a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 62239a53e0cSJaegeuk Kim */ 62339a53e0cSJaegeuk Kim enum count_type { 62439a53e0cSJaegeuk Kim F2FS_WRITEBACK, 62539a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 62639a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 62739a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6288dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 62939a53e0cSJaegeuk Kim NR_COUNT_TYPE, 63039a53e0cSJaegeuk Kim }; 63139a53e0cSJaegeuk Kim 63239a53e0cSJaegeuk Kim /* 633e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 63439a53e0cSJaegeuk Kim * The available types are: 63539a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 63639a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 63739a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 63839a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 63939a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 64039a53e0cSJaegeuk Kim * with waiting the bio's completion 64139a53e0cSJaegeuk Kim * ... Only can be used with META. 64239a53e0cSJaegeuk Kim */ 6437d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 64439a53e0cSJaegeuk Kim enum page_type { 64539a53e0cSJaegeuk Kim DATA, 64639a53e0cSJaegeuk Kim NODE, 64739a53e0cSJaegeuk Kim META, 64839a53e0cSJaegeuk Kim NR_PAGE_TYPE, 64939a53e0cSJaegeuk Kim META_FLUSH, 6508ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 6518ce67cb0SJaegeuk Kim INMEM_DROP, 6528ce67cb0SJaegeuk Kim IPU, 6538ce67cb0SJaegeuk Kim OPU, 65439a53e0cSJaegeuk Kim }; 65539a53e0cSJaegeuk Kim 656458e6197SJaegeuk Kim struct f2fs_io_info { 65705ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 658458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 6597e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 660cf04e8ebSJaegeuk Kim block_t blk_addr; /* block address to be written */ 66105ca3632SJaegeuk Kim struct page *page; /* page to be written */ 6624375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 663458e6197SJaegeuk Kim }; 664458e6197SJaegeuk Kim 66593dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 6661ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 667458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 6681ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 6691ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 670458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 671df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 6721ff7bd3bSJaegeuk Kim }; 6731ff7bd3bSJaegeuk Kim 67467298804SChao Yu /* for inner inode cache management */ 67567298804SChao Yu struct inode_management { 67667298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 67767298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 67867298804SChao Yu struct list_head ino_list; /* inode list head */ 67967298804SChao Yu unsigned long ino_num; /* number of entries */ 68067298804SChao Yu }; 68167298804SChao Yu 682caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 683caf0047eSChao Yu enum { 684caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 685caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 686caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 687caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 688caf0047eSChao Yu }; 689caf0047eSChao Yu 69039a53e0cSJaegeuk Kim struct f2fs_sb_info { 69139a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 6925e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 69339a53e0cSJaegeuk Kim struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 69439a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 695caf0047eSChao Yu int s_flag; /* flags for sbi */ 69639a53e0cSJaegeuk Kim 69739a53e0cSJaegeuk Kim /* for node-related operations */ 69839a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 69939a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 70039a53e0cSJaegeuk Kim 70139a53e0cSJaegeuk Kim /* for segment-related operations */ 70239a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 7031ff7bd3bSJaegeuk Kim 7041ff7bd3bSJaegeuk Kim /* for bio operations */ 705924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 7061ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 70739a53e0cSJaegeuk Kim 70839a53e0cSJaegeuk Kim /* for checkpoint */ 70939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 71039a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 71139936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 712e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 713b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 7145463e7c1SJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 715fb51b5efSChangman Lee wait_queue_head_t cp_wait; 71639a53e0cSJaegeuk Kim 71767298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 7186451e041SJaegeuk Kim 7196451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 7200d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 72139a53e0cSJaegeuk Kim 72239a53e0cSJaegeuk Kim /* for directory inode management */ 72339a53e0cSJaegeuk Kim struct list_head dir_inode_list; /* dir inode list */ 72439a53e0cSJaegeuk Kim spinlock_t dir_inode_lock; /* for dir inode list lock */ 72539a53e0cSJaegeuk Kim 72613054c54SChao Yu /* for extent tree cache */ 72713054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 72813054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 72913054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 73013054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 73113054c54SChao Yu int total_ext_tree; /* extent tree count */ 73213054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 73313054c54SChao Yu 73439a53e0cSJaegeuk Kim /* basic filesystem units */ 73539a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 73639a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 73739a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 73839a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 73939a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 74039a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 74139a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 74239a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 74339a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 74439a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 74539a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 74639a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 74739a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 74839a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 74939a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 750ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 75139a53e0cSJaegeuk Kim 75239a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 75339a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 75439a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 755a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 75639a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 75739a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 75839a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 75939a53e0cSJaegeuk Kim 76039a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 76139a53e0cSJaegeuk Kim 76239a53e0cSJaegeuk Kim /* for cleaning operations */ 76339a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 76439a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 7655ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 76639a53e0cSJaegeuk Kim 767b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 768b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 769b1c57c1cSJaegeuk Kim 77039a53e0cSJaegeuk Kim /* 77139a53e0cSJaegeuk Kim * for stat information. 77239a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 77339a53e0cSJaegeuk Kim */ 77435b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 77539a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 77639a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 77739a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 778b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 77939a53e0cSJaegeuk Kim int total_hit_ext, read_hit_ext; /* extent cache hit ratio */ 78003e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 78103e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 78239a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 78335b09d82SNamjae Jeon unsigned int n_dirty_dirs; /* # of dir inodes */ 78435b09d82SNamjae Jeon #endif 78535b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 78639a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 787b59d0baeSNamjae Jeon 788b59d0baeSNamjae Jeon /* For sysfs suppport */ 789b59d0baeSNamjae Jeon struct kobject s_kobj; 790b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 79139a53e0cSJaegeuk Kim }; 79239a53e0cSJaegeuk Kim 79339a53e0cSJaegeuk Kim /* 79439a53e0cSJaegeuk Kim * Inline functions 79539a53e0cSJaegeuk Kim */ 79639a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 79739a53e0cSJaegeuk Kim { 79839a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 79939a53e0cSJaegeuk Kim } 80039a53e0cSJaegeuk Kim 80139a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 80239a53e0cSJaegeuk Kim { 80339a53e0cSJaegeuk Kim return sb->s_fs_info; 80439a53e0cSJaegeuk Kim } 80539a53e0cSJaegeuk Kim 8064081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 8074081363fSJaegeuk Kim { 8084081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 8094081363fSJaegeuk Kim } 8104081363fSJaegeuk Kim 8114081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 8124081363fSJaegeuk Kim { 8134081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 8144081363fSJaegeuk Kim } 8154081363fSJaegeuk Kim 8164081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 8174081363fSJaegeuk Kim { 8184081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 8194081363fSJaegeuk Kim } 8204081363fSJaegeuk Kim 82139a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 82239a53e0cSJaegeuk Kim { 82339a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 82439a53e0cSJaegeuk Kim } 82539a53e0cSJaegeuk Kim 82639a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 82739a53e0cSJaegeuk Kim { 82839a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 82939a53e0cSJaegeuk Kim } 83039a53e0cSJaegeuk Kim 83145590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 83245590710SGu Zheng { 83345590710SGu Zheng return (struct f2fs_node *)page_address(page); 83445590710SGu Zheng } 83545590710SGu Zheng 83658bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 83758bfaf44SJaegeuk Kim { 83858bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 83958bfaf44SJaegeuk Kim } 84058bfaf44SJaegeuk Kim 84139a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 84239a53e0cSJaegeuk Kim { 84339a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 84439a53e0cSJaegeuk Kim } 84539a53e0cSJaegeuk Kim 84639a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 84739a53e0cSJaegeuk Kim { 84839a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 84939a53e0cSJaegeuk Kim } 85039a53e0cSJaegeuk Kim 85139a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 85239a53e0cSJaegeuk Kim { 85339a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 85439a53e0cSJaegeuk Kim } 85539a53e0cSJaegeuk Kim 85639a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 85739a53e0cSJaegeuk Kim { 85839a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 85939a53e0cSJaegeuk Kim } 86039a53e0cSJaegeuk Kim 86139a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 86239a53e0cSJaegeuk Kim { 86339a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 86439a53e0cSJaegeuk Kim } 86539a53e0cSJaegeuk Kim 8669df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 8679df27d98SGu Zheng { 8689df27d98SGu Zheng return sbi->meta_inode->i_mapping; 8699df27d98SGu Zheng } 8709df27d98SGu Zheng 8714ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 8724ef51a8fSJaegeuk Kim { 8734ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 8744ef51a8fSJaegeuk Kim } 8754ef51a8fSJaegeuk Kim 876caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 87739a53e0cSJaegeuk Kim { 878caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 87939a53e0cSJaegeuk Kim } 88039a53e0cSJaegeuk Kim 881caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 88239a53e0cSJaegeuk Kim { 883caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 884caf0047eSChao Yu } 885caf0047eSChao Yu 886caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 887caf0047eSChao Yu { 888caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 88939a53e0cSJaegeuk Kim } 89039a53e0cSJaegeuk Kim 891d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 892d71b5564SJaegeuk Kim { 893d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 894d71b5564SJaegeuk Kim } 895d71b5564SJaegeuk Kim 89625ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 89725ca923bSJaegeuk Kim { 89825ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 89925ca923bSJaegeuk Kim return ckpt_flags & f; 90025ca923bSJaegeuk Kim } 90125ca923bSJaegeuk Kim 90225ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 90325ca923bSJaegeuk Kim { 90425ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 90525ca923bSJaegeuk Kim ckpt_flags |= f; 90625ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 90725ca923bSJaegeuk Kim } 90825ca923bSJaegeuk Kim 90925ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 91025ca923bSJaegeuk Kim { 91125ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 91225ca923bSJaegeuk Kim ckpt_flags &= (~f); 91325ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 91425ca923bSJaegeuk Kim } 91525ca923bSJaegeuk Kim 916e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 91739a53e0cSJaegeuk Kim { 918e479556bSGu Zheng down_read(&sbi->cp_rwsem); 91939a53e0cSJaegeuk Kim } 92039a53e0cSJaegeuk Kim 921e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 92239a53e0cSJaegeuk Kim { 923e479556bSGu Zheng up_read(&sbi->cp_rwsem); 92439936837SJaegeuk Kim } 92539936837SJaegeuk Kim 926e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 92739936837SJaegeuk Kim { 9280daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 92939936837SJaegeuk Kim } 93039936837SJaegeuk Kim 931e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 93239936837SJaegeuk Kim { 933e479556bSGu Zheng up_write(&sbi->cp_rwsem); 93439a53e0cSJaegeuk Kim } 93539a53e0cSJaegeuk Kim 936119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 937119ee914SJaegeuk Kim { 938119ee914SJaegeuk Kim int reason = CP_SYNC; 939119ee914SJaegeuk Kim 940119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 941119ee914SJaegeuk Kim reason = CP_FASTBOOT; 942119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 943119ee914SJaegeuk Kim reason = CP_UMOUNT; 944119ee914SJaegeuk Kim return reason; 945119ee914SJaegeuk Kim } 946119ee914SJaegeuk Kim 947119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 948119ee914SJaegeuk Kim { 949119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 950119ee914SJaegeuk Kim } 951119ee914SJaegeuk Kim 952119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 953119ee914SJaegeuk Kim { 954119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 955119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 956119ee914SJaegeuk Kim } 957119ee914SJaegeuk Kim 95839a53e0cSJaegeuk Kim /* 95939a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 96039a53e0cSJaegeuk Kim */ 961064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 96239a53e0cSJaegeuk Kim { 963d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 964d6b7d4b3SChao Yu return -EINVAL; 965cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 966064e0823SNamjae Jeon return -EINVAL; 967064e0823SNamjae Jeon return 0; 96839a53e0cSJaegeuk Kim } 96939a53e0cSJaegeuk Kim 97039a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 97139a53e0cSJaegeuk Kim 97239a53e0cSJaegeuk Kim /* 97339a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 97439a53e0cSJaegeuk Kim */ 97539a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 97639a53e0cSJaegeuk Kim { 97739a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 9786c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 97939a53e0cSJaegeuk Kim else 9806c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 98139a53e0cSJaegeuk Kim } 98239a53e0cSJaegeuk Kim 9834bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 9844bc8e9bcSChao Yu { 9854bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 9864bc8e9bcSChao Yu } 9874bc8e9bcSChao Yu 98839a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 98939a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 99039a53e0cSJaegeuk Kim { 99139a53e0cSJaegeuk Kim block_t valid_block_count; 99239a53e0cSJaegeuk Kim 99339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 99439a53e0cSJaegeuk Kim valid_block_count = 99539a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 996cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 99739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 99839a53e0cSJaegeuk Kim return false; 99939a53e0cSJaegeuk Kim } 100039a53e0cSJaegeuk Kim inode->i_blocks += count; 100139a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 100239a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 100339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 100439a53e0cSJaegeuk Kim return true; 100539a53e0cSJaegeuk Kim } 100639a53e0cSJaegeuk Kim 1007da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 100839a53e0cSJaegeuk Kim struct inode *inode, 100939a53e0cSJaegeuk Kim blkcnt_t count) 101039a53e0cSJaegeuk Kim { 101139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 10129850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 10139850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 101439a53e0cSJaegeuk Kim inode->i_blocks -= count; 101539a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 101639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 101739a53e0cSJaegeuk Kim } 101839a53e0cSJaegeuk Kim 101939a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 102039a53e0cSJaegeuk Kim { 102139a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 1022caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 102339a53e0cSJaegeuk Kim } 102439a53e0cSJaegeuk Kim 1025a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 102639a53e0cSJaegeuk Kim { 1027a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1028a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10294081363fSJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 103039a53e0cSJaegeuk Kim } 103139a53e0cSJaegeuk Kim 103239a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 103339a53e0cSJaegeuk Kim { 103439a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 103539a53e0cSJaegeuk Kim } 103639a53e0cSJaegeuk Kim 1037a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 103839a53e0cSJaegeuk Kim { 1039a7ffdbe2SJaegeuk Kim if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)) 10401fe54f9dSJaegeuk Kim return; 10411fe54f9dSJaegeuk Kim 1042a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1043a7ffdbe2SJaegeuk Kim 1044a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10454081363fSJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 104639a53e0cSJaegeuk Kim } 104739a53e0cSJaegeuk Kim 104839a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 104939a53e0cSJaegeuk Kim { 105039a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 105139a53e0cSJaegeuk Kim } 105239a53e0cSJaegeuk Kim 1053a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1054f8b2c1f9SJaegeuk Kim { 1055a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1056f8b2c1f9SJaegeuk Kim } 1057f8b2c1f9SJaegeuk Kim 10585ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 10595ac206cfSNamjae Jeon { 10605ac206cfSNamjae Jeon unsigned int pages_per_sec = sbi->segs_per_sec * 10615ac206cfSNamjae Jeon (1 << sbi->log_blocks_per_seg); 10625ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 10635ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 10645ac206cfSNamjae Jeon } 10655ac206cfSNamjae Jeon 106639a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 106739a53e0cSJaegeuk Kim { 10688b8343faSJaegeuk Kim return sbi->total_valid_block_count; 106939a53e0cSJaegeuk Kim } 107039a53e0cSJaegeuk Kim 107139a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 107239a53e0cSJaegeuk Kim { 107339a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 107439a53e0cSJaegeuk Kim 107539a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 107639a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 107739a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 107839a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 107939a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 108039a53e0cSJaegeuk Kim 108139a53e0cSJaegeuk Kim return 0; 108239a53e0cSJaegeuk Kim } 108339a53e0cSJaegeuk Kim 108455141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 108555141486SWanpeng Li { 108655141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 108755141486SWanpeng Li } 108855141486SWanpeng Li 108939a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 109039a53e0cSJaegeuk Kim { 109139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 10921dbe4152SChangman Lee int offset; 10931dbe4152SChangman Lee 109455141486SWanpeng Li if (__cp_payload(sbi) > 0) { 10951dbe4152SChangman Lee if (flag == NAT_BITMAP) 10961dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 10971dbe4152SChangman Lee else 109865b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 10991dbe4152SChangman Lee } else { 11001dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 110125ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 110239a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 110339a53e0cSJaegeuk Kim } 11041dbe4152SChangman Lee } 110539a53e0cSJaegeuk Kim 110639a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 110739a53e0cSJaegeuk Kim { 110839a53e0cSJaegeuk Kim block_t start_addr; 110939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1110d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 111139a53e0cSJaegeuk Kim 111225ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 111339a53e0cSJaegeuk Kim 111439a53e0cSJaegeuk Kim /* 111539a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1116e1c42045Sarter97 * and even segment must be at cp segment 1 111739a53e0cSJaegeuk Kim */ 111839a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 111939a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 112039a53e0cSJaegeuk Kim 112139a53e0cSJaegeuk Kim return start_addr; 112239a53e0cSJaegeuk Kim } 112339a53e0cSJaegeuk Kim 112439a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 112539a53e0cSJaegeuk Kim { 112639a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 112739a53e0cSJaegeuk Kim } 112839a53e0cSJaegeuk Kim 112939a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1130ef86d709SGu Zheng struct inode *inode) 113139a53e0cSJaegeuk Kim { 113239a53e0cSJaegeuk Kim block_t valid_block_count; 113339a53e0cSJaegeuk Kim unsigned int valid_node_count; 113439a53e0cSJaegeuk Kim 113539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 113639a53e0cSJaegeuk Kim 1137ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1138cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 113939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 114039a53e0cSJaegeuk Kim return false; 114139a53e0cSJaegeuk Kim } 114239a53e0cSJaegeuk Kim 1143ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1144cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 114539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 114639a53e0cSJaegeuk Kim return false; 114739a53e0cSJaegeuk Kim } 114839a53e0cSJaegeuk Kim 114939a53e0cSJaegeuk Kim if (inode) 1150ef86d709SGu Zheng inode->i_blocks++; 1151ef86d709SGu Zheng 1152ef86d709SGu Zheng sbi->alloc_valid_block_count++; 1153ef86d709SGu Zheng sbi->total_valid_node_count++; 1154ef86d709SGu Zheng sbi->total_valid_block_count++; 115539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 115639a53e0cSJaegeuk Kim 115739a53e0cSJaegeuk Kim return true; 115839a53e0cSJaegeuk Kim } 115939a53e0cSJaegeuk Kim 116039a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1161ef86d709SGu Zheng struct inode *inode) 116239a53e0cSJaegeuk Kim { 116339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 116439a53e0cSJaegeuk Kim 11659850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 11669850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 11679850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 116839a53e0cSJaegeuk Kim 1169ef86d709SGu Zheng inode->i_blocks--; 1170ef86d709SGu Zheng sbi->total_valid_node_count--; 1171ef86d709SGu Zheng sbi->total_valid_block_count--; 117239a53e0cSJaegeuk Kim 117339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 117439a53e0cSJaegeuk Kim } 117539a53e0cSJaegeuk Kim 117639a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 117739a53e0cSJaegeuk Kim { 11788b8343faSJaegeuk Kim return sbi->total_valid_node_count; 117939a53e0cSJaegeuk Kim } 118039a53e0cSJaegeuk Kim 118139a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 118239a53e0cSJaegeuk Kim { 118339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 11849850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 118539a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 118639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 118739a53e0cSJaegeuk Kim } 118839a53e0cSJaegeuk Kim 11890e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 119039a53e0cSJaegeuk Kim { 119139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 11929850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 119339a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 119439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 119539a53e0cSJaegeuk Kim } 119639a53e0cSJaegeuk Kim 119739a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 119839a53e0cSJaegeuk Kim { 11998b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 120039a53e0cSJaegeuk Kim } 120139a53e0cSJaegeuk Kim 120239a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 120339a53e0cSJaegeuk Kim { 1204031fa8ccSJaegeuk Kim if (!page) 120539a53e0cSJaegeuk Kim return; 120639a53e0cSJaegeuk Kim 120739a53e0cSJaegeuk Kim if (unlock) { 12089850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 120939a53e0cSJaegeuk Kim unlock_page(page); 121039a53e0cSJaegeuk Kim } 121139a53e0cSJaegeuk Kim page_cache_release(page); 121239a53e0cSJaegeuk Kim } 121339a53e0cSJaegeuk Kim 121439a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 121539a53e0cSJaegeuk Kim { 121639a53e0cSJaegeuk Kim if (dn->node_page) 121739a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 121839a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 121939a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 122039a53e0cSJaegeuk Kim dn->node_page = NULL; 122139a53e0cSJaegeuk Kim dn->inode_page = NULL; 122239a53e0cSJaegeuk Kim } 122339a53e0cSJaegeuk Kim 122439a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1225e8512d2eSGu Zheng size_t size) 122639a53e0cSJaegeuk Kim { 1227e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 122839a53e0cSJaegeuk Kim } 122939a53e0cSJaegeuk Kim 12307bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 12317bd59381SGu Zheng gfp_t flags) 12327bd59381SGu Zheng { 12337bd59381SGu Zheng void *entry; 12347bd59381SGu Zheng retry: 12357bd59381SGu Zheng entry = kmem_cache_alloc(cachep, flags); 12367bd59381SGu Zheng if (!entry) { 12377bd59381SGu Zheng cond_resched(); 12387bd59381SGu Zheng goto retry; 12397bd59381SGu Zheng } 12407bd59381SGu Zheng 12417bd59381SGu Zheng return entry; 12427bd59381SGu Zheng } 12437bd59381SGu Zheng 12449be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 12459be32d72SJaegeuk Kim unsigned long index, void *item) 12469be32d72SJaegeuk Kim { 12479be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 12489be32d72SJaegeuk Kim cond_resched(); 12499be32d72SJaegeuk Kim } 12509be32d72SJaegeuk Kim 125139a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 125239a53e0cSJaegeuk Kim 125339a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 125439a53e0cSJaegeuk Kim { 125545590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 125639a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 125739a53e0cSJaegeuk Kim } 125839a53e0cSJaegeuk Kim 125939a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 126039a53e0cSJaegeuk Kim { 126139a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 126239a53e0cSJaegeuk Kim } 126339a53e0cSJaegeuk Kim 126439a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 126539a53e0cSJaegeuk Kim unsigned int offset) 126639a53e0cSJaegeuk Kim { 126739a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 126839a53e0cSJaegeuk Kim __le32 *addr_array; 126945590710SGu Zheng raw_node = F2FS_NODE(node_page); 127039a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 127139a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 127239a53e0cSJaegeuk Kim } 127339a53e0cSJaegeuk Kim 127439a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 127539a53e0cSJaegeuk Kim { 127639a53e0cSJaegeuk Kim int mask; 127739a53e0cSJaegeuk Kim 127839a53e0cSJaegeuk Kim addr += (nr >> 3); 127939a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 128039a53e0cSJaegeuk Kim return mask & *addr; 128139a53e0cSJaegeuk Kim } 128239a53e0cSJaegeuk Kim 1283a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1284a66cdd98SJaegeuk Kim { 1285a66cdd98SJaegeuk Kim int mask; 1286a66cdd98SJaegeuk Kim 1287a66cdd98SJaegeuk Kim addr += (nr >> 3); 1288a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1289a66cdd98SJaegeuk Kim *addr |= mask; 1290a66cdd98SJaegeuk Kim } 1291a66cdd98SJaegeuk Kim 1292a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1293a66cdd98SJaegeuk Kim { 1294a66cdd98SJaegeuk Kim int mask; 1295a66cdd98SJaegeuk Kim 1296a66cdd98SJaegeuk Kim addr += (nr >> 3); 1297a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1298a66cdd98SJaegeuk Kim *addr &= ~mask; 1299a66cdd98SJaegeuk Kim } 1300a66cdd98SJaegeuk Kim 130152aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 130239a53e0cSJaegeuk Kim { 130339a53e0cSJaegeuk Kim int mask; 130439a53e0cSJaegeuk Kim int ret; 130539a53e0cSJaegeuk Kim 130639a53e0cSJaegeuk Kim addr += (nr >> 3); 130739a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 130839a53e0cSJaegeuk Kim ret = mask & *addr; 130939a53e0cSJaegeuk Kim *addr |= mask; 131039a53e0cSJaegeuk Kim return ret; 131139a53e0cSJaegeuk Kim } 131239a53e0cSJaegeuk Kim 131352aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 131439a53e0cSJaegeuk Kim { 131539a53e0cSJaegeuk Kim int mask; 131639a53e0cSJaegeuk Kim int ret; 131739a53e0cSJaegeuk Kim 131839a53e0cSJaegeuk Kim addr += (nr >> 3); 131939a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 132039a53e0cSJaegeuk Kim ret = mask & *addr; 132139a53e0cSJaegeuk Kim *addr &= ~mask; 132239a53e0cSJaegeuk Kim return ret; 132339a53e0cSJaegeuk Kim } 132439a53e0cSJaegeuk Kim 1325c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1326c6ac4c0eSGu Zheng { 1327c6ac4c0eSGu Zheng int mask; 1328c6ac4c0eSGu Zheng 1329c6ac4c0eSGu Zheng addr += (nr >> 3); 1330c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1331c6ac4c0eSGu Zheng *addr ^= mask; 1332c6ac4c0eSGu Zheng } 1333c6ac4c0eSGu Zheng 133439a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 133539a53e0cSJaegeuk Kim enum { 133639a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1337b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1338ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 133939a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 134039a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 134139a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1342699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 134374d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1344c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1345444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 13461001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 134734d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1348fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1349fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 135088b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 135188b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 135202a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 13533c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 13541e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1355b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1356510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 135739a53e0cSJaegeuk Kim }; 135839a53e0cSJaegeuk Kim 135939a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 136039a53e0cSJaegeuk Kim { 136161e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 136239a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 136339a53e0cSJaegeuk Kim } 136439a53e0cSJaegeuk Kim 136539a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 136639a53e0cSJaegeuk Kim { 136739a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 136839a53e0cSJaegeuk Kim } 136939a53e0cSJaegeuk Kim 137039a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 137139a53e0cSJaegeuk Kim { 137261e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 137339a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 137439a53e0cSJaegeuk Kim } 137539a53e0cSJaegeuk Kim 137639a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 137739a53e0cSJaegeuk Kim { 137839a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 137939a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 138039a53e0cSJaegeuk Kim } 138139a53e0cSJaegeuk Kim 1382444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1383444c580fSJaegeuk Kim struct f2fs_inode *ri) 1384444c580fSJaegeuk Kim { 1385444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1386444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 13871001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 13881001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 138934d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 139034d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1391b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1392b3d208f9SJaegeuk Kim set_inode_flag(fi, FI_DATA_EXIST); 1393510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1394510022a8SJaegeuk Kim set_inode_flag(fi, FI_INLINE_DOTS); 1395444c580fSJaegeuk Kim } 1396444c580fSJaegeuk Kim 1397444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1398444c580fSJaegeuk Kim struct f2fs_inode *ri) 1399444c580fSJaegeuk Kim { 1400444c580fSJaegeuk Kim ri->i_inline = 0; 1401444c580fSJaegeuk Kim 1402444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1403444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 14041001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 14051001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 140634d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 140734d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1408b3d208f9SJaegeuk Kim if (is_inode_flag_set(fi, FI_DATA_EXIST)) 1409b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1410510022a8SJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_DOTS)) 1411510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1412444c580fSJaegeuk Kim } 1413444c580fSJaegeuk Kim 1414987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1415987c7c31SChao Yu { 1416987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1417987c7c31SChao Yu } 1418987c7c31SChao Yu 1419de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1420de93653fSJaegeuk Kim { 1421987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1422de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1423de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1424de93653fSJaegeuk Kim } 1425de93653fSJaegeuk Kim 142665985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 142765985d93SJaegeuk Kim { 1428695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 142965985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 143065985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 143165985d93SJaegeuk Kim } 143265985d93SJaegeuk Kim 143365985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 143465985d93SJaegeuk Kim { 1435987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 143665985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 143765985d93SJaegeuk Kim else 143865985d93SJaegeuk Kim return 0; 143965985d93SJaegeuk Kim } 144065985d93SJaegeuk Kim 14410dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 14420dbdc2aeSJaegeuk Kim { 14430dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 14440dbdc2aeSJaegeuk Kim } 14450dbdc2aeSJaegeuk Kim 1446b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1447b3d208f9SJaegeuk Kim { 1448b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 1449b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1450b3d208f9SJaegeuk Kim } 1451b3d208f9SJaegeuk Kim 1452b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1453b3d208f9SJaegeuk Kim { 1454b3d208f9SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST); 1455b3d208f9SJaegeuk Kim } 1456b3d208f9SJaegeuk Kim 1457510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1458510022a8SJaegeuk Kim { 1459510022a8SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS); 1460510022a8SJaegeuk Kim } 1461510022a8SJaegeuk Kim 146288b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 146388b88a66SJaegeuk Kim { 146488b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 146588b88a66SJaegeuk Kim } 146688b88a66SJaegeuk Kim 146702a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 146802a1335fSJaegeuk Kim { 146902a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 147002a1335fSJaegeuk Kim } 147102a1335fSJaegeuk Kim 14723c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 14733c6c2bebSJaegeuk Kim { 14743c6c2bebSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); 14753c6c2bebSJaegeuk Kim } 14763c6c2bebSJaegeuk Kim 14771e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 14781e84371fSJaegeuk Kim { 14791e84371fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE); 14801e84371fSJaegeuk Kim } 14811e84371fSJaegeuk Kim 14821001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 14831001b347SHuajun Li { 1484695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 14851001b347SHuajun Li return (void *)&(ri->i_addr[1]); 14861001b347SHuajun Li } 14871001b347SHuajun Li 148834d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 148934d67debSChao Yu { 149034d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 149134d67debSChao Yu } 149234d67debSChao Yu 14939486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 14949486ba44SJaegeuk Kim { 14959486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 14969486ba44SJaegeuk Kim kunmap(page); 14979486ba44SJaegeuk Kim } 14989486ba44SJaegeuk Kim 1499b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1500b5492af7SJaegeuk Kim { 1501b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1502b5492af7SJaegeuk Kim } 1503b5492af7SJaegeuk Kim 1504b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1505b5492af7SJaegeuk Kim { 1506b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1507b5492af7SJaegeuk Kim } 1508b5492af7SJaegeuk Kim 1509b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1510b5492af7SJaegeuk Kim { 1511b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1512b5492af7SJaegeuk Kim } 1513b5492af7SJaegeuk Kim 151477888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 151577888c1eSJaegeuk Kim { 151677888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 151777888c1eSJaegeuk Kim } 151877888c1eSJaegeuk Kim 15191e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 15201e968fdfSJaegeuk Kim { 15211e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 15221e968fdfSJaegeuk Kim } 15231e968fdfSJaegeuk Kim 1524744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1525744602cfSJaegeuk Kim { 1526744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1527744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1528744602cfSJaegeuk Kim } 1529744602cfSJaegeuk Kim 1530eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1531eaa693f4SJaegeuk Kim { 1532eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1533eaa693f4SJaegeuk Kim return true; 1534eaa693f4SJaegeuk Kim 1535eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1536eaa693f4SJaegeuk Kim return true; 1537eaa693f4SJaegeuk Kim 1538eaa693f4SJaegeuk Kim return false; 1539eaa693f4SJaegeuk Kim } 1540eaa693f4SJaegeuk Kim 1541a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1542a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1543a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1544a6dda0e6SChristoph Hellwig 1545267378d4SChao Yu /* get offset of first page in next direct node */ 1546267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1547267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1548267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1549267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1550267378d4SChao Yu 155139a53e0cSJaegeuk Kim /* 155239a53e0cSJaegeuk Kim * file.c 155339a53e0cSJaegeuk Kim */ 155439a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 155539a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1556764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 155739a53e0cSJaegeuk Kim void f2fs_truncate(struct inode *); 15582d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 155939a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 156039a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1561b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 156239a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1563e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 156439a53e0cSJaegeuk Kim 156539a53e0cSJaegeuk Kim /* 156639a53e0cSJaegeuk Kim * inode.c 156739a53e0cSJaegeuk Kim */ 156839a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 156939a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 15704660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 157139a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *); 1572744602cfSJaegeuk Kim void update_inode_page(struct inode *); 157339a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 157439a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 157544c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 157639a53e0cSJaegeuk Kim 157739a53e0cSJaegeuk Kim /* 157839a53e0cSJaegeuk Kim * namei.c 157939a53e0cSJaegeuk Kim */ 158039a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 158139a53e0cSJaegeuk Kim 158239a53e0cSJaegeuk Kim /* 158339a53e0cSJaegeuk Kim * dir.c 158439a53e0cSJaegeuk Kim */ 1585dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1586510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 15877b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct qstr *, int *, 15887b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr *); 15897b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 1590*d8c6822aSJaegeuk Kim unsigned int, struct f2fs_str *); 1591062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1592062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1593dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1594bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1595dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1596a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1597dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 159839a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 159939a53e0cSJaegeuk Kim struct page **); 160039a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 160139a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 160239a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 160339a53e0cSJaegeuk Kim struct page *, struct inode *); 16041cd14cafSJaegeuk Kim int update_dent_inode(struct inode *, const struct qstr *); 1605510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 16063b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1607510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1608510022a8SJaegeuk Kim umode_t); 1609dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1610dbeacf02SChao Yu struct inode *); 1611b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 161239a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 161339a53e0cSJaegeuk Kim 1614b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1615b7f7a5e0SAl Viro { 16162b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1617510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1618b7f7a5e0SAl Viro } 1619b7f7a5e0SAl Viro 162039a53e0cSJaegeuk Kim /* 162139a53e0cSJaegeuk Kim * super.c 162239a53e0cSJaegeuk Kim */ 162326d815adSJaegeuk Kim int f2fs_commit_super(struct f2fs_sb_info *); 162439a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1625a07ef784SNamjae Jeon extern __printf(3, 4) 1626a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 162739a53e0cSJaegeuk Kim 162839a53e0cSJaegeuk Kim /* 162939a53e0cSJaegeuk Kim * hash.c 163039a53e0cSJaegeuk Kim */ 1631eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 163239a53e0cSJaegeuk Kim 163339a53e0cSJaegeuk Kim /* 163439a53e0cSJaegeuk Kim * node.c 163539a53e0cSJaegeuk Kim */ 163639a53e0cSJaegeuk Kim struct dnode_of_data; 163739a53e0cSJaegeuk Kim struct node_info; 163839a53e0cSJaegeuk Kim 16396fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 16402dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t); 164188bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 164288bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 164339a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 164439a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 164539a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 16464f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1647cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 164858e674d6SGu Zheng void remove_inode_page(struct inode *); 1649a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 16508ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 165139a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 165239a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 165339a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 165439a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 165539a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 165639a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 165739a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 165839a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 165970cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 16601c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 166139a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 166239a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 166339a53e0cSJaegeuk Kim struct f2fs_summary_block *); 166439a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 166539a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 166639a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 16676e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 166839a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 166939a53e0cSJaegeuk Kim 167039a53e0cSJaegeuk Kim /* 167139a53e0cSJaegeuk Kim * segment.c 167239a53e0cSJaegeuk Kim */ 167388b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 167488b88a66SJaegeuk Kim void commit_inmem_pages(struct inode *, bool); 167539a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *); 16764660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 16776b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 16782163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 16792163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 168039a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 16815e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 1682836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 16834b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1684cf2271e7SJaegeuk Kim void discard_next_dnode(struct f2fs_sb_info *, block_t); 16853fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 168639a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 16874b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 168839a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1689577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 169005ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 169105ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 169205ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 169319f106bcSChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct f2fs_summary *, 169419f106bcSChao Yu block_t, block_t, bool); 1695bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1696bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 16975514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 169839a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 169939a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 170039a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 170139a53e0cSJaegeuk Kim int, unsigned int, int); 17024b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 170339a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 170439a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 17057fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 17067fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 170739a53e0cSJaegeuk Kim 170839a53e0cSJaegeuk Kim /* 170939a53e0cSJaegeuk Kim * checkpoint.c 171039a53e0cSJaegeuk Kim */ 171139a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 171239a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 1713f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 17144c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int); 1715635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 171639a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1717fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1718fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 17196f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *); 1720fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1721cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1722cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 172339a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 172439a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 17258f99a946SChao Yu void recover_orphan_inodes(struct f2fs_sb_info *); 172639a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1727a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 17285deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 172939a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *); 173039a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *); 173175ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 17326451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 17336e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 173439a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 173539a53e0cSJaegeuk Kim 173639a53e0cSJaegeuk Kim /* 173739a53e0cSJaegeuk Kim * data.c 173839a53e0cSJaegeuk Kim */ 1739458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 174005ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 174105ca3632SJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_io_info *); 1742216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 174339a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1744b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 1745429511cdSChao Yu void f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 1746429511cdSChao Yu void f2fs_destroy_extent_tree(struct inode *); 1747028a41e8SChao Yu void f2fs_init_extent_cache(struct inode *, struct f2fs_extent *); 17487e4dde79SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 17490bdee482SChao Yu void f2fs_preserve_extent_tree(struct inode *); 175043f3eae1SJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int); 175143f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t); 175239a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t); 175364aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 175405ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 17559ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1756429511cdSChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 1757429511cdSChao Yu int __init create_extent_cache(void); 1758429511cdSChao Yu void destroy_extent_cache(void); 1759487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1760487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 176139a53e0cSJaegeuk Kim 176239a53e0cSJaegeuk Kim /* 176339a53e0cSJaegeuk Kim * gc.c 176439a53e0cSJaegeuk Kim */ 176539a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 176639a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1767de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1768408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *); 176939a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 177039a53e0cSJaegeuk Kim 177139a53e0cSJaegeuk Kim /* 177239a53e0cSJaegeuk Kim * recovery.c 177339a53e0cSJaegeuk Kim */ 17746ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 177539a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 177639a53e0cSJaegeuk Kim 177739a53e0cSJaegeuk Kim /* 177839a53e0cSJaegeuk Kim * debug.c 177939a53e0cSJaegeuk Kim */ 178039a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 178139a53e0cSJaegeuk Kim struct f2fs_stat_info { 178239a53e0cSJaegeuk Kim struct list_head stat_list; 178339a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 178439a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 178539a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 17864bf6fd9fSChao Yu int hit_ext, total_ext, ext_tree, ext_node; 178739a53e0cSJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 1788dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 178939a53e0cSJaegeuk Kim int total_count, utilization; 1790d24bdcbfSJaegeuk Kim int bg_gc, inline_inode, inline_dir, inmem_pages, wb_pages; 179139a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 179239a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 179339a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 179439a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 179539a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1796942e0be6SChangman Lee int prefree_count, call_count, cp_count; 179739a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 1798e1235983SChangman Lee int bg_node_segs, bg_data_segs; 179939a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 1800e1235983SChangman Lee int bg_data_blks, bg_node_blks; 180139a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 180239a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 180339a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 180439a53e0cSJaegeuk Kim 180539a53e0cSJaegeuk Kim unsigned int segment_count[2]; 180639a53e0cSJaegeuk Kim unsigned int block_count[2]; 1807b9a2c252SChangman Lee unsigned int inplace_count; 18086f0aacbcSJaegeuk Kim unsigned base_mem, cache_mem, page_mem; 180939a53e0cSJaegeuk Kim }; 181039a53e0cSJaegeuk Kim 1811963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1812963d4f7dSGu Zheng { 1813963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1814963d4f7dSGu Zheng } 1815963d4f7dSGu Zheng 1816942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 181739a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1818dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1819dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1820dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 1821dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++) 1822dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++) 18230dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 18240dbdc2aeSJaegeuk Kim do { \ 18250dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 182603e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 18270dbdc2aeSJaegeuk Kim } while (0) 18280dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 18290dbdc2aeSJaegeuk Kim do { \ 18300dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 183103e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 18320dbdc2aeSJaegeuk Kim } while (0) 18333289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 18343289c061SJaegeuk Kim do { \ 18353289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 183603e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 18373289c061SJaegeuk Kim } while (0) 18383289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 18393289c061SJaegeuk Kim do { \ 18403289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 184103e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 18423289c061SJaegeuk Kim } while (0) 1843dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1844dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1845dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1846dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 1847b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 1848b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 1849e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 185039a53e0cSJaegeuk Kim do { \ 1851963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 185239a53e0cSJaegeuk Kim (si)->tot_segs++; \ 1853e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 185439a53e0cSJaegeuk Kim si->data_segs++; \ 1855e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 1856e1235983SChangman Lee } else { \ 185739a53e0cSJaegeuk Kim si->node_segs++; \ 1858e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 1859e1235983SChangman Lee } \ 186039a53e0cSJaegeuk Kim } while (0) 186139a53e0cSJaegeuk Kim 186239a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 186339a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 186439a53e0cSJaegeuk Kim 1865e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 186639a53e0cSJaegeuk Kim do { \ 1867963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 186839a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 186939a53e0cSJaegeuk Kim si->data_blks += (blks); \ 1870e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 187139a53e0cSJaegeuk Kim } while (0) 187239a53e0cSJaegeuk Kim 1873e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 187439a53e0cSJaegeuk Kim do { \ 1875963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 187639a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 187739a53e0cSJaegeuk Kim si->node_blks += (blks); \ 1878e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 187939a53e0cSJaegeuk Kim } while (0) 188039a53e0cSJaegeuk Kim 188139a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 188239a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 18836e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void); 18844589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 188539a53e0cSJaegeuk Kim #else 1886942e0be6SChangman Lee #define stat_inc_cp_count(si) 188739a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 1888dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 1889dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) 1890dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) 1891dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 1892dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) 18930dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 18940dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 18953289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 18963289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 1897dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 1898dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 1899b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 1900e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 190139a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 1902e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 1903e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 190439a53e0cSJaegeuk Kim 190539a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 190639a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 19076e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { } 19084589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 190939a53e0cSJaegeuk Kim #endif 191039a53e0cSJaegeuk Kim 191139a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 191239a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 191339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 191439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 191539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 191639a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 191739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 191839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 191939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 192029e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 19211001b347SHuajun Li 1922e18c65b2SHuajun Li /* 1923e18c65b2SHuajun Li * inline.c 1924e18c65b2SHuajun Li */ 192501b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 192601b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 1927b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 19280bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 1929e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 1930b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 1931b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 1932b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 19330342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 1934201a05beSChao Yu struct f2fs_dir_entry *find_in_inline_dir(struct inode *, struct qstr *, 1935201a05beSChao Yu struct page **); 1936201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 1937201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 1938510022a8SJaegeuk Kim int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 1939510022a8SJaegeuk Kim nid_t, umode_t); 1940201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 1941201a05beSChao Yu struct inode *, struct inode *); 1942201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 1943*d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *, struct dir_context *, 1944*d8c6822aSJaegeuk Kim struct f2fs_str *); 1945cde4de12SJaegeuk Kim 1946cde4de12SJaegeuk Kim /* 1947cde4de12SJaegeuk Kim * crypto support 1948cde4de12SJaegeuk Kim */ 1949cde4de12SJaegeuk Kim static inline int f2fs_encrypted_inode(struct inode *inode) 1950cde4de12SJaegeuk Kim { 1951cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 1952cde4de12SJaegeuk Kim return file_is_encrypt(inode); 1953cde4de12SJaegeuk Kim #else 1954cde4de12SJaegeuk Kim return 0; 1955cde4de12SJaegeuk Kim #endif 1956cde4de12SJaegeuk Kim } 1957cde4de12SJaegeuk Kim 1958cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 1959cde4de12SJaegeuk Kim { 1960cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 1961cde4de12SJaegeuk Kim file_set_encrypt(inode); 1962cde4de12SJaegeuk Kim #endif 1963cde4de12SJaegeuk Kim } 1964cde4de12SJaegeuk Kim 1965cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 1966cde4de12SJaegeuk Kim { 1967cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 1968cde4de12SJaegeuk Kim return unlikely(bio->bi_private != NULL); 1969cde4de12SJaegeuk Kim #else 1970cde4de12SJaegeuk Kim return false; 1971cde4de12SJaegeuk Kim #endif 1972cde4de12SJaegeuk Kim } 1973cde4de12SJaegeuk Kim 1974cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 1975cde4de12SJaegeuk Kim { 1976cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 1977cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 1978cde4de12SJaegeuk Kim #else 1979cde4de12SJaegeuk Kim return 0; 1980cde4de12SJaegeuk Kim #endif 1981cde4de12SJaegeuk Kim } 1982f424f664SJaegeuk Kim 1983fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 1984fcc85a4dSJaegeuk Kim { 1985fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 1986fcc85a4dSJaegeuk Kim mode_t mode = inode->i_mode; 1987fcc85a4dSJaegeuk Kim 1988fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 1989fcc85a4dSJaegeuk Kim #else 1990fcc85a4dSJaegeuk Kim return 0; 1991fcc85a4dSJaegeuk Kim #endif 1992fcc85a4dSJaegeuk Kim } 1993fcc85a4dSJaegeuk Kim 1994f424f664SJaegeuk Kim /* crypto_policy.c */ 1995f424f664SJaegeuk Kim int f2fs_is_child_context_consistent_with_parent(struct inode *, 1996f424f664SJaegeuk Kim struct inode *); 1997f424f664SJaegeuk Kim int f2fs_inherit_context(struct inode *, struct inode *, struct page *); 1998f424f664SJaegeuk Kim int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *); 1999f424f664SJaegeuk Kim int f2fs_get_policy(struct inode *, struct f2fs_encryption_policy *); 200057e5055bSJaegeuk Kim 200157e5055bSJaegeuk Kim /* crypt.c */ 200257e5055bSJaegeuk Kim extern struct workqueue_struct *f2fs_read_workqueue; 200357e5055bSJaegeuk Kim bool f2fs_valid_contents_enc_mode(uint32_t); 200457e5055bSJaegeuk Kim uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t); 200557e5055bSJaegeuk Kim struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *); 200657e5055bSJaegeuk Kim void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *); 200757e5055bSJaegeuk Kim struct page *f2fs_encrypt(struct inode *, struct page *); 200857e5055bSJaegeuk Kim int f2fs_decrypt(struct f2fs_crypto_ctx *, struct page *); 200957e5055bSJaegeuk Kim int f2fs_decrypt_one(struct inode *, struct page *); 201057e5055bSJaegeuk Kim void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *); 201157e5055bSJaegeuk Kim 20120adda907SJaegeuk Kim /* crypto_key.c */ 20130adda907SJaegeuk Kim void f2fs_free_encryption_info(struct inode *); 20140adda907SJaegeuk Kim int _f2fs_get_encryption_info(struct inode *inode); 20150adda907SJaegeuk Kim 20166b3bd08fSJaegeuk Kim /* crypto_fname.c */ 20176b3bd08fSJaegeuk Kim bool f2fs_valid_filenames_enc_mode(uint32_t); 20186b3bd08fSJaegeuk Kim u32 f2fs_fname_crypto_round_up(u32, u32); 20196b3bd08fSJaegeuk Kim int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *); 20206b3bd08fSJaegeuk Kim int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *, 20216b3bd08fSJaegeuk Kim const struct f2fs_str *, struct f2fs_str *); 20226b3bd08fSJaegeuk Kim int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *, 20236b3bd08fSJaegeuk Kim struct f2fs_str *); 20246b3bd08fSJaegeuk Kim 202557e5055bSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 202657e5055bSJaegeuk Kim void f2fs_restore_and_release_control_page(struct page **); 202757e5055bSJaegeuk Kim void f2fs_restore_control_page(struct page *); 202857e5055bSJaegeuk Kim 202957e5055bSJaegeuk Kim int f2fs_init_crypto(void); 203057e5055bSJaegeuk Kim void f2fs_exit_crypto(void); 20310adda907SJaegeuk Kim 20320adda907SJaegeuk Kim int f2fs_has_encryption_key(struct inode *); 20330adda907SJaegeuk Kim 20340adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *inode) 20350adda907SJaegeuk Kim { 20360adda907SJaegeuk Kim struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info; 20370adda907SJaegeuk Kim 20380adda907SJaegeuk Kim if (!ci || 20390adda907SJaegeuk Kim (ci->ci_keyring_key && 20400adda907SJaegeuk Kim (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | 20410adda907SJaegeuk Kim (1 << KEY_FLAG_REVOKED) | 20420adda907SJaegeuk Kim (1 << KEY_FLAG_DEAD))))) 20430adda907SJaegeuk Kim return _f2fs_get_encryption_info(inode); 20440adda907SJaegeuk Kim return 0; 20450adda907SJaegeuk Kim } 20466b3bd08fSJaegeuk Kim 20476b3bd08fSJaegeuk Kim int f2fs_setup_fname_crypto(struct inode *); 20486b3bd08fSJaegeuk Kim void f2fs_fname_crypto_free_buffer(struct f2fs_str *); 20496b3bd08fSJaegeuk Kim int f2fs_fname_setup_filename(struct inode *, const struct qstr *, 20506b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *); 20516b3bd08fSJaegeuk Kim void f2fs_fname_free_filename(struct f2fs_filename *); 205257e5055bSJaegeuk Kim #else 205357e5055bSJaegeuk Kim static inline void f2fs_restore_and_release_control_page(struct page **p) { } 205457e5055bSJaegeuk Kim static inline void f2fs_restore_control_page(struct page *p) { } 205557e5055bSJaegeuk Kim 205657e5055bSJaegeuk Kim static inline int f2fs_init_crypto(void) { return 0; } 205757e5055bSJaegeuk Kim static inline void f2fs_exit_crypto(void) { } 20580adda907SJaegeuk Kim 20590adda907SJaegeuk Kim static inline int f2fs_has_encryption_key(struct inode *i) { return 0; } 20600adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *i) { return 0; } 20616b3bd08fSJaegeuk Kim 20626b3bd08fSJaegeuk Kim static inline int f2fs_setup_fname_crypto(struct inode *i) { return 0; } 20636b3bd08fSJaegeuk Kim static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { } 20646b3bd08fSJaegeuk Kim 20656b3bd08fSJaegeuk Kim static inline int f2fs_fname_setup_filename(struct inode *dir, 20666b3bd08fSJaegeuk Kim const struct qstr *iname, 20676b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *fname) 20686b3bd08fSJaegeuk Kim { 20696b3bd08fSJaegeuk Kim memset(fname, 0, sizeof(struct f2fs_filename)); 20706b3bd08fSJaegeuk Kim fname->usr_fname = iname; 20716b3bd08fSJaegeuk Kim fname->disk_name.name = (unsigned char *)iname->name; 20726b3bd08fSJaegeuk Kim fname->disk_name.len = iname->len; 20736b3bd08fSJaegeuk Kim return 0; 20746b3bd08fSJaegeuk Kim } 20756b3bd08fSJaegeuk Kim 20766b3bd08fSJaegeuk Kim static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { } 207757e5055bSJaegeuk Kim #endif 207839a53e0cSJaegeuk Kim #endif 2079