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 { 2807b3cd7d6SJaegeuk Kim const void *bitmap; 2817b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 2827b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 2837b3cd7d6SJaegeuk Kim int max; 2847b3cd7d6SJaegeuk Kim }; 2857b3cd7d6SJaegeuk Kim 2867b3cd7d6SJaegeuk Kim static inline void make_dentry_ptr(struct f2fs_dentry_ptr *d, 2877b3cd7d6SJaegeuk Kim void *src, int type) 2887b3cd7d6SJaegeuk Kim { 2897b3cd7d6SJaegeuk Kim if (type == 1) { 2907b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 2917b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 2927b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2937b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 2947b3cd7d6SJaegeuk Kim d->filename = t->filename; 2957b3cd7d6SJaegeuk Kim } else { 2967b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 2977b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 2987b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2997b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3007b3cd7d6SJaegeuk Kim d->filename = t->filename; 3017b3cd7d6SJaegeuk Kim } 3027b3cd7d6SJaegeuk Kim } 3037b3cd7d6SJaegeuk Kim 304dbe6a5ffSJaegeuk Kim /* 305dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 306dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 307dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 30839a53e0cSJaegeuk Kim */ 309dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 310dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 311266e97a8SJaegeuk Kim enum { 312266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 313266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 314266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 315266e97a8SJaegeuk Kim * look up a node with readahead called 3164f4124d0SChao Yu * by get_data_block. 31739a53e0cSJaegeuk Kim */ 318266e97a8SJaegeuk Kim }; 319266e97a8SJaegeuk Kim 32039a53e0cSJaegeuk Kim #define F2FS_LINK_MAX 32000 /* maximum link count per file */ 32139a53e0cSJaegeuk Kim 322817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 323817202d9SChao Yu 32413054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 32513054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 32613054c54SChao Yu 32739a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 32813054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 32913054c54SChao Yu 33013054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 33113054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 332c11abd1aSJaegeuk Kim 33339a53e0cSJaegeuk Kim struct extent_info { 33439a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3354d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 336111d2495SMasanari Iida unsigned int len; /* length of the extent */ 33739a53e0cSJaegeuk Kim }; 33839a53e0cSJaegeuk Kim 33913054c54SChao Yu struct extent_node { 34013054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 34113054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 34213054c54SChao Yu struct extent_info ei; /* extent info */ 34313054c54SChao Yu }; 34413054c54SChao Yu 34513054c54SChao Yu struct extent_tree { 34613054c54SChao Yu nid_t ino; /* inode number */ 34713054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 34862c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 34913054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 35013054c54SChao Yu atomic_t refcount; /* reference count of rb-tree */ 35113054c54SChao Yu unsigned int count; /* # of extent node in rb-tree*/ 35213054c54SChao Yu }; 35313054c54SChao Yu 35439a53e0cSJaegeuk Kim /* 355003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 356003a3e1dSJaegeuk Kim * 357003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 358003a3e1dSJaegeuk Kim */ 359003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 360003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 3617f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 3627f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 3637f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 364003a3e1dSJaegeuk Kim 365003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 366003a3e1dSJaegeuk Kim block_t m_pblk; 367003a3e1dSJaegeuk Kim block_t m_lblk; 368003a3e1dSJaegeuk Kim unsigned int m_len; 369003a3e1dSJaegeuk Kim unsigned int m_flags; 370003a3e1dSJaegeuk Kim }; 371003a3e1dSJaegeuk Kim 372003a3e1dSJaegeuk Kim /* 37339a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 37439a53e0cSJaegeuk Kim */ 37539a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 376354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 377cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 37839a53e0cSJaegeuk Kim 379b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 380b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 381b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 382b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 383b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 384b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 385cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 386cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 387cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 388cde4de12SJaegeuk Kim 389cde4de12SJaegeuk Kim /* Encryption algorithms */ 390cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_INVALID 0 391cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_XTS 1 392cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_GCM 2 393cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CBC 3 394cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CTS 4 395b5492af7SJaegeuk Kim 396f424f664SJaegeuk Kim #include "f2fs_crypto.h" 397f424f664SJaegeuk Kim 398ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 399ab9fa662SJaegeuk Kim 40039a53e0cSJaegeuk Kim struct f2fs_inode_info { 40139a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 40239a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 40339a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 40438431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 40539a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4066666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 40739a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 40839a53e0cSJaegeuk Kim 40939a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 41039a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 411d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 412a7ffdbe2SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 41339a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 41439a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 41539a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 416e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 41739a53e0cSJaegeuk Kim struct extent_info ext; /* in-memory extent cache entry */ 4180c872e2dSChao Yu rwlock_t ext_lock; /* rwlock for single extent cache */ 41906292073SChao Yu struct inode_entry *dirty_dir; /* the pointer of dirty dir */ 42088b88a66SJaegeuk Kim 42134ba94baSJaegeuk Kim struct radix_tree_root inmem_root; /* radix tree for inmem pages */ 42288b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 42388b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 424cde4de12SJaegeuk Kim 425cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 426cde4de12SJaegeuk Kim /* Encryption params */ 427cde4de12SJaegeuk Kim struct f2fs_crypt_info *i_crypt_info; 428cde4de12SJaegeuk Kim #endif 42939a53e0cSJaegeuk Kim }; 43039a53e0cSJaegeuk Kim 43139a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 43239a53e0cSJaegeuk Kim struct f2fs_extent i_ext) 43339a53e0cSJaegeuk Kim { 43439a53e0cSJaegeuk Kim ext->fofs = le32_to_cpu(i_ext.fofs); 4354d0b0bd4SChao Yu ext->blk = le32_to_cpu(i_ext.blk); 43639a53e0cSJaegeuk Kim ext->len = le32_to_cpu(i_ext.len); 43739a53e0cSJaegeuk Kim } 43839a53e0cSJaegeuk Kim 43939a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 44039a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 44139a53e0cSJaegeuk Kim { 44239a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4434d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 44439a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 44539a53e0cSJaegeuk Kim } 44639a53e0cSJaegeuk Kim 447429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 448429511cdSChao Yu u32 blk, unsigned int len) 449429511cdSChao Yu { 450429511cdSChao Yu ei->fofs = fofs; 451429511cdSChao Yu ei->blk = blk; 452429511cdSChao Yu ei->len = len; 453429511cdSChao Yu } 454429511cdSChao Yu 4550bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1, 4560bdee482SChao Yu struct extent_info *ei2) 4570bdee482SChao Yu { 4580bdee482SChao Yu return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 4590bdee482SChao Yu ei1->len == ei2->len); 4600bdee482SChao Yu } 4610bdee482SChao Yu 462429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 463429511cdSChao Yu struct extent_info *front) 464429511cdSChao Yu { 465429511cdSChao Yu return (back->fofs + back->len == front->fofs && 466429511cdSChao Yu back->blk + back->len == front->blk); 467429511cdSChao Yu } 468429511cdSChao Yu 469429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 470429511cdSChao Yu struct extent_info *back) 471429511cdSChao Yu { 472429511cdSChao Yu return __is_extent_mergeable(back, cur); 473429511cdSChao Yu } 474429511cdSChao Yu 475429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 476429511cdSChao Yu struct extent_info *front) 477429511cdSChao Yu { 478429511cdSChao Yu return __is_extent_mergeable(cur, front); 479429511cdSChao Yu } 480429511cdSChao Yu 48139a53e0cSJaegeuk Kim struct f2fs_nm_info { 48239a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 48339a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 4847ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 48539a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 486cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 48739a53e0cSJaegeuk Kim 48839a53e0cSJaegeuk Kim /* NAT cache management */ 48939a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 490309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 4918b26ef98SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 49239a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 493309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 494aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 49539a53e0cSJaegeuk Kim 49639a53e0cSJaegeuk Kim /* free node ids management */ 4978a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 49839a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 49939a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 50039a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 50139a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 50239a53e0cSJaegeuk Kim 50339a53e0cSJaegeuk Kim /* for checkpoint */ 50439a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 50539a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 50639a53e0cSJaegeuk Kim }; 50739a53e0cSJaegeuk Kim 50839a53e0cSJaegeuk Kim /* 50939a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 51039a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 51139a53e0cSJaegeuk Kim * by the data offset in a file. 51239a53e0cSJaegeuk Kim */ 51339a53e0cSJaegeuk Kim struct dnode_of_data { 51439a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 51539a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 51639a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 51739a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 51839a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 51939a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 52039a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 52139a53e0cSJaegeuk Kim }; 52239a53e0cSJaegeuk Kim 52339a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 52439a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 52539a53e0cSJaegeuk Kim { 526d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 52739a53e0cSJaegeuk Kim dn->inode = inode; 52839a53e0cSJaegeuk Kim dn->inode_page = ipage; 52939a53e0cSJaegeuk Kim dn->node_page = npage; 53039a53e0cSJaegeuk Kim dn->nid = nid; 53139a53e0cSJaegeuk Kim } 53239a53e0cSJaegeuk Kim 53339a53e0cSJaegeuk Kim /* 53439a53e0cSJaegeuk Kim * For SIT manager 53539a53e0cSJaegeuk Kim * 53639a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 53739a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 53839a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 53939a53e0cSJaegeuk Kim * respectively. 54039a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 54139a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 54239a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 54339a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 54439a53e0cSJaegeuk Kim * data and 8 for node logs. 54539a53e0cSJaegeuk Kim */ 54639a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 54739a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 54839a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 54939a53e0cSJaegeuk Kim 55039a53e0cSJaegeuk Kim enum { 55139a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 55239a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 55339a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 55439a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 55539a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 55639a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 55738aa0889SJaegeuk Kim NO_CHECK_TYPE, 55838aa0889SJaegeuk Kim CURSEG_DIRECT_IO, /* to use for the direct IO path */ 55939a53e0cSJaegeuk Kim }; 56039a53e0cSJaegeuk Kim 5616b4afdd7SJaegeuk Kim struct flush_cmd { 5626b4afdd7SJaegeuk Kim struct completion wait; 563721bd4d5SGu Zheng struct llist_node llnode; 5646b4afdd7SJaegeuk Kim int ret; 5656b4afdd7SJaegeuk Kim }; 5666b4afdd7SJaegeuk Kim 567a688b9d9SGu Zheng struct flush_cmd_control { 568a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 569a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 570721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 571721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 572a688b9d9SGu Zheng }; 573a688b9d9SGu Zheng 57439a53e0cSJaegeuk Kim struct f2fs_sm_info { 57539a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 57639a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 57739a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 57839a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 57939a53e0cSJaegeuk Kim 58039a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 58139a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 58239a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 58339a53e0cSJaegeuk Kim 58439a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 58539a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 58639a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 58739a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 58881eb8d6eSJaegeuk Kim 58981eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 59081eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 5917fd9e544SJaegeuk Kim 5927fd9e544SJaegeuk Kim /* for small discard management */ 5937fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 5947fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 5957fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 596216fbd64SJaegeuk Kim 597bba681cbSJaegeuk Kim /* for batched trimming */ 598bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 599bba681cbSJaegeuk Kim 600184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 601184a5cd2SChao Yu 602216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 603216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 604c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 6056b4afdd7SJaegeuk Kim 6066b4afdd7SJaegeuk Kim /* for flush command control */ 607a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 608a688b9d9SGu Zheng 60939a53e0cSJaegeuk Kim }; 61039a53e0cSJaegeuk Kim 61139a53e0cSJaegeuk Kim /* 61239a53e0cSJaegeuk Kim * For superblock 61339a53e0cSJaegeuk Kim */ 61439a53e0cSJaegeuk Kim /* 61539a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 61639a53e0cSJaegeuk Kim * 61739a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 61839a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 61939a53e0cSJaegeuk Kim */ 62039a53e0cSJaegeuk Kim enum count_type { 62139a53e0cSJaegeuk Kim F2FS_WRITEBACK, 62239a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 62339a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 62439a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6258dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 62639a53e0cSJaegeuk Kim NR_COUNT_TYPE, 62739a53e0cSJaegeuk Kim }; 62839a53e0cSJaegeuk Kim 62939a53e0cSJaegeuk Kim /* 630e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 63139a53e0cSJaegeuk Kim * The available types are: 63239a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 63339a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 63439a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 63539a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 63639a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 63739a53e0cSJaegeuk Kim * with waiting the bio's completion 63839a53e0cSJaegeuk Kim * ... Only can be used with META. 63939a53e0cSJaegeuk Kim */ 6407d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 64139a53e0cSJaegeuk Kim enum page_type { 64239a53e0cSJaegeuk Kim DATA, 64339a53e0cSJaegeuk Kim NODE, 64439a53e0cSJaegeuk Kim META, 64539a53e0cSJaegeuk Kim NR_PAGE_TYPE, 64639a53e0cSJaegeuk Kim META_FLUSH, 6478ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 6488ce67cb0SJaegeuk Kim INMEM_DROP, 6498ce67cb0SJaegeuk Kim IPU, 6508ce67cb0SJaegeuk Kim OPU, 65139a53e0cSJaegeuk Kim }; 65239a53e0cSJaegeuk Kim 653458e6197SJaegeuk Kim struct f2fs_io_info { 65405ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 655458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 6567e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 657cf04e8ebSJaegeuk Kim block_t blk_addr; /* block address to be written */ 65805ca3632SJaegeuk Kim struct page *page; /* page to be written */ 659*4375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 660458e6197SJaegeuk Kim }; 661458e6197SJaegeuk Kim 66293dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 6631ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 664458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 6651ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 6661ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 667458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 668df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 6691ff7bd3bSJaegeuk Kim }; 6701ff7bd3bSJaegeuk Kim 67167298804SChao Yu /* for inner inode cache management */ 67267298804SChao Yu struct inode_management { 67367298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 67467298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 67567298804SChao Yu struct list_head ino_list; /* inode list head */ 67667298804SChao Yu unsigned long ino_num; /* number of entries */ 67767298804SChao Yu }; 67867298804SChao Yu 679caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 680caf0047eSChao Yu enum { 681caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 682caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 683caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 684caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 685caf0047eSChao Yu }; 686caf0047eSChao Yu 68739a53e0cSJaegeuk Kim struct f2fs_sb_info { 68839a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 6895e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 69039a53e0cSJaegeuk Kim struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 69139a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 692caf0047eSChao Yu int s_flag; /* flags for sbi */ 69339a53e0cSJaegeuk Kim 69439a53e0cSJaegeuk Kim /* for node-related operations */ 69539a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 69639a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 69739a53e0cSJaegeuk Kim 69839a53e0cSJaegeuk Kim /* for segment-related operations */ 69939a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 7001ff7bd3bSJaegeuk Kim 7011ff7bd3bSJaegeuk Kim /* for bio operations */ 702924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 7031ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 70439a53e0cSJaegeuk Kim 70539a53e0cSJaegeuk Kim /* for checkpoint */ 70639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 70739a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 70839936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 709e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 710b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 7115463e7c1SJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 712fb51b5efSChangman Lee wait_queue_head_t cp_wait; 71339a53e0cSJaegeuk Kim 71467298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 7156451e041SJaegeuk Kim 7166451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 7170d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 71839a53e0cSJaegeuk Kim 71939a53e0cSJaegeuk Kim /* for directory inode management */ 72039a53e0cSJaegeuk Kim struct list_head dir_inode_list; /* dir inode list */ 72139a53e0cSJaegeuk Kim spinlock_t dir_inode_lock; /* for dir inode list lock */ 72239a53e0cSJaegeuk Kim 72313054c54SChao Yu /* for extent tree cache */ 72413054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 72513054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 72613054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 72713054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 72813054c54SChao Yu int total_ext_tree; /* extent tree count */ 72913054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 73013054c54SChao Yu 73139a53e0cSJaegeuk Kim /* basic filesystem units */ 73239a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 73339a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 73439a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 73539a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 73639a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 73739a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 73839a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 73939a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 74039a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 74139a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 74239a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 74339a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 74439a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 74539a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 74639a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 747ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 74839a53e0cSJaegeuk Kim 74939a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 75039a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 75139a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 752a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 75339a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 75439a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 75539a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 75639a53e0cSJaegeuk Kim 75739a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 75839a53e0cSJaegeuk Kim 75939a53e0cSJaegeuk Kim /* for cleaning operations */ 76039a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 76139a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 7625ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 76339a53e0cSJaegeuk Kim 764b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 765b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 766b1c57c1cSJaegeuk Kim 76739a53e0cSJaegeuk Kim /* 76839a53e0cSJaegeuk Kim * for stat information. 76939a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 77039a53e0cSJaegeuk Kim */ 77135b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 77239a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 77339a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 77439a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 775b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 77639a53e0cSJaegeuk Kim int total_hit_ext, read_hit_ext; /* extent cache hit ratio */ 77703e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 77803e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 77939a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 78035b09d82SNamjae Jeon unsigned int n_dirty_dirs; /* # of dir inodes */ 78135b09d82SNamjae Jeon #endif 78235b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 78339a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 784b59d0baeSNamjae Jeon 785b59d0baeSNamjae Jeon /* For sysfs suppport */ 786b59d0baeSNamjae Jeon struct kobject s_kobj; 787b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 78839a53e0cSJaegeuk Kim }; 78939a53e0cSJaegeuk Kim 79039a53e0cSJaegeuk Kim /* 79139a53e0cSJaegeuk Kim * Inline functions 79239a53e0cSJaegeuk Kim */ 79339a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 79439a53e0cSJaegeuk Kim { 79539a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 79639a53e0cSJaegeuk Kim } 79739a53e0cSJaegeuk Kim 79839a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 79939a53e0cSJaegeuk Kim { 80039a53e0cSJaegeuk Kim return sb->s_fs_info; 80139a53e0cSJaegeuk Kim } 80239a53e0cSJaegeuk Kim 8034081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 8044081363fSJaegeuk Kim { 8054081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 8064081363fSJaegeuk Kim } 8074081363fSJaegeuk Kim 8084081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 8094081363fSJaegeuk Kim { 8104081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 8114081363fSJaegeuk Kim } 8124081363fSJaegeuk Kim 8134081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 8144081363fSJaegeuk Kim { 8154081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 8164081363fSJaegeuk Kim } 8174081363fSJaegeuk Kim 81839a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 81939a53e0cSJaegeuk Kim { 82039a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 82139a53e0cSJaegeuk Kim } 82239a53e0cSJaegeuk Kim 82339a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 82439a53e0cSJaegeuk Kim { 82539a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 82639a53e0cSJaegeuk Kim } 82739a53e0cSJaegeuk Kim 82845590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 82945590710SGu Zheng { 83045590710SGu Zheng return (struct f2fs_node *)page_address(page); 83145590710SGu Zheng } 83245590710SGu Zheng 83358bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 83458bfaf44SJaegeuk Kim { 83558bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 83658bfaf44SJaegeuk Kim } 83758bfaf44SJaegeuk Kim 83839a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 83939a53e0cSJaegeuk Kim { 84039a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 84139a53e0cSJaegeuk Kim } 84239a53e0cSJaegeuk Kim 84339a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 84439a53e0cSJaegeuk Kim { 84539a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 84639a53e0cSJaegeuk Kim } 84739a53e0cSJaegeuk Kim 84839a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 84939a53e0cSJaegeuk Kim { 85039a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 85139a53e0cSJaegeuk Kim } 85239a53e0cSJaegeuk Kim 85339a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 85439a53e0cSJaegeuk Kim { 85539a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 85639a53e0cSJaegeuk Kim } 85739a53e0cSJaegeuk Kim 85839a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 85939a53e0cSJaegeuk Kim { 86039a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 86139a53e0cSJaegeuk Kim } 86239a53e0cSJaegeuk Kim 8639df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 8649df27d98SGu Zheng { 8659df27d98SGu Zheng return sbi->meta_inode->i_mapping; 8669df27d98SGu Zheng } 8679df27d98SGu Zheng 8684ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 8694ef51a8fSJaegeuk Kim { 8704ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 8714ef51a8fSJaegeuk Kim } 8724ef51a8fSJaegeuk Kim 873caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 87439a53e0cSJaegeuk Kim { 875caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 87639a53e0cSJaegeuk Kim } 87739a53e0cSJaegeuk Kim 878caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 87939a53e0cSJaegeuk Kim { 880caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 881caf0047eSChao Yu } 882caf0047eSChao Yu 883caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 884caf0047eSChao Yu { 885caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 88639a53e0cSJaegeuk Kim } 88739a53e0cSJaegeuk Kim 888d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 889d71b5564SJaegeuk Kim { 890d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 891d71b5564SJaegeuk Kim } 892d71b5564SJaegeuk Kim 89325ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 89425ca923bSJaegeuk Kim { 89525ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 89625ca923bSJaegeuk Kim return ckpt_flags & f; 89725ca923bSJaegeuk Kim } 89825ca923bSJaegeuk Kim 89925ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 90025ca923bSJaegeuk Kim { 90125ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 90225ca923bSJaegeuk Kim ckpt_flags |= f; 90325ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 90425ca923bSJaegeuk Kim } 90525ca923bSJaegeuk Kim 90625ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 90725ca923bSJaegeuk Kim { 90825ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 90925ca923bSJaegeuk Kim ckpt_flags &= (~f); 91025ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 91125ca923bSJaegeuk Kim } 91225ca923bSJaegeuk Kim 913e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 91439a53e0cSJaegeuk Kim { 915e479556bSGu Zheng down_read(&sbi->cp_rwsem); 91639a53e0cSJaegeuk Kim } 91739a53e0cSJaegeuk Kim 918e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 91939a53e0cSJaegeuk Kim { 920e479556bSGu Zheng up_read(&sbi->cp_rwsem); 92139936837SJaegeuk Kim } 92239936837SJaegeuk Kim 923e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 92439936837SJaegeuk Kim { 9250daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 92639936837SJaegeuk Kim } 92739936837SJaegeuk Kim 928e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 92939936837SJaegeuk Kim { 930e479556bSGu Zheng up_write(&sbi->cp_rwsem); 93139a53e0cSJaegeuk Kim } 93239a53e0cSJaegeuk Kim 933119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 934119ee914SJaegeuk Kim { 935119ee914SJaegeuk Kim int reason = CP_SYNC; 936119ee914SJaegeuk Kim 937119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 938119ee914SJaegeuk Kim reason = CP_FASTBOOT; 939119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 940119ee914SJaegeuk Kim reason = CP_UMOUNT; 941119ee914SJaegeuk Kim return reason; 942119ee914SJaegeuk Kim } 943119ee914SJaegeuk Kim 944119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 945119ee914SJaegeuk Kim { 946119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 947119ee914SJaegeuk Kim } 948119ee914SJaegeuk Kim 949119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 950119ee914SJaegeuk Kim { 951119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 952119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 953119ee914SJaegeuk Kim } 954119ee914SJaegeuk Kim 95539a53e0cSJaegeuk Kim /* 95639a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 95739a53e0cSJaegeuk Kim */ 958064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 95939a53e0cSJaegeuk Kim { 960d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 961d6b7d4b3SChao Yu return -EINVAL; 962cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 963064e0823SNamjae Jeon return -EINVAL; 964064e0823SNamjae Jeon return 0; 96539a53e0cSJaegeuk Kim } 96639a53e0cSJaegeuk Kim 96739a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 96839a53e0cSJaegeuk Kim 96939a53e0cSJaegeuk Kim /* 97039a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 97139a53e0cSJaegeuk Kim */ 97239a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 97339a53e0cSJaegeuk Kim { 97439a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 9756c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 97639a53e0cSJaegeuk Kim else 9776c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 97839a53e0cSJaegeuk Kim } 97939a53e0cSJaegeuk Kim 9804bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 9814bc8e9bcSChao Yu { 9824bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 9834bc8e9bcSChao Yu } 9844bc8e9bcSChao Yu 98539a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 98639a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 98739a53e0cSJaegeuk Kim { 98839a53e0cSJaegeuk Kim block_t valid_block_count; 98939a53e0cSJaegeuk Kim 99039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 99139a53e0cSJaegeuk Kim valid_block_count = 99239a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 993cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 99439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 99539a53e0cSJaegeuk Kim return false; 99639a53e0cSJaegeuk Kim } 99739a53e0cSJaegeuk Kim inode->i_blocks += count; 99839a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 99939a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 100039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 100139a53e0cSJaegeuk Kim return true; 100239a53e0cSJaegeuk Kim } 100339a53e0cSJaegeuk Kim 1004da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 100539a53e0cSJaegeuk Kim struct inode *inode, 100639a53e0cSJaegeuk Kim blkcnt_t count) 100739a53e0cSJaegeuk Kim { 100839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 10099850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 10109850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 101139a53e0cSJaegeuk Kim inode->i_blocks -= count; 101239a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 101339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 101439a53e0cSJaegeuk Kim } 101539a53e0cSJaegeuk Kim 101639a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 101739a53e0cSJaegeuk Kim { 101839a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 1019caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 102039a53e0cSJaegeuk Kim } 102139a53e0cSJaegeuk Kim 1022a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 102339a53e0cSJaegeuk Kim { 1024a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1025a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10264081363fSJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 102739a53e0cSJaegeuk Kim } 102839a53e0cSJaegeuk Kim 102939a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 103039a53e0cSJaegeuk Kim { 103139a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 103239a53e0cSJaegeuk Kim } 103339a53e0cSJaegeuk Kim 1034a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 103539a53e0cSJaegeuk Kim { 1036a7ffdbe2SJaegeuk Kim if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)) 10371fe54f9dSJaegeuk Kim return; 10381fe54f9dSJaegeuk Kim 1039a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1040a7ffdbe2SJaegeuk Kim 1041a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10424081363fSJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 104339a53e0cSJaegeuk Kim } 104439a53e0cSJaegeuk Kim 104539a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 104639a53e0cSJaegeuk Kim { 104739a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 104839a53e0cSJaegeuk Kim } 104939a53e0cSJaegeuk Kim 1050a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1051f8b2c1f9SJaegeuk Kim { 1052a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1053f8b2c1f9SJaegeuk Kim } 1054f8b2c1f9SJaegeuk Kim 10555ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 10565ac206cfSNamjae Jeon { 10575ac206cfSNamjae Jeon unsigned int pages_per_sec = sbi->segs_per_sec * 10585ac206cfSNamjae Jeon (1 << sbi->log_blocks_per_seg); 10595ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 10605ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 10615ac206cfSNamjae Jeon } 10625ac206cfSNamjae Jeon 106339a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 106439a53e0cSJaegeuk Kim { 10658b8343faSJaegeuk Kim return sbi->total_valid_block_count; 106639a53e0cSJaegeuk Kim } 106739a53e0cSJaegeuk Kim 106839a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 106939a53e0cSJaegeuk Kim { 107039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 107139a53e0cSJaegeuk Kim 107239a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 107339a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 107439a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 107539a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 107639a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 107739a53e0cSJaegeuk Kim 107839a53e0cSJaegeuk Kim return 0; 107939a53e0cSJaegeuk Kim } 108039a53e0cSJaegeuk Kim 108155141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 108255141486SWanpeng Li { 108355141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 108455141486SWanpeng Li } 108555141486SWanpeng Li 108639a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 108739a53e0cSJaegeuk Kim { 108839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 10891dbe4152SChangman Lee int offset; 10901dbe4152SChangman Lee 109155141486SWanpeng Li if (__cp_payload(sbi) > 0) { 10921dbe4152SChangman Lee if (flag == NAT_BITMAP) 10931dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 10941dbe4152SChangman Lee else 109565b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 10961dbe4152SChangman Lee } else { 10971dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 109825ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 109939a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 110039a53e0cSJaegeuk Kim } 11011dbe4152SChangman Lee } 110239a53e0cSJaegeuk Kim 110339a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 110439a53e0cSJaegeuk Kim { 110539a53e0cSJaegeuk Kim block_t start_addr; 110639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1107d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 110839a53e0cSJaegeuk Kim 110925ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 111039a53e0cSJaegeuk Kim 111139a53e0cSJaegeuk Kim /* 111239a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1113e1c42045Sarter97 * and even segment must be at cp segment 1 111439a53e0cSJaegeuk Kim */ 111539a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 111639a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 111739a53e0cSJaegeuk Kim 111839a53e0cSJaegeuk Kim return start_addr; 111939a53e0cSJaegeuk Kim } 112039a53e0cSJaegeuk Kim 112139a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 112239a53e0cSJaegeuk Kim { 112339a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 112439a53e0cSJaegeuk Kim } 112539a53e0cSJaegeuk Kim 112639a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1127ef86d709SGu Zheng struct inode *inode) 112839a53e0cSJaegeuk Kim { 112939a53e0cSJaegeuk Kim block_t valid_block_count; 113039a53e0cSJaegeuk Kim unsigned int valid_node_count; 113139a53e0cSJaegeuk Kim 113239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 113339a53e0cSJaegeuk Kim 1134ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1135cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 113639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 113739a53e0cSJaegeuk Kim return false; 113839a53e0cSJaegeuk Kim } 113939a53e0cSJaegeuk Kim 1140ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1141cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 114239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 114339a53e0cSJaegeuk Kim return false; 114439a53e0cSJaegeuk Kim } 114539a53e0cSJaegeuk Kim 114639a53e0cSJaegeuk Kim if (inode) 1147ef86d709SGu Zheng inode->i_blocks++; 1148ef86d709SGu Zheng 1149ef86d709SGu Zheng sbi->alloc_valid_block_count++; 1150ef86d709SGu Zheng sbi->total_valid_node_count++; 1151ef86d709SGu Zheng sbi->total_valid_block_count++; 115239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 115339a53e0cSJaegeuk Kim 115439a53e0cSJaegeuk Kim return true; 115539a53e0cSJaegeuk Kim } 115639a53e0cSJaegeuk Kim 115739a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1158ef86d709SGu Zheng struct inode *inode) 115939a53e0cSJaegeuk Kim { 116039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 116139a53e0cSJaegeuk Kim 11629850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 11639850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 11649850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 116539a53e0cSJaegeuk Kim 1166ef86d709SGu Zheng inode->i_blocks--; 1167ef86d709SGu Zheng sbi->total_valid_node_count--; 1168ef86d709SGu Zheng sbi->total_valid_block_count--; 116939a53e0cSJaegeuk Kim 117039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 117139a53e0cSJaegeuk Kim } 117239a53e0cSJaegeuk Kim 117339a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 117439a53e0cSJaegeuk Kim { 11758b8343faSJaegeuk Kim return sbi->total_valid_node_count; 117639a53e0cSJaegeuk Kim } 117739a53e0cSJaegeuk Kim 117839a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 117939a53e0cSJaegeuk Kim { 118039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 11819850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 118239a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 118339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 118439a53e0cSJaegeuk Kim } 118539a53e0cSJaegeuk Kim 11860e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 118739a53e0cSJaegeuk Kim { 118839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 11899850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 119039a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 119139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 119239a53e0cSJaegeuk Kim } 119339a53e0cSJaegeuk Kim 119439a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 119539a53e0cSJaegeuk Kim { 11968b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 119739a53e0cSJaegeuk Kim } 119839a53e0cSJaegeuk Kim 119939a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 120039a53e0cSJaegeuk Kim { 1201031fa8ccSJaegeuk Kim if (!page) 120239a53e0cSJaegeuk Kim return; 120339a53e0cSJaegeuk Kim 120439a53e0cSJaegeuk Kim if (unlock) { 12059850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 120639a53e0cSJaegeuk Kim unlock_page(page); 120739a53e0cSJaegeuk Kim } 120839a53e0cSJaegeuk Kim page_cache_release(page); 120939a53e0cSJaegeuk Kim } 121039a53e0cSJaegeuk Kim 121139a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 121239a53e0cSJaegeuk Kim { 121339a53e0cSJaegeuk Kim if (dn->node_page) 121439a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 121539a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 121639a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 121739a53e0cSJaegeuk Kim dn->node_page = NULL; 121839a53e0cSJaegeuk Kim dn->inode_page = NULL; 121939a53e0cSJaegeuk Kim } 122039a53e0cSJaegeuk Kim 122139a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1222e8512d2eSGu Zheng size_t size) 122339a53e0cSJaegeuk Kim { 1224e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 122539a53e0cSJaegeuk Kim } 122639a53e0cSJaegeuk Kim 12277bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 12287bd59381SGu Zheng gfp_t flags) 12297bd59381SGu Zheng { 12307bd59381SGu Zheng void *entry; 12317bd59381SGu Zheng retry: 12327bd59381SGu Zheng entry = kmem_cache_alloc(cachep, flags); 12337bd59381SGu Zheng if (!entry) { 12347bd59381SGu Zheng cond_resched(); 12357bd59381SGu Zheng goto retry; 12367bd59381SGu Zheng } 12377bd59381SGu Zheng 12387bd59381SGu Zheng return entry; 12397bd59381SGu Zheng } 12407bd59381SGu Zheng 12419be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 12429be32d72SJaegeuk Kim unsigned long index, void *item) 12439be32d72SJaegeuk Kim { 12449be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 12459be32d72SJaegeuk Kim cond_resched(); 12469be32d72SJaegeuk Kim } 12479be32d72SJaegeuk Kim 124839a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 124939a53e0cSJaegeuk Kim 125039a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 125139a53e0cSJaegeuk Kim { 125245590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 125339a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 125439a53e0cSJaegeuk Kim } 125539a53e0cSJaegeuk Kim 125639a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 125739a53e0cSJaegeuk Kim { 125839a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 125939a53e0cSJaegeuk Kim } 126039a53e0cSJaegeuk Kim 126139a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 126239a53e0cSJaegeuk Kim unsigned int offset) 126339a53e0cSJaegeuk Kim { 126439a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 126539a53e0cSJaegeuk Kim __le32 *addr_array; 126645590710SGu Zheng raw_node = F2FS_NODE(node_page); 126739a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 126839a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 126939a53e0cSJaegeuk Kim } 127039a53e0cSJaegeuk Kim 127139a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 127239a53e0cSJaegeuk Kim { 127339a53e0cSJaegeuk Kim int mask; 127439a53e0cSJaegeuk Kim 127539a53e0cSJaegeuk Kim addr += (nr >> 3); 127639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 127739a53e0cSJaegeuk Kim return mask & *addr; 127839a53e0cSJaegeuk Kim } 127939a53e0cSJaegeuk Kim 1280a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1281a66cdd98SJaegeuk Kim { 1282a66cdd98SJaegeuk Kim int mask; 1283a66cdd98SJaegeuk Kim 1284a66cdd98SJaegeuk Kim addr += (nr >> 3); 1285a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1286a66cdd98SJaegeuk Kim *addr |= mask; 1287a66cdd98SJaegeuk Kim } 1288a66cdd98SJaegeuk Kim 1289a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1290a66cdd98SJaegeuk Kim { 1291a66cdd98SJaegeuk Kim int mask; 1292a66cdd98SJaegeuk Kim 1293a66cdd98SJaegeuk Kim addr += (nr >> 3); 1294a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1295a66cdd98SJaegeuk Kim *addr &= ~mask; 1296a66cdd98SJaegeuk Kim } 1297a66cdd98SJaegeuk Kim 129852aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 129939a53e0cSJaegeuk Kim { 130039a53e0cSJaegeuk Kim int mask; 130139a53e0cSJaegeuk Kim int ret; 130239a53e0cSJaegeuk Kim 130339a53e0cSJaegeuk Kim addr += (nr >> 3); 130439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 130539a53e0cSJaegeuk Kim ret = mask & *addr; 130639a53e0cSJaegeuk Kim *addr |= mask; 130739a53e0cSJaegeuk Kim return ret; 130839a53e0cSJaegeuk Kim } 130939a53e0cSJaegeuk Kim 131052aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 131139a53e0cSJaegeuk Kim { 131239a53e0cSJaegeuk Kim int mask; 131339a53e0cSJaegeuk Kim int ret; 131439a53e0cSJaegeuk Kim 131539a53e0cSJaegeuk Kim addr += (nr >> 3); 131639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 131739a53e0cSJaegeuk Kim ret = mask & *addr; 131839a53e0cSJaegeuk Kim *addr &= ~mask; 131939a53e0cSJaegeuk Kim return ret; 132039a53e0cSJaegeuk Kim } 132139a53e0cSJaegeuk Kim 1322c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1323c6ac4c0eSGu Zheng { 1324c6ac4c0eSGu Zheng int mask; 1325c6ac4c0eSGu Zheng 1326c6ac4c0eSGu Zheng addr += (nr >> 3); 1327c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1328c6ac4c0eSGu Zheng *addr ^= mask; 1329c6ac4c0eSGu Zheng } 1330c6ac4c0eSGu Zheng 133139a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 133239a53e0cSJaegeuk Kim enum { 133339a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1334b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1335ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 133639a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 133739a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 133839a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1339699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 134074d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1341c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1342444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 13431001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 134434d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1345fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1346fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 134788b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 134888b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 134902a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 13503c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 13511e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1352b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1353510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 135439a53e0cSJaegeuk Kim }; 135539a53e0cSJaegeuk Kim 135639a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 135739a53e0cSJaegeuk Kim { 135861e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 135939a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 136039a53e0cSJaegeuk Kim } 136139a53e0cSJaegeuk Kim 136239a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 136339a53e0cSJaegeuk Kim { 136439a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 136539a53e0cSJaegeuk Kim } 136639a53e0cSJaegeuk Kim 136739a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 136839a53e0cSJaegeuk Kim { 136961e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 137039a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 137139a53e0cSJaegeuk Kim } 137239a53e0cSJaegeuk Kim 137339a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 137439a53e0cSJaegeuk Kim { 137539a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 137639a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 137739a53e0cSJaegeuk Kim } 137839a53e0cSJaegeuk Kim 1379444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1380444c580fSJaegeuk Kim struct f2fs_inode *ri) 1381444c580fSJaegeuk Kim { 1382444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1383444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 13841001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 13851001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 138634d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 138734d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1388b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1389b3d208f9SJaegeuk Kim set_inode_flag(fi, FI_DATA_EXIST); 1390510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1391510022a8SJaegeuk Kim set_inode_flag(fi, FI_INLINE_DOTS); 1392444c580fSJaegeuk Kim } 1393444c580fSJaegeuk Kim 1394444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1395444c580fSJaegeuk Kim struct f2fs_inode *ri) 1396444c580fSJaegeuk Kim { 1397444c580fSJaegeuk Kim ri->i_inline = 0; 1398444c580fSJaegeuk Kim 1399444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1400444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 14011001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 14021001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 140334d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 140434d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1405b3d208f9SJaegeuk Kim if (is_inode_flag_set(fi, FI_DATA_EXIST)) 1406b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1407510022a8SJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_DOTS)) 1408510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1409444c580fSJaegeuk Kim } 1410444c580fSJaegeuk Kim 1411987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1412987c7c31SChao Yu { 1413987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1414987c7c31SChao Yu } 1415987c7c31SChao Yu 1416de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1417de93653fSJaegeuk Kim { 1418987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1419de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1420de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1421de93653fSJaegeuk Kim } 1422de93653fSJaegeuk Kim 142365985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 142465985d93SJaegeuk Kim { 1425695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 142665985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 142765985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 142865985d93SJaegeuk Kim } 142965985d93SJaegeuk Kim 143065985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 143165985d93SJaegeuk Kim { 1432987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 143365985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 143465985d93SJaegeuk Kim else 143565985d93SJaegeuk Kim return 0; 143665985d93SJaegeuk Kim } 143765985d93SJaegeuk Kim 14380dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 14390dbdc2aeSJaegeuk Kim { 14400dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 14410dbdc2aeSJaegeuk Kim } 14420dbdc2aeSJaegeuk Kim 1443b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1444b3d208f9SJaegeuk Kim { 1445b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 1446b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1447b3d208f9SJaegeuk Kim } 1448b3d208f9SJaegeuk Kim 1449b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1450b3d208f9SJaegeuk Kim { 1451b3d208f9SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST); 1452b3d208f9SJaegeuk Kim } 1453b3d208f9SJaegeuk Kim 1454510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1455510022a8SJaegeuk Kim { 1456510022a8SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS); 1457510022a8SJaegeuk Kim } 1458510022a8SJaegeuk Kim 145988b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 146088b88a66SJaegeuk Kim { 146188b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 146288b88a66SJaegeuk Kim } 146388b88a66SJaegeuk Kim 146402a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 146502a1335fSJaegeuk Kim { 146602a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 146702a1335fSJaegeuk Kim } 146802a1335fSJaegeuk Kim 14693c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 14703c6c2bebSJaegeuk Kim { 14713c6c2bebSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); 14723c6c2bebSJaegeuk Kim } 14733c6c2bebSJaegeuk Kim 14741e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 14751e84371fSJaegeuk Kim { 14761e84371fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE); 14771e84371fSJaegeuk Kim } 14781e84371fSJaegeuk Kim 14791001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 14801001b347SHuajun Li { 1481695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 14821001b347SHuajun Li return (void *)&(ri->i_addr[1]); 14831001b347SHuajun Li } 14841001b347SHuajun Li 148534d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 148634d67debSChao Yu { 148734d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 148834d67debSChao Yu } 148934d67debSChao Yu 14909486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 14919486ba44SJaegeuk Kim { 14929486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 14939486ba44SJaegeuk Kim kunmap(page); 14949486ba44SJaegeuk Kim } 14959486ba44SJaegeuk Kim 1496b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1497b5492af7SJaegeuk Kim { 1498b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1499b5492af7SJaegeuk Kim } 1500b5492af7SJaegeuk Kim 1501b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1502b5492af7SJaegeuk Kim { 1503b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1504b5492af7SJaegeuk Kim } 1505b5492af7SJaegeuk Kim 1506b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1507b5492af7SJaegeuk Kim { 1508b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1509b5492af7SJaegeuk Kim } 1510b5492af7SJaegeuk Kim 151177888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 151277888c1eSJaegeuk Kim { 151377888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 151477888c1eSJaegeuk Kim } 151577888c1eSJaegeuk Kim 15161e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 15171e968fdfSJaegeuk Kim { 15181e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 15191e968fdfSJaegeuk Kim } 15201e968fdfSJaegeuk Kim 1521744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1522744602cfSJaegeuk Kim { 1523744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1524744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1525744602cfSJaegeuk Kim } 1526744602cfSJaegeuk Kim 1527eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1528eaa693f4SJaegeuk Kim { 1529eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1530eaa693f4SJaegeuk Kim return true; 1531eaa693f4SJaegeuk Kim 1532eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1533eaa693f4SJaegeuk Kim return true; 1534eaa693f4SJaegeuk Kim 1535eaa693f4SJaegeuk Kim return false; 1536eaa693f4SJaegeuk Kim } 1537eaa693f4SJaegeuk Kim 1538a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1539a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1540a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1541a6dda0e6SChristoph Hellwig 1542267378d4SChao Yu /* get offset of first page in next direct node */ 1543267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1544267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1545267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1546267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1547267378d4SChao Yu 154839a53e0cSJaegeuk Kim /* 154939a53e0cSJaegeuk Kim * file.c 155039a53e0cSJaegeuk Kim */ 155139a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 155239a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1553764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 155439a53e0cSJaegeuk Kim void f2fs_truncate(struct inode *); 15552d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 155639a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 155739a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1558b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 155939a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1560e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 156139a53e0cSJaegeuk Kim 156239a53e0cSJaegeuk Kim /* 156339a53e0cSJaegeuk Kim * inode.c 156439a53e0cSJaegeuk Kim */ 156539a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 156639a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 15674660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 156839a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *); 1569744602cfSJaegeuk Kim void update_inode_page(struct inode *); 157039a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 157139a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 157244c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 157339a53e0cSJaegeuk Kim 157439a53e0cSJaegeuk Kim /* 157539a53e0cSJaegeuk Kim * namei.c 157639a53e0cSJaegeuk Kim */ 157739a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 157839a53e0cSJaegeuk Kim 157939a53e0cSJaegeuk Kim /* 158039a53e0cSJaegeuk Kim * dir.c 158139a53e0cSJaegeuk Kim */ 1582dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1583510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 15847b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct qstr *, int *, 15857b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr *); 15867b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 15877b3cd7d6SJaegeuk Kim unsigned int); 1588062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1589062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1590dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1591bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1592dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1593a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1594dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 159539a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 159639a53e0cSJaegeuk Kim struct page **); 159739a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 159839a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 159939a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 160039a53e0cSJaegeuk Kim struct page *, struct inode *); 16011cd14cafSJaegeuk Kim int update_dent_inode(struct inode *, const struct qstr *); 1602510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 16033b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1604510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1605510022a8SJaegeuk Kim umode_t); 1606dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1607dbeacf02SChao Yu struct inode *); 1608b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 160939a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 161039a53e0cSJaegeuk Kim 1611b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1612b7f7a5e0SAl Viro { 16132b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1614510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1615b7f7a5e0SAl Viro } 1616b7f7a5e0SAl Viro 161739a53e0cSJaegeuk Kim /* 161839a53e0cSJaegeuk Kim * super.c 161939a53e0cSJaegeuk Kim */ 162026d815adSJaegeuk Kim int f2fs_commit_super(struct f2fs_sb_info *); 162139a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1622a07ef784SNamjae Jeon extern __printf(3, 4) 1623a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 162439a53e0cSJaegeuk Kim 162539a53e0cSJaegeuk Kim /* 162639a53e0cSJaegeuk Kim * hash.c 162739a53e0cSJaegeuk Kim */ 1628eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 162939a53e0cSJaegeuk Kim 163039a53e0cSJaegeuk Kim /* 163139a53e0cSJaegeuk Kim * node.c 163239a53e0cSJaegeuk Kim */ 163339a53e0cSJaegeuk Kim struct dnode_of_data; 163439a53e0cSJaegeuk Kim struct node_info; 163539a53e0cSJaegeuk Kim 16366fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 16372dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t); 163888bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 163988bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 164039a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 164139a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 164239a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 16434f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1644cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 164558e674d6SGu Zheng void remove_inode_page(struct inode *); 1646a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 16478ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 164839a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 164939a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 165039a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 165139a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 165239a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 165339a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 165439a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 165539a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 165670cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 16571c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 165839a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 165939a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 166039a53e0cSJaegeuk Kim struct f2fs_summary_block *); 166139a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 166239a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 166339a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 16646e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 166539a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 166639a53e0cSJaegeuk Kim 166739a53e0cSJaegeuk Kim /* 166839a53e0cSJaegeuk Kim * segment.c 166939a53e0cSJaegeuk Kim */ 167088b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 167188b88a66SJaegeuk Kim void commit_inmem_pages(struct inode *, bool); 167239a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *); 16734660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 16746b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 16752163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 16762163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 167739a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 16785e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 1679836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 16804b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1681cf2271e7SJaegeuk Kim void discard_next_dnode(struct f2fs_sb_info *, block_t); 16823fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 168339a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 16844b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 168539a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1686577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 168705ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 168805ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 168905ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 169019f106bcSChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct f2fs_summary *, 169119f106bcSChao Yu block_t, block_t, bool); 1692bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1693bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 16945514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 169539a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 169639a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 169739a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 169839a53e0cSJaegeuk Kim int, unsigned int, int); 16994b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 170039a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 170139a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 17027fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 17037fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 170439a53e0cSJaegeuk Kim 170539a53e0cSJaegeuk Kim /* 170639a53e0cSJaegeuk Kim * checkpoint.c 170739a53e0cSJaegeuk Kim */ 170839a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 170939a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 1710f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 17114c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int); 1712635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 171339a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1714fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1715fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 17166f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *); 1717fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1718cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1719cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 172039a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 172139a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 17228f99a946SChao Yu void recover_orphan_inodes(struct f2fs_sb_info *); 172339a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1724a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 17255deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 172639a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *); 172739a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *); 172875ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 17296451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 17306e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 173139a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 173239a53e0cSJaegeuk Kim 173339a53e0cSJaegeuk Kim /* 173439a53e0cSJaegeuk Kim * data.c 173539a53e0cSJaegeuk Kim */ 1736458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 173705ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 173805ca3632SJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_io_info *); 1739216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 174039a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1741b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 1742429511cdSChao Yu void f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 1743429511cdSChao Yu void f2fs_destroy_extent_tree(struct inode *); 1744028a41e8SChao Yu void f2fs_init_extent_cache(struct inode *, struct f2fs_extent *); 17457e4dde79SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 17460bdee482SChao Yu void f2fs_preserve_extent_tree(struct inode *); 174743f3eae1SJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int); 174843f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t); 174939a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t); 175064aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 175105ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 17529ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1753429511cdSChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 1754429511cdSChao Yu int __init create_extent_cache(void); 1755429511cdSChao Yu void destroy_extent_cache(void); 1756487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1757487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 175839a53e0cSJaegeuk Kim 175939a53e0cSJaegeuk Kim /* 176039a53e0cSJaegeuk Kim * gc.c 176139a53e0cSJaegeuk Kim */ 176239a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 176339a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1764de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1765408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *); 176639a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 176739a53e0cSJaegeuk Kim 176839a53e0cSJaegeuk Kim /* 176939a53e0cSJaegeuk Kim * recovery.c 177039a53e0cSJaegeuk Kim */ 17716ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 177239a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 177339a53e0cSJaegeuk Kim 177439a53e0cSJaegeuk Kim /* 177539a53e0cSJaegeuk Kim * debug.c 177639a53e0cSJaegeuk Kim */ 177739a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 177839a53e0cSJaegeuk Kim struct f2fs_stat_info { 177939a53e0cSJaegeuk Kim struct list_head stat_list; 178039a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 178139a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 178239a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 17834bf6fd9fSChao Yu int hit_ext, total_ext, ext_tree, ext_node; 178439a53e0cSJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 1785dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 178639a53e0cSJaegeuk Kim int total_count, utilization; 1787d24bdcbfSJaegeuk Kim int bg_gc, inline_inode, inline_dir, inmem_pages, wb_pages; 178839a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 178939a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 179039a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 179139a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 179239a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1793942e0be6SChangman Lee int prefree_count, call_count, cp_count; 179439a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 1795e1235983SChangman Lee int bg_node_segs, bg_data_segs; 179639a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 1797e1235983SChangman Lee int bg_data_blks, bg_node_blks; 179839a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 179939a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 180039a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 180139a53e0cSJaegeuk Kim 180239a53e0cSJaegeuk Kim unsigned int segment_count[2]; 180339a53e0cSJaegeuk Kim unsigned int block_count[2]; 1804b9a2c252SChangman Lee unsigned int inplace_count; 18056f0aacbcSJaegeuk Kim unsigned base_mem, cache_mem, page_mem; 180639a53e0cSJaegeuk Kim }; 180739a53e0cSJaegeuk Kim 1808963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1809963d4f7dSGu Zheng { 1810963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1811963d4f7dSGu Zheng } 1812963d4f7dSGu Zheng 1813942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 181439a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1815dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1816dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1817dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 1818dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++) 1819dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++) 18200dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 18210dbdc2aeSJaegeuk Kim do { \ 18220dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 182303e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 18240dbdc2aeSJaegeuk Kim } while (0) 18250dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 18260dbdc2aeSJaegeuk Kim do { \ 18270dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 182803e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 18290dbdc2aeSJaegeuk Kim } while (0) 18303289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 18313289c061SJaegeuk Kim do { \ 18323289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 183303e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 18343289c061SJaegeuk Kim } while (0) 18353289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 18363289c061SJaegeuk Kim do { \ 18373289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 183803e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 18393289c061SJaegeuk Kim } while (0) 1840dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1841dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1842dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1843dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 1844b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 1845b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 1846e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 184739a53e0cSJaegeuk Kim do { \ 1848963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 184939a53e0cSJaegeuk Kim (si)->tot_segs++; \ 1850e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 185139a53e0cSJaegeuk Kim si->data_segs++; \ 1852e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 1853e1235983SChangman Lee } else { \ 185439a53e0cSJaegeuk Kim si->node_segs++; \ 1855e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 1856e1235983SChangman Lee } \ 185739a53e0cSJaegeuk Kim } while (0) 185839a53e0cSJaegeuk Kim 185939a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 186039a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 186139a53e0cSJaegeuk Kim 1862e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 186339a53e0cSJaegeuk Kim do { \ 1864963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 186539a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 186639a53e0cSJaegeuk Kim si->data_blks += (blks); \ 1867e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 186839a53e0cSJaegeuk Kim } while (0) 186939a53e0cSJaegeuk Kim 1870e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 187139a53e0cSJaegeuk Kim do { \ 1872963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 187339a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 187439a53e0cSJaegeuk Kim si->node_blks += (blks); \ 1875e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 187639a53e0cSJaegeuk Kim } while (0) 187739a53e0cSJaegeuk Kim 187839a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 187939a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 18806e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void); 18814589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 188239a53e0cSJaegeuk Kim #else 1883942e0be6SChangman Lee #define stat_inc_cp_count(si) 188439a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 1885dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 1886dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) 1887dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) 1888dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 1889dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) 18900dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 18910dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 18923289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 18933289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 1894dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 1895dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 1896b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 1897e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 189839a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 1899e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 1900e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 190139a53e0cSJaegeuk Kim 190239a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 190339a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 19046e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { } 19054589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 190639a53e0cSJaegeuk Kim #endif 190739a53e0cSJaegeuk Kim 190839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 190939a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 191039a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 191139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 191239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 191339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 191439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 191539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 191639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 191729e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 19181001b347SHuajun Li 1919e18c65b2SHuajun Li /* 1920e18c65b2SHuajun Li * inline.c 1921e18c65b2SHuajun Li */ 192201b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 192301b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 1924b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 19250bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 1926e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 1927b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 1928b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 1929b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 19300342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 1931201a05beSChao Yu struct f2fs_dir_entry *find_in_inline_dir(struct inode *, struct qstr *, 1932201a05beSChao Yu struct page **); 1933201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 1934201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 1935510022a8SJaegeuk Kim int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 1936510022a8SJaegeuk Kim nid_t, umode_t); 1937201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 1938201a05beSChao Yu struct inode *, struct inode *); 1939201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 1940201a05beSChao Yu int f2fs_read_inline_dir(struct file *, struct dir_context *); 1941cde4de12SJaegeuk Kim 1942cde4de12SJaegeuk Kim /* 1943cde4de12SJaegeuk Kim * crypto support 1944cde4de12SJaegeuk Kim */ 1945cde4de12SJaegeuk Kim static inline int f2fs_encrypted_inode(struct inode *inode) 1946cde4de12SJaegeuk Kim { 1947cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 1948cde4de12SJaegeuk Kim return file_is_encrypt(inode); 1949cde4de12SJaegeuk Kim #else 1950cde4de12SJaegeuk Kim return 0; 1951cde4de12SJaegeuk Kim #endif 1952cde4de12SJaegeuk Kim } 1953cde4de12SJaegeuk Kim 1954cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 1955cde4de12SJaegeuk Kim { 1956cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 1957cde4de12SJaegeuk Kim file_set_encrypt(inode); 1958cde4de12SJaegeuk Kim #endif 1959cde4de12SJaegeuk Kim } 1960cde4de12SJaegeuk Kim 1961cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 1962cde4de12SJaegeuk Kim { 1963cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 1964cde4de12SJaegeuk Kim return unlikely(bio->bi_private != NULL); 1965cde4de12SJaegeuk Kim #else 1966cde4de12SJaegeuk Kim return false; 1967cde4de12SJaegeuk Kim #endif 1968cde4de12SJaegeuk Kim } 1969cde4de12SJaegeuk Kim 1970cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 1971cde4de12SJaegeuk Kim { 1972cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 1973cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 1974cde4de12SJaegeuk Kim #else 1975cde4de12SJaegeuk Kim return 0; 1976cde4de12SJaegeuk Kim #endif 1977cde4de12SJaegeuk Kim } 1978f424f664SJaegeuk Kim 1979fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 1980fcc85a4dSJaegeuk Kim { 1981fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 1982fcc85a4dSJaegeuk Kim mode_t mode = inode->i_mode; 1983fcc85a4dSJaegeuk Kim 1984fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 1985fcc85a4dSJaegeuk Kim #else 1986fcc85a4dSJaegeuk Kim return 0; 1987fcc85a4dSJaegeuk Kim #endif 1988fcc85a4dSJaegeuk Kim } 1989fcc85a4dSJaegeuk Kim 1990f424f664SJaegeuk Kim /* crypto_policy.c */ 1991f424f664SJaegeuk Kim int f2fs_is_child_context_consistent_with_parent(struct inode *, 1992f424f664SJaegeuk Kim struct inode *); 1993f424f664SJaegeuk Kim int f2fs_inherit_context(struct inode *, struct inode *, struct page *); 1994f424f664SJaegeuk Kim int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *); 1995f424f664SJaegeuk Kim int f2fs_get_policy(struct inode *, struct f2fs_encryption_policy *); 199657e5055bSJaegeuk Kim 199757e5055bSJaegeuk Kim /* crypt.c */ 199857e5055bSJaegeuk Kim extern struct workqueue_struct *f2fs_read_workqueue; 199957e5055bSJaegeuk Kim bool f2fs_valid_contents_enc_mode(uint32_t); 200057e5055bSJaegeuk Kim uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t); 200157e5055bSJaegeuk Kim struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *); 200257e5055bSJaegeuk Kim void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *); 200357e5055bSJaegeuk Kim struct page *f2fs_encrypt(struct inode *, struct page *); 200457e5055bSJaegeuk Kim int f2fs_decrypt(struct f2fs_crypto_ctx *, struct page *); 200557e5055bSJaegeuk Kim int f2fs_decrypt_one(struct inode *, struct page *); 200657e5055bSJaegeuk Kim void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *); 200757e5055bSJaegeuk Kim 20080adda907SJaegeuk Kim /* crypto_key.c */ 20090adda907SJaegeuk Kim void f2fs_free_encryption_info(struct inode *); 20100adda907SJaegeuk Kim int _f2fs_get_encryption_info(struct inode *inode); 20110adda907SJaegeuk Kim 20126b3bd08fSJaegeuk Kim /* crypto_fname.c */ 20136b3bd08fSJaegeuk Kim bool f2fs_valid_filenames_enc_mode(uint32_t); 20146b3bd08fSJaegeuk Kim u32 f2fs_fname_crypto_round_up(u32, u32); 20156b3bd08fSJaegeuk Kim int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *); 20166b3bd08fSJaegeuk Kim int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *, 20176b3bd08fSJaegeuk Kim const struct f2fs_str *, struct f2fs_str *); 20186b3bd08fSJaegeuk Kim int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *, 20196b3bd08fSJaegeuk Kim struct f2fs_str *); 20206b3bd08fSJaegeuk Kim 202157e5055bSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 202257e5055bSJaegeuk Kim void f2fs_restore_and_release_control_page(struct page **); 202357e5055bSJaegeuk Kim void f2fs_restore_control_page(struct page *); 202457e5055bSJaegeuk Kim 202557e5055bSJaegeuk Kim int f2fs_init_crypto(void); 202657e5055bSJaegeuk Kim void f2fs_exit_crypto(void); 20270adda907SJaegeuk Kim 20280adda907SJaegeuk Kim int f2fs_has_encryption_key(struct inode *); 20290adda907SJaegeuk Kim 20300adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *inode) 20310adda907SJaegeuk Kim { 20320adda907SJaegeuk Kim struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info; 20330adda907SJaegeuk Kim 20340adda907SJaegeuk Kim if (!ci || 20350adda907SJaegeuk Kim (ci->ci_keyring_key && 20360adda907SJaegeuk Kim (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | 20370adda907SJaegeuk Kim (1 << KEY_FLAG_REVOKED) | 20380adda907SJaegeuk Kim (1 << KEY_FLAG_DEAD))))) 20390adda907SJaegeuk Kim return _f2fs_get_encryption_info(inode); 20400adda907SJaegeuk Kim return 0; 20410adda907SJaegeuk Kim } 20426b3bd08fSJaegeuk Kim 20436b3bd08fSJaegeuk Kim int f2fs_setup_fname_crypto(struct inode *); 20446b3bd08fSJaegeuk Kim void f2fs_fname_crypto_free_buffer(struct f2fs_str *); 20456b3bd08fSJaegeuk Kim int f2fs_fname_setup_filename(struct inode *, const struct qstr *, 20466b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *); 20476b3bd08fSJaegeuk Kim void f2fs_fname_free_filename(struct f2fs_filename *); 204857e5055bSJaegeuk Kim #else 204957e5055bSJaegeuk Kim static inline void f2fs_restore_and_release_control_page(struct page **p) { } 205057e5055bSJaegeuk Kim static inline void f2fs_restore_control_page(struct page *p) { } 205157e5055bSJaegeuk Kim 205257e5055bSJaegeuk Kim static inline int f2fs_init_crypto(void) { return 0; } 205357e5055bSJaegeuk Kim static inline void f2fs_exit_crypto(void) { } 20540adda907SJaegeuk Kim 20550adda907SJaegeuk Kim static inline int f2fs_has_encryption_key(struct inode *i) { return 0; } 20560adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *i) { return 0; } 20576b3bd08fSJaegeuk Kim 20586b3bd08fSJaegeuk Kim static inline int f2fs_setup_fname_crypto(struct inode *i) { return 0; } 20596b3bd08fSJaegeuk Kim static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { } 20606b3bd08fSJaegeuk Kim 20616b3bd08fSJaegeuk Kim static inline int f2fs_fname_setup_filename(struct inode *dir, 20626b3bd08fSJaegeuk Kim const struct qstr *iname, 20636b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *fname) 20646b3bd08fSJaegeuk Kim { 20656b3bd08fSJaegeuk Kim memset(fname, 0, sizeof(struct f2fs_filename)); 20666b3bd08fSJaegeuk Kim fname->usr_fname = iname; 20676b3bd08fSJaegeuk Kim fname->disk_name.name = (unsigned char *)iname->name; 20686b3bd08fSJaegeuk Kim fname->disk_name.len = iname->len; 20696b3bd08fSJaegeuk Kim return 0; 20706b3bd08fSJaegeuk Kim } 20716b3bd08fSJaegeuk Kim 20726b3bd08fSJaegeuk Kim static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { } 207357e5055bSJaegeuk Kim #endif 207439a53e0cSJaegeuk Kim #endif 2075