10a8165d7SJaegeuk Kim /* 239a53e0cSJaegeuk Kim * fs/f2fs/f2fs.h 339a53e0cSJaegeuk Kim * 439a53e0cSJaegeuk Kim * Copyright (c) 2012 Samsung Electronics Co., Ltd. 539a53e0cSJaegeuk Kim * http://www.samsung.com/ 639a53e0cSJaegeuk Kim * 739a53e0cSJaegeuk Kim * This program is free software; you can redistribute it and/or modify 839a53e0cSJaegeuk Kim * it under the terms of the GNU General Public License version 2 as 939a53e0cSJaegeuk Kim * published by the Free Software Foundation. 1039a53e0cSJaegeuk Kim */ 1139a53e0cSJaegeuk Kim #ifndef _LINUX_F2FS_H 1239a53e0cSJaegeuk Kim #define _LINUX_F2FS_H 1339a53e0cSJaegeuk Kim 1439a53e0cSJaegeuk Kim #include <linux/types.h> 1539a53e0cSJaegeuk Kim #include <linux/page-flags.h> 1639a53e0cSJaegeuk Kim #include <linux/buffer_head.h> 1739a53e0cSJaegeuk Kim #include <linux/slab.h> 1839a53e0cSJaegeuk Kim #include <linux/crc32.h> 1939a53e0cSJaegeuk Kim #include <linux/magic.h> 20c2d715d1SJaegeuk Kim #include <linux/kobject.h> 217bd59381SGu Zheng #include <linux/sched.h> 22740432f8SJaegeuk Kim #include <linux/bio.h> 2339a53e0cSJaegeuk Kim 245d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 259850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 260daaad97SJaegeuk Kim #define f2fs_down_write(x, y) down_write_nest_lock(x, y) 275d56b671SJaegeuk Kim #else 289850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 299850cf4aSJaegeuk Kim do { \ 309850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 319850cf4aSJaegeuk Kim WARN_ON(1); \ 32caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 339850cf4aSJaegeuk Kim } \ 349850cf4aSJaegeuk Kim } while (0) 350daaad97SJaegeuk Kim #define f2fs_down_write(x, y) down_write(x) 365d56b671SJaegeuk Kim #endif 375d56b671SJaegeuk Kim 3839a53e0cSJaegeuk Kim /* 3939a53e0cSJaegeuk Kim * For mount options 4039a53e0cSJaegeuk Kim */ 4139a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 4239a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 4339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 4439a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 4539a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 4639a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 4739a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 48444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 491001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 5034d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 5134d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 5234d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 53d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 5489672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 5539a53e0cSJaegeuk Kim 5639a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 5739a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 5839a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 5939a53e0cSJaegeuk Kim 6039a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 6139a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 6239a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 6339a53e0cSJaegeuk Kim 64a9841c4dSJaegeuk Kim typedef u32 block_t; /* 65a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 66a9841c4dSJaegeuk Kim * address format, __le32. 67a9841c4dSJaegeuk Kim */ 6839a53e0cSJaegeuk Kim typedef u32 nid_t; 6939a53e0cSJaegeuk Kim 7039a53e0cSJaegeuk Kim struct f2fs_mount_info { 7139a53e0cSJaegeuk Kim unsigned int opt; 7239a53e0cSJaegeuk Kim }; 7339a53e0cSJaegeuk Kim 74cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 75cde4de12SJaegeuk Kim 7676f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 7776f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 7876f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 7976f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask) 8076f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 8176f105a2SJaegeuk Kim F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask) 8276f105a2SJaegeuk Kim 837e586fa0SJaegeuk Kim #define CRCPOLY_LE 0xedb88320 847e586fa0SJaegeuk Kim 857e586fa0SJaegeuk Kim static inline __u32 f2fs_crc32(void *buf, size_t len) 8639a53e0cSJaegeuk Kim { 877e586fa0SJaegeuk Kim unsigned char *p = (unsigned char *)buf; 887e586fa0SJaegeuk Kim __u32 crc = F2FS_SUPER_MAGIC; 897e586fa0SJaegeuk Kim int i; 907e586fa0SJaegeuk Kim 917e586fa0SJaegeuk Kim while (len--) { 927e586fa0SJaegeuk Kim crc ^= *p++; 937e586fa0SJaegeuk Kim for (i = 0; i < 8; i++) 947e586fa0SJaegeuk Kim crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); 957e586fa0SJaegeuk Kim } 967e586fa0SJaegeuk Kim return crc; 9739a53e0cSJaegeuk Kim } 9839a53e0cSJaegeuk Kim 997e586fa0SJaegeuk Kim static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size) 10039a53e0cSJaegeuk Kim { 1017e586fa0SJaegeuk Kim return f2fs_crc32(buf, buf_size) == blk_crc; 10239a53e0cSJaegeuk Kim } 10339a53e0cSJaegeuk Kim 10439a53e0cSJaegeuk Kim /* 10539a53e0cSJaegeuk Kim * For checkpoint manager 10639a53e0cSJaegeuk Kim */ 10739a53e0cSJaegeuk Kim enum { 10839a53e0cSJaegeuk Kim NAT_BITMAP, 10939a53e0cSJaegeuk Kim SIT_BITMAP 11039a53e0cSJaegeuk Kim }; 11139a53e0cSJaegeuk Kim 11275ab4cb8SJaegeuk Kim enum { 11375ab4cb8SJaegeuk Kim CP_UMOUNT, 114119ee914SJaegeuk Kim CP_FASTBOOT, 11575ab4cb8SJaegeuk Kim CP_SYNC, 11610027551SJaegeuk Kim CP_RECOVERY, 1174b2fecc8SJaegeuk Kim CP_DISCARD, 11875ab4cb8SJaegeuk Kim }; 11975ab4cb8SJaegeuk Kim 120bba681cbSJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 32 121bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 122bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 123a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 124a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 125bba681cbSJaegeuk Kim 12675ab4cb8SJaegeuk Kim struct cp_control { 12775ab4cb8SJaegeuk Kim int reason; 1284b2fecc8SJaegeuk Kim __u64 trim_start; 1294b2fecc8SJaegeuk Kim __u64 trim_end; 1304b2fecc8SJaegeuk Kim __u64 trim_minlen; 1314b2fecc8SJaegeuk Kim __u64 trimmed; 13275ab4cb8SJaegeuk Kim }; 13375ab4cb8SJaegeuk Kim 134662befdaSChao Yu /* 13581c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 136662befdaSChao Yu */ 137662befdaSChao Yu enum { 138662befdaSChao Yu META_CP, 139662befdaSChao Yu META_NAT, 14081c1a0f1SChao Yu META_SIT, 1414c521f49SJaegeuk Kim META_SSA, 1424c521f49SJaegeuk Kim META_POR, 143662befdaSChao Yu }; 144662befdaSChao Yu 1456451e041SJaegeuk Kim /* for the list of ino */ 1466451e041SJaegeuk Kim enum { 1476451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 148fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 149fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1506451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1516451e041SJaegeuk Kim }; 1526451e041SJaegeuk Kim 1536451e041SJaegeuk Kim struct ino_entry { 15439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 15539a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 15639a53e0cSJaegeuk Kim }; 15739a53e0cSJaegeuk Kim 15806292073SChao Yu /* 15906292073SChao Yu * for the list of directory inodes or gc inodes. 16006292073SChao Yu * NOTE: there are two slab users for this structure, if we add/modify/delete 16106292073SChao Yu * fields in structure for one of slab users, it may affect fields or size of 16206292073SChao Yu * other one, in this condition, it's better to split both of slab and related 16306292073SChao Yu * data structure. 16406292073SChao Yu */ 16506292073SChao Yu struct inode_entry { 16639a53e0cSJaegeuk Kim struct list_head list; /* list head */ 16739a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 16839a53e0cSJaegeuk Kim }; 16939a53e0cSJaegeuk Kim 1707fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1717fd9e544SJaegeuk Kim struct discard_entry { 1727fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1737fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1747fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1757fd9e544SJaegeuk Kim }; 1767fd9e544SJaegeuk Kim 17739a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 17839a53e0cSJaegeuk Kim struct fsync_inode_entry { 17939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18039a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 181c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 182c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 183c52e1b10SJaegeuk Kim block_t last_inode; /* block address locating the last inode */ 18439a53e0cSJaegeuk Kim }; 18539a53e0cSJaegeuk Kim 18639a53e0cSJaegeuk Kim #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats)) 18739a53e0cSJaegeuk Kim #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits)) 18839a53e0cSJaegeuk Kim 18939a53e0cSJaegeuk Kim #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne) 19039a53e0cSJaegeuk Kim #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid) 19139a53e0cSJaegeuk Kim #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se) 19239a53e0cSJaegeuk Kim #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno) 19339a53e0cSJaegeuk Kim 194309cc2b6SJaegeuk Kim #define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum)) 195309cc2b6SJaegeuk Kim #define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum)) 196309cc2b6SJaegeuk Kim 19739a53e0cSJaegeuk Kim static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i) 19839a53e0cSJaegeuk Kim { 19939a53e0cSJaegeuk Kim int before = nats_in_cursum(rs); 20039a53e0cSJaegeuk Kim rs->n_nats = cpu_to_le16(before + i); 20139a53e0cSJaegeuk Kim return before; 20239a53e0cSJaegeuk Kim } 20339a53e0cSJaegeuk Kim 20439a53e0cSJaegeuk Kim static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i) 20539a53e0cSJaegeuk Kim { 20639a53e0cSJaegeuk Kim int before = sits_in_cursum(rs); 20739a53e0cSJaegeuk Kim rs->n_sits = cpu_to_le16(before + i); 20839a53e0cSJaegeuk Kim return before; 20939a53e0cSJaegeuk Kim } 21039a53e0cSJaegeuk Kim 211184a5cd2SChao Yu static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size, 212184a5cd2SChao Yu int type) 213184a5cd2SChao Yu { 214184a5cd2SChao Yu if (type == NAT_JOURNAL) 215309cc2b6SJaegeuk Kim return size <= MAX_NAT_JENTRIES(sum); 216309cc2b6SJaegeuk Kim return size <= MAX_SIT_JENTRIES(sum); 217184a5cd2SChao Yu } 218184a5cd2SChao Yu 21939a53e0cSJaegeuk Kim /* 220e9750824SNamjae Jeon * ioctl commands 221e9750824SNamjae Jeon */ 222e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 223e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 224d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 225e9750824SNamjae Jeon 22688b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 22788b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 22888b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 22902a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2301e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2311e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 232c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 23388b88a66SJaegeuk Kim 234f424f664SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY \ 235f424f664SJaegeuk Kim _IOR('f', 19, struct f2fs_encryption_policy) 236f424f664SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT \ 237f424f664SJaegeuk Kim _IOW('f', 20, __u8[16]) 238f424f664SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY \ 239f424f664SJaegeuk Kim _IOW('f', 21, struct f2fs_encryption_policy) 240f424f664SJaegeuk Kim 2411abff93dSJaegeuk Kim /* 2421abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2431abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2441abff93dSJaegeuk Kim */ 2451abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2461abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2471abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2481abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 2491abff93dSJaegeuk Kim 250e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 251e9750824SNamjae Jeon /* 252e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 253e9750824SNamjae Jeon */ 254e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 255e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 256e9750824SNamjae Jeon #endif 257e9750824SNamjae Jeon 258e9750824SNamjae Jeon /* 25939a53e0cSJaegeuk Kim * For INODE and NODE manager 26039a53e0cSJaegeuk Kim */ 2617b3cd7d6SJaegeuk Kim /* for directory operations */ 2626b3bd08fSJaegeuk Kim struct f2fs_str { 2636b3bd08fSJaegeuk Kim unsigned char *name; 2646b3bd08fSJaegeuk Kim u32 len; 2656b3bd08fSJaegeuk Kim }; 2666b3bd08fSJaegeuk Kim 2676b3bd08fSJaegeuk Kim struct f2fs_filename { 2686b3bd08fSJaegeuk Kim const struct qstr *usr_fname; 2696b3bd08fSJaegeuk Kim struct f2fs_str disk_name; 2706b3bd08fSJaegeuk Kim f2fs_hash_t hash; 2716b3bd08fSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2726b3bd08fSJaegeuk Kim struct f2fs_str crypto_buf; 2736b3bd08fSJaegeuk Kim #endif 2746b3bd08fSJaegeuk Kim }; 2756b3bd08fSJaegeuk Kim 2766b3bd08fSJaegeuk Kim #define FSTR_INIT(n, l) { .name = n, .len = l } 2776b3bd08fSJaegeuk Kim #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len) 2786b3bd08fSJaegeuk Kim #define fname_name(p) ((p)->disk_name.name) 2796b3bd08fSJaegeuk Kim #define fname_len(p) ((p)->disk_name.len) 2806b3bd08fSJaegeuk Kim 2817b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 282d8c6822aSJaegeuk Kim struct inode *inode; 2837b3cd7d6SJaegeuk Kim const void *bitmap; 2847b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 2857b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 2867b3cd7d6SJaegeuk Kim int max; 2877b3cd7d6SJaegeuk Kim }; 2887b3cd7d6SJaegeuk Kim 289d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode, 290d8c6822aSJaegeuk Kim struct f2fs_dentry_ptr *d, void *src, int type) 2917b3cd7d6SJaegeuk Kim { 292d8c6822aSJaegeuk Kim d->inode = inode; 293d8c6822aSJaegeuk Kim 2947b3cd7d6SJaegeuk Kim if (type == 1) { 2957b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 2967b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 2977b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 2987b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 2997b3cd7d6SJaegeuk Kim d->filename = t->filename; 3007b3cd7d6SJaegeuk Kim } else { 3017b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 3027b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3037b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3047b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3057b3cd7d6SJaegeuk Kim d->filename = t->filename; 3067b3cd7d6SJaegeuk Kim } 3077b3cd7d6SJaegeuk Kim } 3087b3cd7d6SJaegeuk Kim 309dbe6a5ffSJaegeuk Kim /* 310dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 311dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 312dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 31339a53e0cSJaegeuk Kim */ 314dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 315dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 316266e97a8SJaegeuk Kim enum { 317266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 318266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 319266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 320266e97a8SJaegeuk Kim * look up a node with readahead called 3214f4124d0SChao Yu * by get_data_block. 32239a53e0cSJaegeuk Kim */ 323266e97a8SJaegeuk Kim }; 324266e97a8SJaegeuk Kim 325a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 32639a53e0cSJaegeuk Kim 327817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 328817202d9SChao Yu 32913054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 33013054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 33113054c54SChao Yu 33239a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 33313054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 33413054c54SChao Yu 33513054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 33613054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 337c11abd1aSJaegeuk Kim 33839a53e0cSJaegeuk Kim struct extent_info { 33939a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3404d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 341111d2495SMasanari Iida unsigned int len; /* length of the extent */ 34239a53e0cSJaegeuk Kim }; 34339a53e0cSJaegeuk Kim 34413054c54SChao Yu struct extent_node { 34513054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 34613054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 34713054c54SChao Yu struct extent_info ei; /* extent info */ 34813054c54SChao Yu }; 34913054c54SChao Yu 35013054c54SChao Yu struct extent_tree { 35113054c54SChao Yu nid_t ino; /* inode number */ 35213054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 35362c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 3543e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 35513054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 35613054c54SChao Yu atomic_t refcount; /* reference count of rb-tree */ 35713054c54SChao Yu unsigned int count; /* # of extent node in rb-tree*/ 35813054c54SChao Yu }; 35913054c54SChao Yu 36039a53e0cSJaegeuk Kim /* 361003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 362003a3e1dSJaegeuk Kim * 363003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 364003a3e1dSJaegeuk Kim */ 365003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 366003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 3677f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 3687f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 3697f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 370003a3e1dSJaegeuk Kim 371003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 372003a3e1dSJaegeuk Kim block_t m_pblk; 373003a3e1dSJaegeuk Kim block_t m_lblk; 374003a3e1dSJaegeuk Kim unsigned int m_len; 375003a3e1dSJaegeuk Kim unsigned int m_flags; 376003a3e1dSJaegeuk Kim }; 377003a3e1dSJaegeuk Kim 378e2b4e2bcSChao Yu /* for flag in get_data_block */ 379e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 380e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 381e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 382e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 383e2b4e2bcSChao Yu 384003a3e1dSJaegeuk Kim /* 38539a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 38639a53e0cSJaegeuk Kim */ 38739a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 388354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 389cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 390e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 39139a53e0cSJaegeuk Kim 392b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 393b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 394b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 395b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 396b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 397b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 398cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 399cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 400cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 401e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 402e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 403cde4de12SJaegeuk Kim 404cde4de12SJaegeuk Kim /* Encryption algorithms */ 405cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_INVALID 0 406cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_XTS 1 407cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_GCM 2 408cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CBC 3 409cde4de12SJaegeuk Kim #define F2FS_ENCRYPTION_MODE_AES_256_CTS 4 410b5492af7SJaegeuk Kim 411f424f664SJaegeuk Kim #include "f2fs_crypto.h" 412f424f664SJaegeuk Kim 413ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 414ab9fa662SJaegeuk Kim 41539a53e0cSJaegeuk Kim struct f2fs_inode_info { 41639a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 41739a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 41839a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 41938431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 42039a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4216666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 42239a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 42339a53e0cSJaegeuk Kim 42439a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 42539a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 426d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 427a7ffdbe2SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 42839a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 42939a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 43039a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 431e518ff81SJaegeuk Kim unsigned long long xattr_ver; /* cp version of xattr modification */ 43206292073SChao Yu struct inode_entry *dirty_dir; /* the pointer of dirty dir */ 43388b88a66SJaegeuk Kim 43488b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 43588b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 436cde4de12SJaegeuk Kim 4373e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 4383e72f721SJaegeuk Kim 439cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 440cde4de12SJaegeuk Kim /* Encryption params */ 441cde4de12SJaegeuk Kim struct f2fs_crypt_info *i_crypt_info; 442cde4de12SJaegeuk Kim #endif 44339a53e0cSJaegeuk Kim }; 44439a53e0cSJaegeuk Kim 44539a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 44639a53e0cSJaegeuk Kim struct f2fs_extent i_ext) 44739a53e0cSJaegeuk Kim { 44839a53e0cSJaegeuk Kim ext->fofs = le32_to_cpu(i_ext.fofs); 4494d0b0bd4SChao Yu ext->blk = le32_to_cpu(i_ext.blk); 45039a53e0cSJaegeuk Kim ext->len = le32_to_cpu(i_ext.len); 45139a53e0cSJaegeuk Kim } 45239a53e0cSJaegeuk Kim 45339a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 45439a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 45539a53e0cSJaegeuk Kim { 45639a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4574d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 45839a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 45939a53e0cSJaegeuk Kim } 46039a53e0cSJaegeuk Kim 461429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 462429511cdSChao Yu u32 blk, unsigned int len) 463429511cdSChao Yu { 464429511cdSChao Yu ei->fofs = fofs; 465429511cdSChao Yu ei->blk = blk; 466429511cdSChao Yu ei->len = len; 467429511cdSChao Yu } 468429511cdSChao Yu 4690bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1, 4700bdee482SChao Yu struct extent_info *ei2) 4710bdee482SChao Yu { 4720bdee482SChao Yu return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk && 4730bdee482SChao Yu ei1->len == ei2->len); 4740bdee482SChao Yu } 4750bdee482SChao Yu 476429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 477429511cdSChao Yu struct extent_info *front) 478429511cdSChao Yu { 479429511cdSChao Yu return (back->fofs + back->len == front->fofs && 480429511cdSChao Yu back->blk + back->len == front->blk); 481429511cdSChao Yu } 482429511cdSChao Yu 483429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 484429511cdSChao Yu struct extent_info *back) 485429511cdSChao Yu { 486429511cdSChao Yu return __is_extent_mergeable(back, cur); 487429511cdSChao Yu } 488429511cdSChao Yu 489429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 490429511cdSChao Yu struct extent_info *front) 491429511cdSChao Yu { 492429511cdSChao Yu return __is_extent_mergeable(cur, front); 493429511cdSChao Yu } 494429511cdSChao Yu 49539a53e0cSJaegeuk Kim struct f2fs_nm_info { 49639a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 49739a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 4987ee0eeabSJaegeuk Kim nid_t available_nids; /* maximum available node ids */ 49939a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 500cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 50139a53e0cSJaegeuk Kim 50239a53e0cSJaegeuk Kim /* NAT cache management */ 50339a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 504309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 5058b26ef98SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 50639a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 507309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 508aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 50939a53e0cSJaegeuk Kim 51039a53e0cSJaegeuk Kim /* free node ids management */ 5118a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 51239a53e0cSJaegeuk Kim struct list_head free_nid_list; /* a list for free nids */ 51339a53e0cSJaegeuk Kim spinlock_t free_nid_list_lock; /* protect free nid list */ 51439a53e0cSJaegeuk Kim unsigned int fcnt; /* the number of free node id */ 51539a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 51639a53e0cSJaegeuk Kim 51739a53e0cSJaegeuk Kim /* for checkpoint */ 51839a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 51939a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 52039a53e0cSJaegeuk Kim }; 52139a53e0cSJaegeuk Kim 52239a53e0cSJaegeuk Kim /* 52339a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 52439a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 52539a53e0cSJaegeuk Kim * by the data offset in a file. 52639a53e0cSJaegeuk Kim */ 52739a53e0cSJaegeuk Kim struct dnode_of_data { 52839a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 52939a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 53039a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 53139a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 53239a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 53339a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 53439a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 53539a53e0cSJaegeuk Kim }; 53639a53e0cSJaegeuk Kim 53739a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 53839a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 53939a53e0cSJaegeuk Kim { 540d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 54139a53e0cSJaegeuk Kim dn->inode = inode; 54239a53e0cSJaegeuk Kim dn->inode_page = ipage; 54339a53e0cSJaegeuk Kim dn->node_page = npage; 54439a53e0cSJaegeuk Kim dn->nid = nid; 54539a53e0cSJaegeuk Kim } 54639a53e0cSJaegeuk Kim 54739a53e0cSJaegeuk Kim /* 54839a53e0cSJaegeuk Kim * For SIT manager 54939a53e0cSJaegeuk Kim * 55039a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 55139a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 55239a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 55339a53e0cSJaegeuk Kim * respectively. 55439a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 55539a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 55639a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 55739a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 55839a53e0cSJaegeuk Kim * data and 8 for node logs. 55939a53e0cSJaegeuk Kim */ 56039a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 56139a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 56239a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 56339a53e0cSJaegeuk Kim 56439a53e0cSJaegeuk Kim enum { 56539a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 56639a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 56739a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 56839a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 56939a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 57039a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 57138aa0889SJaegeuk Kim NO_CHECK_TYPE, 57238aa0889SJaegeuk Kim CURSEG_DIRECT_IO, /* to use for the direct IO path */ 57339a53e0cSJaegeuk Kim }; 57439a53e0cSJaegeuk Kim 5756b4afdd7SJaegeuk Kim struct flush_cmd { 5766b4afdd7SJaegeuk Kim struct completion wait; 577721bd4d5SGu Zheng struct llist_node llnode; 5786b4afdd7SJaegeuk Kim int ret; 5796b4afdd7SJaegeuk Kim }; 5806b4afdd7SJaegeuk Kim 581a688b9d9SGu Zheng struct flush_cmd_control { 582a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 583a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 584721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 585721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 586a688b9d9SGu Zheng }; 587a688b9d9SGu Zheng 58839a53e0cSJaegeuk Kim struct f2fs_sm_info { 58939a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 59039a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 59139a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 59239a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 59339a53e0cSJaegeuk Kim 59439a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 59539a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 59639a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 59739a53e0cSJaegeuk Kim 59839a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 59939a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 60039a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 60139a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 60281eb8d6eSJaegeuk Kim 60381eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 60481eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 6057fd9e544SJaegeuk Kim 6067fd9e544SJaegeuk Kim /* for small discard management */ 6077fd9e544SJaegeuk Kim struct list_head discard_list; /* 4KB discard list */ 6087fd9e544SJaegeuk Kim int nr_discards; /* # of discards in the list */ 6097fd9e544SJaegeuk Kim int max_discards; /* max. discards to be issued */ 610216fbd64SJaegeuk Kim 611bba681cbSJaegeuk Kim /* for batched trimming */ 612bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 613bba681cbSJaegeuk Kim 614184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 615184a5cd2SChao Yu 616216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 617216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 618c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 6196b4afdd7SJaegeuk Kim 6206b4afdd7SJaegeuk Kim /* for flush command control */ 621a688b9d9SGu Zheng struct flush_cmd_control *cmd_control_info; 622a688b9d9SGu Zheng 62339a53e0cSJaegeuk Kim }; 62439a53e0cSJaegeuk Kim 62539a53e0cSJaegeuk Kim /* 62639a53e0cSJaegeuk Kim * For superblock 62739a53e0cSJaegeuk Kim */ 62839a53e0cSJaegeuk Kim /* 62939a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 63039a53e0cSJaegeuk Kim * 63139a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 63239a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 63339a53e0cSJaegeuk Kim */ 63439a53e0cSJaegeuk Kim enum count_type { 63539a53e0cSJaegeuk Kim F2FS_WRITEBACK, 63639a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 63739a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 63839a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6398dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 64039a53e0cSJaegeuk Kim NR_COUNT_TYPE, 64139a53e0cSJaegeuk Kim }; 64239a53e0cSJaegeuk Kim 64339a53e0cSJaegeuk Kim /* 644e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 64539a53e0cSJaegeuk Kim * The available types are: 64639a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 64739a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 64839a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 64939a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 65039a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 65139a53e0cSJaegeuk Kim * with waiting the bio's completion 65239a53e0cSJaegeuk Kim * ... Only can be used with META. 65339a53e0cSJaegeuk Kim */ 6547d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 65539a53e0cSJaegeuk Kim enum page_type { 65639a53e0cSJaegeuk Kim DATA, 65739a53e0cSJaegeuk Kim NODE, 65839a53e0cSJaegeuk Kim META, 65939a53e0cSJaegeuk Kim NR_PAGE_TYPE, 66039a53e0cSJaegeuk Kim META_FLUSH, 6618ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 6628ce67cb0SJaegeuk Kim INMEM_DROP, 6638ce67cb0SJaegeuk Kim IPU, 6648ce67cb0SJaegeuk Kim OPU, 66539a53e0cSJaegeuk Kim }; 66639a53e0cSJaegeuk Kim 667458e6197SJaegeuk Kim struct f2fs_io_info { 66805ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 669458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 6707e8f2308SGu Zheng int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */ 671cf04e8ebSJaegeuk Kim block_t blk_addr; /* block address to be written */ 67205ca3632SJaegeuk Kim struct page *page; /* page to be written */ 6734375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 674458e6197SJaegeuk Kim }; 675458e6197SJaegeuk Kim 67693dfe2acSJaegeuk Kim #define is_read_io(rw) (((rw) & 1) == READ) 6771ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 678458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 6791ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 6801ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 681458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 682df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 6831ff7bd3bSJaegeuk Kim }; 6841ff7bd3bSJaegeuk Kim 68567298804SChao Yu /* for inner inode cache management */ 68667298804SChao Yu struct inode_management { 68767298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 68867298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 68967298804SChao Yu struct list_head ino_list; /* inode list head */ 69067298804SChao Yu unsigned long ino_num; /* number of entries */ 69167298804SChao Yu }; 69267298804SChao Yu 693caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 694caf0047eSChao Yu enum { 695caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 696caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 697caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 698caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 699caf0047eSChao Yu }; 700caf0047eSChao Yu 70139a53e0cSJaegeuk Kim struct f2fs_sb_info { 70239a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 7035e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 70439a53e0cSJaegeuk Kim struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 70539a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 706caf0047eSChao Yu int s_flag; /* flags for sbi */ 70739a53e0cSJaegeuk Kim 70839a53e0cSJaegeuk Kim /* for node-related operations */ 70939a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 71039a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 71139a53e0cSJaegeuk Kim 71239a53e0cSJaegeuk Kim /* for segment-related operations */ 71339a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 7141ff7bd3bSJaegeuk Kim 7151ff7bd3bSJaegeuk Kim /* for bio operations */ 716924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 7171ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 71839a53e0cSJaegeuk Kim 71939a53e0cSJaegeuk Kim /* for checkpoint */ 72039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 72139a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 72239936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 723e479556bSGu Zheng struct rw_semaphore cp_rwsem; /* blocking FS operations */ 724b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 7255463e7c1SJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 726fb51b5efSChangman Lee wait_queue_head_t cp_wait; 72739a53e0cSJaegeuk Kim 72867298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 7296451e041SJaegeuk Kim 7306451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 7310d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 73239a53e0cSJaegeuk Kim 73339a53e0cSJaegeuk Kim /* for directory inode management */ 73439a53e0cSJaegeuk Kim struct list_head dir_inode_list; /* dir inode list */ 73539a53e0cSJaegeuk Kim spinlock_t dir_inode_lock; /* for dir inode list lock */ 73639a53e0cSJaegeuk Kim 73713054c54SChao Yu /* for extent tree cache */ 73813054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 73913054c54SChao Yu struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 74013054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 74113054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 74213054c54SChao Yu int total_ext_tree; /* extent tree count */ 74313054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 74413054c54SChao Yu 74539a53e0cSJaegeuk Kim /* basic filesystem units */ 74639a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 74739a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 74839a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 74939a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 75039a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 75139a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 75239a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 75339a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 75439a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 75539a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 75639a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 75739a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 75839a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 75939a53e0cSJaegeuk Kim unsigned int total_valid_inode_count; /* valid inode count */ 76039a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 761ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 76239a53e0cSJaegeuk Kim 76339a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 76439a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 76539a53e0cSJaegeuk Kim block_t alloc_valid_block_count; /* # of allocated blocks */ 766a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 76739a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 76839a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 76939a53e0cSJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */ 77039a53e0cSJaegeuk Kim 77139a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 77239a53e0cSJaegeuk Kim 77339a53e0cSJaegeuk Kim /* for cleaning operations */ 77439a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 77539a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 7765ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 77739a53e0cSJaegeuk Kim 778b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 779b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 780b1c57c1cSJaegeuk Kim 78139a53e0cSJaegeuk Kim /* 78239a53e0cSJaegeuk Kim * for stat information. 78339a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 78439a53e0cSJaegeuk Kim */ 78535b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 78639a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 78739a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 78839a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 789b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 790727edac5SChao Yu atomic_t total_hit_ext; /* # of lookup extent cache */ 791029e13ccSChao Yu atomic_t read_hit_rbtree; /* # of hit rbtree extent node */ 79291c481ffSChao Yu atomic_t read_hit_largest; /* # of hit largest extent node */ 79391c481ffSChao Yu atomic_t read_hit_cached; /* # of hit cached extent node */ 794d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 79503e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 79603e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 79739a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 79835b09d82SNamjae Jeon unsigned int n_dirty_dirs; /* # of dir inodes */ 79935b09d82SNamjae Jeon #endif 80035b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 80139a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 802b59d0baeSNamjae Jeon 803b59d0baeSNamjae Jeon /* For sysfs suppport */ 804b59d0baeSNamjae Jeon struct kobject s_kobj; 805b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 8062658e50dSJaegeuk Kim 8072658e50dSJaegeuk Kim /* For shrinker support */ 8082658e50dSJaegeuk Kim struct list_head s_list; 8092658e50dSJaegeuk Kim struct mutex umount_mutex; 8102658e50dSJaegeuk Kim unsigned int shrinker_run_no; 81139a53e0cSJaegeuk Kim }; 81239a53e0cSJaegeuk Kim 81339a53e0cSJaegeuk Kim /* 81439a53e0cSJaegeuk Kim * Inline functions 81539a53e0cSJaegeuk Kim */ 81639a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 81739a53e0cSJaegeuk Kim { 81839a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 81939a53e0cSJaegeuk Kim } 82039a53e0cSJaegeuk Kim 82139a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 82239a53e0cSJaegeuk Kim { 82339a53e0cSJaegeuk Kim return sb->s_fs_info; 82439a53e0cSJaegeuk Kim } 82539a53e0cSJaegeuk Kim 8264081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 8274081363fSJaegeuk Kim { 8284081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 8294081363fSJaegeuk Kim } 8304081363fSJaegeuk Kim 8314081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 8324081363fSJaegeuk Kim { 8334081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 8344081363fSJaegeuk Kim } 8354081363fSJaegeuk Kim 8364081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 8374081363fSJaegeuk Kim { 8384081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 8394081363fSJaegeuk Kim } 8404081363fSJaegeuk Kim 84139a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 84239a53e0cSJaegeuk Kim { 84339a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 84439a53e0cSJaegeuk Kim } 84539a53e0cSJaegeuk Kim 84639a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 84739a53e0cSJaegeuk Kim { 84839a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 84939a53e0cSJaegeuk Kim } 85039a53e0cSJaegeuk Kim 85145590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 85245590710SGu Zheng { 85345590710SGu Zheng return (struct f2fs_node *)page_address(page); 85445590710SGu Zheng } 85545590710SGu Zheng 85658bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 85758bfaf44SJaegeuk Kim { 85858bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 85958bfaf44SJaegeuk Kim } 86058bfaf44SJaegeuk Kim 86139a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 86239a53e0cSJaegeuk Kim { 86339a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 86439a53e0cSJaegeuk Kim } 86539a53e0cSJaegeuk Kim 86639a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 86739a53e0cSJaegeuk Kim { 86839a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 86939a53e0cSJaegeuk Kim } 87039a53e0cSJaegeuk Kim 87139a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 87239a53e0cSJaegeuk Kim { 87339a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 87439a53e0cSJaegeuk Kim } 87539a53e0cSJaegeuk Kim 87639a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 87739a53e0cSJaegeuk Kim { 87839a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 87939a53e0cSJaegeuk Kim } 88039a53e0cSJaegeuk Kim 88139a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 88239a53e0cSJaegeuk Kim { 88339a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 88439a53e0cSJaegeuk Kim } 88539a53e0cSJaegeuk Kim 8869df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 8879df27d98SGu Zheng { 8889df27d98SGu Zheng return sbi->meta_inode->i_mapping; 8899df27d98SGu Zheng } 8909df27d98SGu Zheng 8914ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 8924ef51a8fSJaegeuk Kim { 8934ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 8944ef51a8fSJaegeuk Kim } 8954ef51a8fSJaegeuk Kim 896caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 89739a53e0cSJaegeuk Kim { 898caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 89939a53e0cSJaegeuk Kim } 90039a53e0cSJaegeuk Kim 901caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 90239a53e0cSJaegeuk Kim { 903caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 904caf0047eSChao Yu } 905caf0047eSChao Yu 906caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 907caf0047eSChao Yu { 908caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 90939a53e0cSJaegeuk Kim } 91039a53e0cSJaegeuk Kim 911d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 912d71b5564SJaegeuk Kim { 913d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 914d71b5564SJaegeuk Kim } 915d71b5564SJaegeuk Kim 91625ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 91725ca923bSJaegeuk Kim { 91825ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 91925ca923bSJaegeuk Kim return ckpt_flags & f; 92025ca923bSJaegeuk Kim } 92125ca923bSJaegeuk Kim 92225ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 92325ca923bSJaegeuk Kim { 92425ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 92525ca923bSJaegeuk Kim ckpt_flags |= f; 92625ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 92725ca923bSJaegeuk Kim } 92825ca923bSJaegeuk Kim 92925ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 93025ca923bSJaegeuk Kim { 93125ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 93225ca923bSJaegeuk Kim ckpt_flags &= (~f); 93325ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 93425ca923bSJaegeuk Kim } 93525ca923bSJaegeuk Kim 936e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 93739a53e0cSJaegeuk Kim { 938e479556bSGu Zheng down_read(&sbi->cp_rwsem); 93939a53e0cSJaegeuk Kim } 94039a53e0cSJaegeuk Kim 941e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 94239a53e0cSJaegeuk Kim { 943e479556bSGu Zheng up_read(&sbi->cp_rwsem); 94439936837SJaegeuk Kim } 94539936837SJaegeuk Kim 946e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 94739936837SJaegeuk Kim { 9480daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 94939936837SJaegeuk Kim } 95039936837SJaegeuk Kim 951e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 95239936837SJaegeuk Kim { 953e479556bSGu Zheng up_write(&sbi->cp_rwsem); 95439a53e0cSJaegeuk Kim } 95539a53e0cSJaegeuk Kim 956119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 957119ee914SJaegeuk Kim { 958119ee914SJaegeuk Kim int reason = CP_SYNC; 959119ee914SJaegeuk Kim 960119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 961119ee914SJaegeuk Kim reason = CP_FASTBOOT; 962119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 963119ee914SJaegeuk Kim reason = CP_UMOUNT; 964119ee914SJaegeuk Kim return reason; 965119ee914SJaegeuk Kim } 966119ee914SJaegeuk Kim 967119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 968119ee914SJaegeuk Kim { 969119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 970119ee914SJaegeuk Kim } 971119ee914SJaegeuk Kim 972119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 973119ee914SJaegeuk Kim { 974119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 975119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 976119ee914SJaegeuk Kim } 977119ee914SJaegeuk Kim 97839a53e0cSJaegeuk Kim /* 97939a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 98039a53e0cSJaegeuk Kim */ 981064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 98239a53e0cSJaegeuk Kim { 983d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 984d6b7d4b3SChao Yu return -EINVAL; 985cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 986064e0823SNamjae Jeon return -EINVAL; 987064e0823SNamjae Jeon return 0; 98839a53e0cSJaegeuk Kim } 98939a53e0cSJaegeuk Kim 99039a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 99139a53e0cSJaegeuk Kim 99239a53e0cSJaegeuk Kim /* 99339a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 99439a53e0cSJaegeuk Kim */ 99539a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 99639a53e0cSJaegeuk Kim { 99739a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 9986c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 99939a53e0cSJaegeuk Kim else 10006c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 100139a53e0cSJaegeuk Kim } 100239a53e0cSJaegeuk Kim 10034bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 10044bc8e9bcSChao Yu { 10054bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 10064bc8e9bcSChao Yu } 10074bc8e9bcSChao Yu 100839a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 100939a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 101039a53e0cSJaegeuk Kim { 101139a53e0cSJaegeuk Kim block_t valid_block_count; 101239a53e0cSJaegeuk Kim 101339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 101439a53e0cSJaegeuk Kim valid_block_count = 101539a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 1016cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 101739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 101839a53e0cSJaegeuk Kim return false; 101939a53e0cSJaegeuk Kim } 102039a53e0cSJaegeuk Kim inode->i_blocks += count; 102139a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 102239a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 102339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 102439a53e0cSJaegeuk Kim return true; 102539a53e0cSJaegeuk Kim } 102639a53e0cSJaegeuk Kim 1027da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 102839a53e0cSJaegeuk Kim struct inode *inode, 102939a53e0cSJaegeuk Kim blkcnt_t count) 103039a53e0cSJaegeuk Kim { 103139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 10329850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 10339850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 103439a53e0cSJaegeuk Kim inode->i_blocks -= count; 103539a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 103639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 103739a53e0cSJaegeuk Kim } 103839a53e0cSJaegeuk Kim 103939a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 104039a53e0cSJaegeuk Kim { 104139a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 1042caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 104339a53e0cSJaegeuk Kim } 104439a53e0cSJaegeuk Kim 1045a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 104639a53e0cSJaegeuk Kim { 1047a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1048a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10494081363fSJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 105039a53e0cSJaegeuk Kim } 105139a53e0cSJaegeuk Kim 105239a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 105339a53e0cSJaegeuk Kim { 105439a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 105539a53e0cSJaegeuk Kim } 105639a53e0cSJaegeuk Kim 1057a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 105839a53e0cSJaegeuk Kim { 10595ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 10605ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 10611fe54f9dSJaegeuk Kim return; 10621fe54f9dSJaegeuk Kim 1063a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1064a7ffdbe2SJaegeuk Kim 1065a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10664081363fSJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 106739a53e0cSJaegeuk Kim } 106839a53e0cSJaegeuk Kim 106939a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 107039a53e0cSJaegeuk Kim { 107139a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 107239a53e0cSJaegeuk Kim } 107339a53e0cSJaegeuk Kim 1074a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1075f8b2c1f9SJaegeuk Kim { 1076a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1077f8b2c1f9SJaegeuk Kim } 1078f8b2c1f9SJaegeuk Kim 10795ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 10805ac206cfSNamjae Jeon { 10815ac206cfSNamjae Jeon unsigned int pages_per_sec = sbi->segs_per_sec * 10825ac206cfSNamjae Jeon (1 << sbi->log_blocks_per_seg); 10835ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 10845ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 10855ac206cfSNamjae Jeon } 10865ac206cfSNamjae Jeon 108739a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 108839a53e0cSJaegeuk Kim { 10898b8343faSJaegeuk Kim return sbi->total_valid_block_count; 109039a53e0cSJaegeuk Kim } 109139a53e0cSJaegeuk Kim 109239a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 109339a53e0cSJaegeuk Kim { 109439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 109539a53e0cSJaegeuk Kim 109639a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 109739a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 109839a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 109939a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 110039a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 110139a53e0cSJaegeuk Kim 110239a53e0cSJaegeuk Kim return 0; 110339a53e0cSJaegeuk Kim } 110439a53e0cSJaegeuk Kim 110555141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 110655141486SWanpeng Li { 110755141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 110855141486SWanpeng Li } 110955141486SWanpeng Li 111039a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 111139a53e0cSJaegeuk Kim { 111239a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 11131dbe4152SChangman Lee int offset; 11141dbe4152SChangman Lee 111555141486SWanpeng Li if (__cp_payload(sbi) > 0) { 11161dbe4152SChangman Lee if (flag == NAT_BITMAP) 11171dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 11181dbe4152SChangman Lee else 111965b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 11201dbe4152SChangman Lee } else { 11211dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 112225ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 112339a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 112439a53e0cSJaegeuk Kim } 11251dbe4152SChangman Lee } 112639a53e0cSJaegeuk Kim 112739a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 112839a53e0cSJaegeuk Kim { 112939a53e0cSJaegeuk Kim block_t start_addr; 113039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1131d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 113239a53e0cSJaegeuk Kim 113325ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 113439a53e0cSJaegeuk Kim 113539a53e0cSJaegeuk Kim /* 113639a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1137e1c42045Sarter97 * and even segment must be at cp segment 1 113839a53e0cSJaegeuk Kim */ 113939a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 114039a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 114139a53e0cSJaegeuk Kim 114239a53e0cSJaegeuk Kim return start_addr; 114339a53e0cSJaegeuk Kim } 114439a53e0cSJaegeuk Kim 114539a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 114639a53e0cSJaegeuk Kim { 114739a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 114839a53e0cSJaegeuk Kim } 114939a53e0cSJaegeuk Kim 115039a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1151ef86d709SGu Zheng struct inode *inode) 115239a53e0cSJaegeuk Kim { 115339a53e0cSJaegeuk Kim block_t valid_block_count; 115439a53e0cSJaegeuk Kim unsigned int valid_node_count; 115539a53e0cSJaegeuk Kim 115639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 115739a53e0cSJaegeuk Kim 1158ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1159cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 116039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 116139a53e0cSJaegeuk Kim return false; 116239a53e0cSJaegeuk Kim } 116339a53e0cSJaegeuk Kim 1164ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1165cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 116639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 116739a53e0cSJaegeuk Kim return false; 116839a53e0cSJaegeuk Kim } 116939a53e0cSJaegeuk Kim 117039a53e0cSJaegeuk Kim if (inode) 1171ef86d709SGu Zheng inode->i_blocks++; 1172ef86d709SGu Zheng 1173ef86d709SGu Zheng sbi->alloc_valid_block_count++; 1174ef86d709SGu Zheng sbi->total_valid_node_count++; 1175ef86d709SGu Zheng sbi->total_valid_block_count++; 117639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 117739a53e0cSJaegeuk Kim 117839a53e0cSJaegeuk Kim return true; 117939a53e0cSJaegeuk Kim } 118039a53e0cSJaegeuk Kim 118139a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1182ef86d709SGu Zheng struct inode *inode) 118339a53e0cSJaegeuk Kim { 118439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 118539a53e0cSJaegeuk Kim 11869850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 11879850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 11889850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 118939a53e0cSJaegeuk Kim 1190ef86d709SGu Zheng inode->i_blocks--; 1191ef86d709SGu Zheng sbi->total_valid_node_count--; 1192ef86d709SGu Zheng sbi->total_valid_block_count--; 119339a53e0cSJaegeuk Kim 119439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 119539a53e0cSJaegeuk Kim } 119639a53e0cSJaegeuk Kim 119739a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 119839a53e0cSJaegeuk Kim { 11998b8343faSJaegeuk Kim return sbi->total_valid_node_count; 120039a53e0cSJaegeuk Kim } 120139a53e0cSJaegeuk Kim 120239a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 120339a53e0cSJaegeuk Kim { 120439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12059850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 120639a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 120739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 120839a53e0cSJaegeuk Kim } 120939a53e0cSJaegeuk Kim 12100e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 121139a53e0cSJaegeuk Kim { 121239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12139850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 121439a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 121539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 121639a53e0cSJaegeuk Kim } 121739a53e0cSJaegeuk Kim 121839a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 121939a53e0cSJaegeuk Kim { 12208b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 122139a53e0cSJaegeuk Kim } 122239a53e0cSJaegeuk Kim 122339a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 122439a53e0cSJaegeuk Kim { 1225031fa8ccSJaegeuk Kim if (!page) 122639a53e0cSJaegeuk Kim return; 122739a53e0cSJaegeuk Kim 122839a53e0cSJaegeuk Kim if (unlock) { 12299850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 123039a53e0cSJaegeuk Kim unlock_page(page); 123139a53e0cSJaegeuk Kim } 123239a53e0cSJaegeuk Kim page_cache_release(page); 123339a53e0cSJaegeuk Kim } 123439a53e0cSJaegeuk Kim 123539a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 123639a53e0cSJaegeuk Kim { 123739a53e0cSJaegeuk Kim if (dn->node_page) 123839a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 123939a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 124039a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 124139a53e0cSJaegeuk Kim dn->node_page = NULL; 124239a53e0cSJaegeuk Kim dn->inode_page = NULL; 124339a53e0cSJaegeuk Kim } 124439a53e0cSJaegeuk Kim 124539a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1246e8512d2eSGu Zheng size_t size) 124739a53e0cSJaegeuk Kim { 1248e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 124939a53e0cSJaegeuk Kim } 125039a53e0cSJaegeuk Kim 12517bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 12527bd59381SGu Zheng gfp_t flags) 12537bd59381SGu Zheng { 12547bd59381SGu Zheng void *entry; 12557bd59381SGu Zheng 125680c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 125780c54505SJaegeuk Kim if (!entry) 125880c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 12597bd59381SGu Zheng return entry; 12607bd59381SGu Zheng } 12617bd59381SGu Zheng 1262740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1263740432f8SJaegeuk Kim { 1264740432f8SJaegeuk Kim struct bio *bio; 1265740432f8SJaegeuk Kim 1266740432f8SJaegeuk Kim /* No failure on bio allocation */ 1267740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 126880c54505SJaegeuk Kim if (!bio) 126980c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1270740432f8SJaegeuk Kim return bio; 1271740432f8SJaegeuk Kim } 1272740432f8SJaegeuk Kim 12739be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 12749be32d72SJaegeuk Kim unsigned long index, void *item) 12759be32d72SJaegeuk Kim { 12769be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 12779be32d72SJaegeuk Kim cond_resched(); 12789be32d72SJaegeuk Kim } 12799be32d72SJaegeuk Kim 128039a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 128139a53e0cSJaegeuk Kim 128239a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 128339a53e0cSJaegeuk Kim { 128445590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 128539a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 128639a53e0cSJaegeuk Kim } 128739a53e0cSJaegeuk Kim 128839a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 128939a53e0cSJaegeuk Kim { 129039a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 129139a53e0cSJaegeuk Kim } 129239a53e0cSJaegeuk Kim 129339a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 129439a53e0cSJaegeuk Kim unsigned int offset) 129539a53e0cSJaegeuk Kim { 129639a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 129739a53e0cSJaegeuk Kim __le32 *addr_array; 129845590710SGu Zheng raw_node = F2FS_NODE(node_page); 129939a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 130039a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 130139a53e0cSJaegeuk Kim } 130239a53e0cSJaegeuk Kim 130339a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 130439a53e0cSJaegeuk Kim { 130539a53e0cSJaegeuk Kim int mask; 130639a53e0cSJaegeuk Kim 130739a53e0cSJaegeuk Kim addr += (nr >> 3); 130839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 130939a53e0cSJaegeuk Kim return mask & *addr; 131039a53e0cSJaegeuk Kim } 131139a53e0cSJaegeuk Kim 1312a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1313a66cdd98SJaegeuk Kim { 1314a66cdd98SJaegeuk Kim int mask; 1315a66cdd98SJaegeuk Kim 1316a66cdd98SJaegeuk Kim addr += (nr >> 3); 1317a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1318a66cdd98SJaegeuk Kim *addr |= mask; 1319a66cdd98SJaegeuk Kim } 1320a66cdd98SJaegeuk Kim 1321a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1322a66cdd98SJaegeuk Kim { 1323a66cdd98SJaegeuk Kim int mask; 1324a66cdd98SJaegeuk Kim 1325a66cdd98SJaegeuk Kim addr += (nr >> 3); 1326a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1327a66cdd98SJaegeuk Kim *addr &= ~mask; 1328a66cdd98SJaegeuk Kim } 1329a66cdd98SJaegeuk Kim 133052aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 133139a53e0cSJaegeuk Kim { 133239a53e0cSJaegeuk Kim int mask; 133339a53e0cSJaegeuk Kim int ret; 133439a53e0cSJaegeuk Kim 133539a53e0cSJaegeuk Kim addr += (nr >> 3); 133639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 133739a53e0cSJaegeuk Kim ret = mask & *addr; 133839a53e0cSJaegeuk Kim *addr |= mask; 133939a53e0cSJaegeuk Kim return ret; 134039a53e0cSJaegeuk Kim } 134139a53e0cSJaegeuk Kim 134252aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 134339a53e0cSJaegeuk Kim { 134439a53e0cSJaegeuk Kim int mask; 134539a53e0cSJaegeuk Kim int ret; 134639a53e0cSJaegeuk Kim 134739a53e0cSJaegeuk Kim addr += (nr >> 3); 134839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 134939a53e0cSJaegeuk Kim ret = mask & *addr; 135039a53e0cSJaegeuk Kim *addr &= ~mask; 135139a53e0cSJaegeuk Kim return ret; 135239a53e0cSJaegeuk Kim } 135339a53e0cSJaegeuk Kim 1354c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1355c6ac4c0eSGu Zheng { 1356c6ac4c0eSGu Zheng int mask; 1357c6ac4c0eSGu Zheng 1358c6ac4c0eSGu Zheng addr += (nr >> 3); 1359c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1360c6ac4c0eSGu Zheng *addr ^= mask; 1361c6ac4c0eSGu Zheng } 1362c6ac4c0eSGu Zheng 136339a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 136439a53e0cSJaegeuk Kim enum { 136539a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1366b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1367ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 136839a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 136939a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 137039a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1371c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1372699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 137374d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1374c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1375444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 13761001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 137734d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1378fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1379fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 138088b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 138188b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 138202a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 13833c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 13841e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1385b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1386510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 138739a53e0cSJaegeuk Kim }; 138839a53e0cSJaegeuk Kim 138939a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 139039a53e0cSJaegeuk Kim { 139161e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 139239a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 139339a53e0cSJaegeuk Kim } 139439a53e0cSJaegeuk Kim 139539a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 139639a53e0cSJaegeuk Kim { 139739a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 139839a53e0cSJaegeuk Kim } 139939a53e0cSJaegeuk Kim 140039a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 140139a53e0cSJaegeuk Kim { 140261e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 140339a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 140439a53e0cSJaegeuk Kim } 140539a53e0cSJaegeuk Kim 140639a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 140739a53e0cSJaegeuk Kim { 140839a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 140939a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 141039a53e0cSJaegeuk Kim } 141139a53e0cSJaegeuk Kim 1412444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1413444c580fSJaegeuk Kim struct f2fs_inode *ri) 1414444c580fSJaegeuk Kim { 1415444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1416444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 14171001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 14181001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 141934d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 142034d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1421b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1422b3d208f9SJaegeuk Kim set_inode_flag(fi, FI_DATA_EXIST); 1423510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1424510022a8SJaegeuk Kim set_inode_flag(fi, FI_INLINE_DOTS); 1425444c580fSJaegeuk Kim } 1426444c580fSJaegeuk Kim 1427444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1428444c580fSJaegeuk Kim struct f2fs_inode *ri) 1429444c580fSJaegeuk Kim { 1430444c580fSJaegeuk Kim ri->i_inline = 0; 1431444c580fSJaegeuk Kim 1432444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1433444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 14341001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 14351001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 143634d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 143734d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1438b3d208f9SJaegeuk Kim if (is_inode_flag_set(fi, FI_DATA_EXIST)) 1439b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1440510022a8SJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_DOTS)) 1441510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1442444c580fSJaegeuk Kim } 1443444c580fSJaegeuk Kim 1444987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1445987c7c31SChao Yu { 1446987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1447987c7c31SChao Yu } 1448987c7c31SChao Yu 1449de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1450de93653fSJaegeuk Kim { 1451987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1452de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1453de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1454de93653fSJaegeuk Kim } 1455de93653fSJaegeuk Kim 145665985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 145765985d93SJaegeuk Kim { 1458695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 145965985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 146065985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 146165985d93SJaegeuk Kim } 146265985d93SJaegeuk Kim 146365985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 146465985d93SJaegeuk Kim { 1465987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 146665985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 146765985d93SJaegeuk Kim else 146865985d93SJaegeuk Kim return 0; 146965985d93SJaegeuk Kim } 147065985d93SJaegeuk Kim 14710dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 14720dbdc2aeSJaegeuk Kim { 14730dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 14740dbdc2aeSJaegeuk Kim } 14750dbdc2aeSJaegeuk Kim 1476b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1477b3d208f9SJaegeuk Kim { 1478b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 1479b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1480b3d208f9SJaegeuk Kim } 1481b3d208f9SJaegeuk Kim 1482b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1483b3d208f9SJaegeuk Kim { 1484b3d208f9SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST); 1485b3d208f9SJaegeuk Kim } 1486b3d208f9SJaegeuk Kim 1487510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1488510022a8SJaegeuk Kim { 1489510022a8SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS); 1490510022a8SJaegeuk Kim } 1491510022a8SJaegeuk Kim 149288b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 149388b88a66SJaegeuk Kim { 149488b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 149588b88a66SJaegeuk Kim } 149688b88a66SJaegeuk Kim 149702a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 149802a1335fSJaegeuk Kim { 149902a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 150002a1335fSJaegeuk Kim } 150102a1335fSJaegeuk Kim 15023c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 15033c6c2bebSJaegeuk Kim { 15043c6c2bebSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); 15053c6c2bebSJaegeuk Kim } 15063c6c2bebSJaegeuk Kim 15071e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 15081e84371fSJaegeuk Kim { 15091e84371fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE); 15101e84371fSJaegeuk Kim } 15111e84371fSJaegeuk Kim 15121001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 15131001b347SHuajun Li { 1514695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 15151001b347SHuajun Li return (void *)&(ri->i_addr[1]); 15161001b347SHuajun Li } 15171001b347SHuajun Li 151834d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 151934d67debSChao Yu { 152034d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 152134d67debSChao Yu } 152234d67debSChao Yu 15239486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 15249486ba44SJaegeuk Kim { 15259486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 15269486ba44SJaegeuk Kim kunmap(page); 15279486ba44SJaegeuk Kim } 15289486ba44SJaegeuk Kim 1529b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1530b5492af7SJaegeuk Kim { 1531b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1532b5492af7SJaegeuk Kim } 1533b5492af7SJaegeuk Kim 1534b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1535b5492af7SJaegeuk Kim { 1536b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1537b5492af7SJaegeuk Kim } 1538b5492af7SJaegeuk Kim 1539b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1540b5492af7SJaegeuk Kim { 1541b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1542b5492af7SJaegeuk Kim } 1543b5492af7SJaegeuk Kim 154477888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 154577888c1eSJaegeuk Kim { 154677888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 154777888c1eSJaegeuk Kim } 154877888c1eSJaegeuk Kim 15491e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 15501e968fdfSJaegeuk Kim { 15511e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 15521e968fdfSJaegeuk Kim } 15531e968fdfSJaegeuk Kim 1554744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1555744602cfSJaegeuk Kim { 1556744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1557744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1558744602cfSJaegeuk Kim } 1559744602cfSJaegeuk Kim 1560eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1561eaa693f4SJaegeuk Kim { 1562eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1563eaa693f4SJaegeuk Kim return true; 1564eaa693f4SJaegeuk Kim 1565eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1566eaa693f4SJaegeuk Kim return true; 1567eaa693f4SJaegeuk Kim 1568eaa693f4SJaegeuk Kim return false; 1569eaa693f4SJaegeuk Kim } 1570eaa693f4SJaegeuk Kim 15713e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 15723e72f721SJaegeuk Kim { 15733e72f721SJaegeuk Kim mode_t mode = inode->i_mode; 15743e72f721SJaegeuk Kim 15753e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 15763e72f721SJaegeuk Kim is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT)) 15773e72f721SJaegeuk Kim return false; 15783e72f721SJaegeuk Kim 15793e72f721SJaegeuk Kim return S_ISREG(mode); 15803e72f721SJaegeuk Kim } 15813e72f721SJaegeuk Kim 1582a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1583a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1584a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1585a6dda0e6SChristoph Hellwig 1586267378d4SChao Yu /* get offset of first page in next direct node */ 1587267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1588267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1589267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1590267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1591267378d4SChao Yu 159239a53e0cSJaegeuk Kim /* 159339a53e0cSJaegeuk Kim * file.c 159439a53e0cSJaegeuk Kim */ 159539a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 159639a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1597764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 1598b0154891SChao Yu int f2fs_truncate(struct inode *, bool); 15992d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 160039a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 160139a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1602b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 160339a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1604e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 160539a53e0cSJaegeuk Kim 160639a53e0cSJaegeuk Kim /* 160739a53e0cSJaegeuk Kim * inode.c 160839a53e0cSJaegeuk Kim */ 160939a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 161039a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 16114660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 161239a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *); 1613744602cfSJaegeuk Kim void update_inode_page(struct inode *); 161439a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 161539a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 161644c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 161739a53e0cSJaegeuk Kim 161839a53e0cSJaegeuk Kim /* 161939a53e0cSJaegeuk Kim * namei.c 162039a53e0cSJaegeuk Kim */ 162139a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 162239a53e0cSJaegeuk Kim 162339a53e0cSJaegeuk Kim /* 162439a53e0cSJaegeuk Kim * dir.c 162539a53e0cSJaegeuk Kim */ 1626dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1627510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 16286e22c691SJaegeuk Kim 16296e22c691SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct f2fs_filename *, 16306e22c691SJaegeuk Kim f2fs_hash_t, int *, struct f2fs_dentry_ptr *); 16317b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 1632d8c6822aSJaegeuk Kim unsigned int, struct f2fs_str *); 1633062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1634062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1635dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1636bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1637dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1638a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1639dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 164039a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 164139a53e0cSJaegeuk Kim struct page **); 164239a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 164339a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 164439a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 164539a53e0cSJaegeuk Kim struct page *, struct inode *); 1646e7d55452SJaegeuk Kim int update_dent_inode(struct inode *, struct inode *, const struct qstr *); 1647510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 16483b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1649510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1650510022a8SJaegeuk Kim umode_t); 1651dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1652dbeacf02SChao Yu struct inode *); 1653b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 165439a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 165539a53e0cSJaegeuk Kim 1656b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1657b7f7a5e0SAl Viro { 16582b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1659510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1660b7f7a5e0SAl Viro } 1661b7f7a5e0SAl Viro 166239a53e0cSJaegeuk Kim /* 166339a53e0cSJaegeuk Kim * super.c 166439a53e0cSJaegeuk Kim */ 1665c5bda1c8SChao Yu int f2fs_commit_super(struct f2fs_sb_info *, bool); 166639a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1667a07ef784SNamjae Jeon extern __printf(3, 4) 1668a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 166939a53e0cSJaegeuk Kim 167039a53e0cSJaegeuk Kim /* 167139a53e0cSJaegeuk Kim * hash.c 167239a53e0cSJaegeuk Kim */ 1673eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 167439a53e0cSJaegeuk Kim 167539a53e0cSJaegeuk Kim /* 167639a53e0cSJaegeuk Kim * node.c 167739a53e0cSJaegeuk Kim */ 167839a53e0cSJaegeuk Kim struct dnode_of_data; 167939a53e0cSJaegeuk Kim struct node_info; 168039a53e0cSJaegeuk Kim 16816fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 16822dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t); 168388bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 168488bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 168539a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 168639a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 168739a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 16884f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1689cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 1690*13ec7297SChao Yu int remove_inode_page(struct inode *); 1691a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 16928ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 169339a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 169439a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 169539a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 169639a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 169739a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 169839a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 169939a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 170039a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 170131696580SChao Yu int try_to_free_nids(struct f2fs_sb_info *, int); 170270cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 17031c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 170439a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 170539a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 170639a53e0cSJaegeuk Kim struct f2fs_summary_block *); 170739a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 170839a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 170939a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 17106e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 171139a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 171239a53e0cSJaegeuk Kim 171339a53e0cSJaegeuk Kim /* 171439a53e0cSJaegeuk Kim * segment.c 171539a53e0cSJaegeuk Kim */ 171688b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 1717edb27deeSJaegeuk Kim int commit_inmem_pages(struct inode *, bool); 171839a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *); 17194660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 17206b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 17212163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 17222163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 172339a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 17245e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 1725836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 17264b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1727e90c2d28SChao Yu bool discard_next_dnode(struct f2fs_sb_info *, block_t); 17283fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 172939a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 17304b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 173139a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1732381722d2SChao Yu void update_meta_page(struct f2fs_sb_info *, void *, block_t); 1733577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 173405ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 173505ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 173605ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 1737528e3459SChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *, 1738528e3459SChao Yu block_t, block_t, unsigned char, bool); 1739bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1740bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 17415514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 174239a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 174339a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 174439a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 174539a53e0cSJaegeuk Kim int, unsigned int, int); 17464b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 174739a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 174839a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 17497fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 17507fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 175139a53e0cSJaegeuk Kim 175239a53e0cSJaegeuk Kim /* 175339a53e0cSJaegeuk Kim * checkpoint.c 175439a53e0cSJaegeuk Kim */ 175539a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 175639a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 1757f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 17584c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int); 1759635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 176039a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1761fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1762fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 17636f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *); 1764fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1765cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1766cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 176739a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 176839a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 17698c14bfadSChao Yu int recover_orphan_inodes(struct f2fs_sb_info *); 177039a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1771a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 17725deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 177339a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *); 177439a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *); 177575ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 17766451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 17776e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 177839a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 177939a53e0cSJaegeuk Kim 178039a53e0cSJaegeuk Kim /* 178139a53e0cSJaegeuk Kim * data.c 178239a53e0cSJaegeuk Kim */ 1783458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 178405ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 178505ca3632SJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_io_info *); 1786216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 178739a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1788759af1c9SFan Li int f2fs_get_block(struct dnode_of_data *, pgoff_t); 1789b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 179043f3eae1SJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int); 179143f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t); 179239a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t); 179364aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 179405ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 17959ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1796487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1797487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 179839a53e0cSJaegeuk Kim 179939a53e0cSJaegeuk Kim /* 180039a53e0cSJaegeuk Kim * gc.c 180139a53e0cSJaegeuk Kim */ 180239a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 180339a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1804de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1805408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *); 180639a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 180739a53e0cSJaegeuk Kim 180839a53e0cSJaegeuk Kim /* 180939a53e0cSJaegeuk Kim * recovery.c 181039a53e0cSJaegeuk Kim */ 18116ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 181239a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 181339a53e0cSJaegeuk Kim 181439a53e0cSJaegeuk Kim /* 181539a53e0cSJaegeuk Kim * debug.c 181639a53e0cSJaegeuk Kim */ 181739a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 181839a53e0cSJaegeuk Kim struct f2fs_stat_info { 181939a53e0cSJaegeuk Kim struct list_head stat_list; 182039a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 182139a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 182239a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 1823029e13ccSChao Yu int hit_largest, hit_cached, hit_rbtree, hit_total, total_ext; 1824029e13ccSChao Yu int ext_tree, ext_node; 182539a53e0cSJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 1826dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 182739a53e0cSJaegeuk Kim int total_count, utilization; 1828d5e8f6c9SChao Yu int bg_gc, inmem_pages, wb_pages; 1829d5e8f6c9SChao Yu int inline_xattr, inline_inode, inline_dir; 183039a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 183139a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 183239a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 183339a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 183439a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1835942e0be6SChangman Lee int prefree_count, call_count, cp_count; 183639a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 1837e1235983SChangman Lee int bg_node_segs, bg_data_segs; 183839a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 1839e1235983SChangman Lee int bg_data_blks, bg_node_blks; 184039a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 184139a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 184239a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 184339a53e0cSJaegeuk Kim 184439a53e0cSJaegeuk Kim unsigned int segment_count[2]; 184539a53e0cSJaegeuk Kim unsigned int block_count[2]; 1846b9a2c252SChangman Lee unsigned int inplace_count; 18476f0aacbcSJaegeuk Kim unsigned base_mem, cache_mem, page_mem; 184839a53e0cSJaegeuk Kim }; 184939a53e0cSJaegeuk Kim 1850963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1851963d4f7dSGu Zheng { 1852963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1853963d4f7dSGu Zheng } 1854963d4f7dSGu Zheng 1855942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 185639a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1857dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1858dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1859dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 1860727edac5SChao Yu #define stat_inc_total_hit(sbi) (atomic_inc(&(sbi)->total_hit_ext)) 1861029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic_inc(&(sbi)->read_hit_rbtree)) 186291c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) (atomic_inc(&(sbi)->read_hit_largest)) 186391c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) (atomic_inc(&(sbi)->read_hit_cached)) 1864d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 1865d5e8f6c9SChao Yu do { \ 1866d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1867d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 1868d5e8f6c9SChao Yu } while (0) 1869d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 1870d5e8f6c9SChao Yu do { \ 1871d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1872d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 1873d5e8f6c9SChao Yu } while (0) 18740dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 18750dbdc2aeSJaegeuk Kim do { \ 18760dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 187703e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 18780dbdc2aeSJaegeuk Kim } while (0) 18790dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 18800dbdc2aeSJaegeuk Kim do { \ 18810dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 188203e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 18830dbdc2aeSJaegeuk Kim } while (0) 18843289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 18853289c061SJaegeuk Kim do { \ 18863289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 188703e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 18883289c061SJaegeuk Kim } while (0) 18893289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 18903289c061SJaegeuk Kim do { \ 18913289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 189203e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 18933289c061SJaegeuk Kim } while (0) 1894dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1895dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1896dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1897dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 1898b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 1899b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 1900e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 190139a53e0cSJaegeuk Kim do { \ 1902963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 190339a53e0cSJaegeuk Kim (si)->tot_segs++; \ 1904e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 190539a53e0cSJaegeuk Kim si->data_segs++; \ 1906e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 1907e1235983SChangman Lee } else { \ 190839a53e0cSJaegeuk Kim si->node_segs++; \ 1909e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 1910e1235983SChangman Lee } \ 191139a53e0cSJaegeuk Kim } while (0) 191239a53e0cSJaegeuk Kim 191339a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 191439a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 191539a53e0cSJaegeuk Kim 1916e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 191739a53e0cSJaegeuk Kim do { \ 1918963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 191939a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 192039a53e0cSJaegeuk Kim si->data_blks += (blks); \ 1921e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 192239a53e0cSJaegeuk Kim } while (0) 192339a53e0cSJaegeuk Kim 1924e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 192539a53e0cSJaegeuk Kim do { \ 1926963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 192739a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 192839a53e0cSJaegeuk Kim si->node_blks += (blks); \ 1929e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 193039a53e0cSJaegeuk Kim } while (0) 193139a53e0cSJaegeuk Kim 193239a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 193339a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 19346e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void); 19354589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 193639a53e0cSJaegeuk Kim #else 1937942e0be6SChangman Lee #define stat_inc_cp_count(si) 193839a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 1939dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 1940dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) 1941dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) 1942dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 1943029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 194491c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 194591c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 1946d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 1947d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 19480dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 19490dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 19503289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 19513289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 1952dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 1953dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 1954b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 1955e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 195639a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 1957e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 1958e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 195939a53e0cSJaegeuk Kim 196039a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 196139a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 19626e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { } 19634589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 196439a53e0cSJaegeuk Kim #endif 196539a53e0cSJaegeuk Kim 196639a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 196739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 196839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 196939a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 197039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 197139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 197239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 197339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 1974cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 197539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 197629e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 19771001b347SHuajun Li 1978e18c65b2SHuajun Li /* 1979e18c65b2SHuajun Li * inline.c 1980e18c65b2SHuajun Li */ 198101b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 198201b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 1983b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 19840bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 1985e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 1986b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 1987b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 1988b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 19890342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 19906e22c691SJaegeuk Kim struct f2fs_dir_entry *find_in_inline_dir(struct inode *, 19916e22c691SJaegeuk Kim struct f2fs_filename *, struct page **); 1992201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 1993201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 1994510022a8SJaegeuk Kim int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 1995510022a8SJaegeuk Kim nid_t, umode_t); 1996201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 1997201a05beSChao Yu struct inode *, struct inode *); 1998201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 1999d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *, struct dir_context *, 2000d8c6822aSJaegeuk Kim struct f2fs_str *); 2001cde4de12SJaegeuk Kim 2002cde4de12SJaegeuk Kim /* 20032658e50dSJaegeuk Kim * shrinker.c 20042658e50dSJaegeuk Kim */ 20052658e50dSJaegeuk Kim unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *); 20062658e50dSJaegeuk Kim unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *); 20072658e50dSJaegeuk Kim void f2fs_join_shrinker(struct f2fs_sb_info *); 20082658e50dSJaegeuk Kim void f2fs_leave_shrinker(struct f2fs_sb_info *); 20092658e50dSJaegeuk Kim 20102658e50dSJaegeuk Kim /* 2011a28ef1f5SChao Yu * extent_cache.c 2012a28ef1f5SChao Yu */ 2013a28ef1f5SChao Yu unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 2014a28ef1f5SChao Yu void f2fs_drop_largest_extent(struct inode *, pgoff_t); 2015a28ef1f5SChao Yu void f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 2016a28ef1f5SChao Yu unsigned int f2fs_destroy_extent_node(struct inode *); 2017a28ef1f5SChao Yu void f2fs_destroy_extent_tree(struct inode *); 2018a28ef1f5SChao Yu bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *); 2019a28ef1f5SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 2020a28ef1f5SChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 2021a28ef1f5SChao Yu int __init create_extent_cache(void); 2022a28ef1f5SChao Yu void destroy_extent_cache(void); 2023a28ef1f5SChao Yu 2024a28ef1f5SChao Yu /* 2025cde4de12SJaegeuk Kim * crypto support 2026cde4de12SJaegeuk Kim */ 2027cde4de12SJaegeuk Kim static inline int f2fs_encrypted_inode(struct inode *inode) 2028cde4de12SJaegeuk Kim { 2029cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2030cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2031cde4de12SJaegeuk Kim #else 2032cde4de12SJaegeuk Kim return 0; 2033cde4de12SJaegeuk Kim #endif 2034cde4de12SJaegeuk Kim } 2035cde4de12SJaegeuk Kim 2036cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2037cde4de12SJaegeuk Kim { 2038cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2039cde4de12SJaegeuk Kim file_set_encrypt(inode); 2040cde4de12SJaegeuk Kim #endif 2041cde4de12SJaegeuk Kim } 2042cde4de12SJaegeuk Kim 2043cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2044cde4de12SJaegeuk Kim { 2045cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2046cde4de12SJaegeuk Kim return unlikely(bio->bi_private != NULL); 2047cde4de12SJaegeuk Kim #else 2048cde4de12SJaegeuk Kim return false; 2049cde4de12SJaegeuk Kim #endif 2050cde4de12SJaegeuk Kim } 2051cde4de12SJaegeuk Kim 2052cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2053cde4de12SJaegeuk Kim { 2054cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2055cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2056cde4de12SJaegeuk Kim #else 2057cde4de12SJaegeuk Kim return 0; 2058cde4de12SJaegeuk Kim #endif 2059cde4de12SJaegeuk Kim } 2060f424f664SJaegeuk Kim 2061fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2062fcc85a4dSJaegeuk Kim { 2063fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2064fcc85a4dSJaegeuk Kim mode_t mode = inode->i_mode; 2065fcc85a4dSJaegeuk Kim 2066fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2067fcc85a4dSJaegeuk Kim #else 2068fcc85a4dSJaegeuk Kim return 0; 2069fcc85a4dSJaegeuk Kim #endif 2070fcc85a4dSJaegeuk Kim } 2071fcc85a4dSJaegeuk Kim 2072f424f664SJaegeuk Kim /* crypto_policy.c */ 2073f424f664SJaegeuk Kim int f2fs_is_child_context_consistent_with_parent(struct inode *, 2074f424f664SJaegeuk Kim struct inode *); 2075f424f664SJaegeuk Kim int f2fs_inherit_context(struct inode *, struct inode *, struct page *); 2076f424f664SJaegeuk Kim int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *); 2077f424f664SJaegeuk Kim int f2fs_get_policy(struct inode *, struct f2fs_encryption_policy *); 207857e5055bSJaegeuk Kim 207957e5055bSJaegeuk Kim /* crypt.c */ 20808bacf6deSJaegeuk Kim extern struct kmem_cache *f2fs_crypt_info_cachep; 208157e5055bSJaegeuk Kim bool f2fs_valid_contents_enc_mode(uint32_t); 208257e5055bSJaegeuk Kim uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t); 208357e5055bSJaegeuk Kim struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *); 208457e5055bSJaegeuk Kim void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *); 208557e5055bSJaegeuk Kim struct page *f2fs_encrypt(struct inode *, struct page *); 208657e5055bSJaegeuk Kim int f2fs_decrypt(struct f2fs_crypto_ctx *, struct page *); 208757e5055bSJaegeuk Kim int f2fs_decrypt_one(struct inode *, struct page *); 208857e5055bSJaegeuk Kim void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *); 208957e5055bSJaegeuk Kim 20900adda907SJaegeuk Kim /* crypto_key.c */ 209126bf3dc7SJaegeuk Kim void f2fs_free_encryption_info(struct inode *, struct f2fs_crypt_info *); 20920adda907SJaegeuk Kim int _f2fs_get_encryption_info(struct inode *inode); 20930adda907SJaegeuk Kim 20946b3bd08fSJaegeuk Kim /* crypto_fname.c */ 20956b3bd08fSJaegeuk Kim bool f2fs_valid_filenames_enc_mode(uint32_t); 20966b3bd08fSJaegeuk Kim u32 f2fs_fname_crypto_round_up(u32, u32); 20976b3bd08fSJaegeuk Kim int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *); 20986b3bd08fSJaegeuk Kim int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *, 20996b3bd08fSJaegeuk Kim const struct f2fs_str *, struct f2fs_str *); 21006b3bd08fSJaegeuk Kim int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *, 21016b3bd08fSJaegeuk Kim struct f2fs_str *); 21026b3bd08fSJaegeuk Kim 210357e5055bSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 210457e5055bSJaegeuk Kim void f2fs_restore_and_release_control_page(struct page **); 210557e5055bSJaegeuk Kim void f2fs_restore_control_page(struct page *); 210657e5055bSJaegeuk Kim 2107cfc4d971SJaegeuk Kim int __init f2fs_init_crypto(void); 2108cfc4d971SJaegeuk Kim int f2fs_crypto_initialize(void); 210957e5055bSJaegeuk Kim void f2fs_exit_crypto(void); 21100adda907SJaegeuk Kim 21110adda907SJaegeuk Kim int f2fs_has_encryption_key(struct inode *); 21120adda907SJaegeuk Kim 21130adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *inode) 21140adda907SJaegeuk Kim { 21150adda907SJaegeuk Kim struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info; 21160adda907SJaegeuk Kim 21170adda907SJaegeuk Kim if (!ci || 21180adda907SJaegeuk Kim (ci->ci_keyring_key && 21190adda907SJaegeuk Kim (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | 21200adda907SJaegeuk Kim (1 << KEY_FLAG_REVOKED) | 21210adda907SJaegeuk Kim (1 << KEY_FLAG_DEAD))))) 21220adda907SJaegeuk Kim return _f2fs_get_encryption_info(inode); 21230adda907SJaegeuk Kim return 0; 21240adda907SJaegeuk Kim } 21256b3bd08fSJaegeuk Kim 21266b3bd08fSJaegeuk Kim void f2fs_fname_crypto_free_buffer(struct f2fs_str *); 21276b3bd08fSJaegeuk Kim int f2fs_fname_setup_filename(struct inode *, const struct qstr *, 21286b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *); 21296b3bd08fSJaegeuk Kim void f2fs_fname_free_filename(struct f2fs_filename *); 213057e5055bSJaegeuk Kim #else 213157e5055bSJaegeuk Kim static inline void f2fs_restore_and_release_control_page(struct page **p) { } 213257e5055bSJaegeuk Kim static inline void f2fs_restore_control_page(struct page *p) { } 213357e5055bSJaegeuk Kim 2134cfc4d971SJaegeuk Kim static inline int __init f2fs_init_crypto(void) { return 0; } 213557e5055bSJaegeuk Kim static inline void f2fs_exit_crypto(void) { } 21360adda907SJaegeuk Kim 21370adda907SJaegeuk Kim static inline int f2fs_has_encryption_key(struct inode *i) { return 0; } 21380adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *i) { return 0; } 21396b3bd08fSJaegeuk Kim static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { } 21406b3bd08fSJaegeuk Kim 21416b3bd08fSJaegeuk Kim static inline int f2fs_fname_setup_filename(struct inode *dir, 21426b3bd08fSJaegeuk Kim const struct qstr *iname, 21436b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *fname) 21446b3bd08fSJaegeuk Kim { 21456b3bd08fSJaegeuk Kim memset(fname, 0, sizeof(struct f2fs_filename)); 21466b3bd08fSJaegeuk Kim fname->usr_fname = iname; 21476b3bd08fSJaegeuk Kim fname->disk_name.name = (unsigned char *)iname->name; 21486b3bd08fSJaegeuk Kim fname->disk_name.len = iname->len; 21496b3bd08fSJaegeuk Kim return 0; 21506b3bd08fSJaegeuk Kim } 21516b3bd08fSJaegeuk Kim 21526b3bd08fSJaegeuk Kim static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { } 215357e5055bSJaegeuk Kim #endif 215439a53e0cSJaegeuk Kim #endif 2155