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 378*e2b4e2bcSChao Yu /* for flag in get_data_block */ 379*e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 380*e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 381*e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 382*e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 383*e2b4e2bcSChao 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 */ 791727edac5SChao Yu atomic_t read_hit_ext; /* # of hit extent cache */ 792d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 79303e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 79403e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 79539a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 79635b09d82SNamjae Jeon unsigned int n_dirty_dirs; /* # of dir inodes */ 79735b09d82SNamjae Jeon #endif 79835b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 79939a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 800b59d0baeSNamjae Jeon 801b59d0baeSNamjae Jeon /* For sysfs suppport */ 802b59d0baeSNamjae Jeon struct kobject s_kobj; 803b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 8042658e50dSJaegeuk Kim 8052658e50dSJaegeuk Kim /* For shrinker support */ 8062658e50dSJaegeuk Kim struct list_head s_list; 8072658e50dSJaegeuk Kim struct mutex umount_mutex; 8082658e50dSJaegeuk Kim unsigned int shrinker_run_no; 80939a53e0cSJaegeuk Kim }; 81039a53e0cSJaegeuk Kim 81139a53e0cSJaegeuk Kim /* 81239a53e0cSJaegeuk Kim * Inline functions 81339a53e0cSJaegeuk Kim */ 81439a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 81539a53e0cSJaegeuk Kim { 81639a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 81739a53e0cSJaegeuk Kim } 81839a53e0cSJaegeuk Kim 81939a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 82039a53e0cSJaegeuk Kim { 82139a53e0cSJaegeuk Kim return sb->s_fs_info; 82239a53e0cSJaegeuk Kim } 82339a53e0cSJaegeuk Kim 8244081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 8254081363fSJaegeuk Kim { 8264081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 8274081363fSJaegeuk Kim } 8284081363fSJaegeuk Kim 8294081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 8304081363fSJaegeuk Kim { 8314081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 8324081363fSJaegeuk Kim } 8334081363fSJaegeuk Kim 8344081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 8354081363fSJaegeuk Kim { 8364081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 8374081363fSJaegeuk Kim } 8384081363fSJaegeuk Kim 83939a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 84039a53e0cSJaegeuk Kim { 84139a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 84239a53e0cSJaegeuk Kim } 84339a53e0cSJaegeuk Kim 84439a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 84539a53e0cSJaegeuk Kim { 84639a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 84739a53e0cSJaegeuk Kim } 84839a53e0cSJaegeuk Kim 84945590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 85045590710SGu Zheng { 85145590710SGu Zheng return (struct f2fs_node *)page_address(page); 85245590710SGu Zheng } 85345590710SGu Zheng 85458bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 85558bfaf44SJaegeuk Kim { 85658bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 85758bfaf44SJaegeuk Kim } 85858bfaf44SJaegeuk Kim 85939a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 86039a53e0cSJaegeuk Kim { 86139a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 86239a53e0cSJaegeuk Kim } 86339a53e0cSJaegeuk Kim 86439a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 86539a53e0cSJaegeuk Kim { 86639a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 86739a53e0cSJaegeuk Kim } 86839a53e0cSJaegeuk Kim 86939a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 87039a53e0cSJaegeuk Kim { 87139a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 87239a53e0cSJaegeuk Kim } 87339a53e0cSJaegeuk Kim 87439a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 87539a53e0cSJaegeuk Kim { 87639a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 87739a53e0cSJaegeuk Kim } 87839a53e0cSJaegeuk Kim 87939a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 88039a53e0cSJaegeuk Kim { 88139a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 88239a53e0cSJaegeuk Kim } 88339a53e0cSJaegeuk Kim 8849df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 8859df27d98SGu Zheng { 8869df27d98SGu Zheng return sbi->meta_inode->i_mapping; 8879df27d98SGu Zheng } 8889df27d98SGu Zheng 8894ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 8904ef51a8fSJaegeuk Kim { 8914ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 8924ef51a8fSJaegeuk Kim } 8934ef51a8fSJaegeuk Kim 894caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 89539a53e0cSJaegeuk Kim { 896caf0047eSChao Yu return sbi->s_flag & (0x01 << type); 89739a53e0cSJaegeuk Kim } 89839a53e0cSJaegeuk Kim 899caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 90039a53e0cSJaegeuk Kim { 901caf0047eSChao Yu sbi->s_flag |= (0x01 << type); 902caf0047eSChao Yu } 903caf0047eSChao Yu 904caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 905caf0047eSChao Yu { 906caf0047eSChao Yu sbi->s_flag &= ~(0x01 << type); 90739a53e0cSJaegeuk Kim } 90839a53e0cSJaegeuk Kim 909d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 910d71b5564SJaegeuk Kim { 911d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 912d71b5564SJaegeuk Kim } 913d71b5564SJaegeuk Kim 91425ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 91525ca923bSJaegeuk Kim { 91625ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 91725ca923bSJaegeuk Kim return ckpt_flags & f; 91825ca923bSJaegeuk Kim } 91925ca923bSJaegeuk Kim 92025ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 92125ca923bSJaegeuk Kim { 92225ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 92325ca923bSJaegeuk Kim ckpt_flags |= f; 92425ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 92525ca923bSJaegeuk Kim } 92625ca923bSJaegeuk Kim 92725ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 92825ca923bSJaegeuk Kim { 92925ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 93025ca923bSJaegeuk Kim ckpt_flags &= (~f); 93125ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 93225ca923bSJaegeuk Kim } 93325ca923bSJaegeuk Kim 934e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 93539a53e0cSJaegeuk Kim { 936e479556bSGu Zheng down_read(&sbi->cp_rwsem); 93739a53e0cSJaegeuk Kim } 93839a53e0cSJaegeuk Kim 939e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 94039a53e0cSJaegeuk Kim { 941e479556bSGu Zheng up_read(&sbi->cp_rwsem); 94239936837SJaegeuk Kim } 94339936837SJaegeuk Kim 944e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 94539936837SJaegeuk Kim { 9460daaad97SJaegeuk Kim f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex); 94739936837SJaegeuk Kim } 94839936837SJaegeuk Kim 949e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 95039936837SJaegeuk Kim { 951e479556bSGu Zheng up_write(&sbi->cp_rwsem); 95239a53e0cSJaegeuk Kim } 95339a53e0cSJaegeuk Kim 954119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 955119ee914SJaegeuk Kim { 956119ee914SJaegeuk Kim int reason = CP_SYNC; 957119ee914SJaegeuk Kim 958119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 959119ee914SJaegeuk Kim reason = CP_FASTBOOT; 960119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 961119ee914SJaegeuk Kim reason = CP_UMOUNT; 962119ee914SJaegeuk Kim return reason; 963119ee914SJaegeuk Kim } 964119ee914SJaegeuk Kim 965119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 966119ee914SJaegeuk Kim { 967119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 968119ee914SJaegeuk Kim } 969119ee914SJaegeuk Kim 970119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 971119ee914SJaegeuk Kim { 972119ee914SJaegeuk Kim return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) || 973119ee914SJaegeuk Kim is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG)); 974119ee914SJaegeuk Kim } 975119ee914SJaegeuk Kim 97639a53e0cSJaegeuk Kim /* 97739a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 97839a53e0cSJaegeuk Kim */ 979064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 98039a53e0cSJaegeuk Kim { 981d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 982d6b7d4b3SChao Yu return -EINVAL; 983cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 984064e0823SNamjae Jeon return -EINVAL; 985064e0823SNamjae Jeon return 0; 98639a53e0cSJaegeuk Kim } 98739a53e0cSJaegeuk Kim 98839a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 98939a53e0cSJaegeuk Kim 99039a53e0cSJaegeuk Kim /* 99139a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 99239a53e0cSJaegeuk Kim */ 99339a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 99439a53e0cSJaegeuk Kim { 99539a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 9966c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 99739a53e0cSJaegeuk Kim else 9986c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 99939a53e0cSJaegeuk Kim } 100039a53e0cSJaegeuk Kim 10014bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 10024bc8e9bcSChao Yu { 10034bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 10044bc8e9bcSChao Yu } 10054bc8e9bcSChao Yu 100639a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 100739a53e0cSJaegeuk Kim struct inode *inode, blkcnt_t count) 100839a53e0cSJaegeuk Kim { 100939a53e0cSJaegeuk Kim block_t valid_block_count; 101039a53e0cSJaegeuk Kim 101139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 101239a53e0cSJaegeuk Kim valid_block_count = 101339a53e0cSJaegeuk Kim sbi->total_valid_block_count + (block_t)count; 1014cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 101539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 101639a53e0cSJaegeuk Kim return false; 101739a53e0cSJaegeuk Kim } 101839a53e0cSJaegeuk Kim inode->i_blocks += count; 101939a53e0cSJaegeuk Kim sbi->total_valid_block_count = valid_block_count; 102039a53e0cSJaegeuk Kim sbi->alloc_valid_block_count += (block_t)count; 102139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 102239a53e0cSJaegeuk Kim return true; 102339a53e0cSJaegeuk Kim } 102439a53e0cSJaegeuk Kim 1025da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 102639a53e0cSJaegeuk Kim struct inode *inode, 102739a53e0cSJaegeuk Kim blkcnt_t count) 102839a53e0cSJaegeuk Kim { 102939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 10309850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 10319850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 103239a53e0cSJaegeuk Kim inode->i_blocks -= count; 103339a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 103439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 103539a53e0cSJaegeuk Kim } 103639a53e0cSJaegeuk Kim 103739a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 103839a53e0cSJaegeuk Kim { 103939a53e0cSJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 1040caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 104139a53e0cSJaegeuk Kim } 104239a53e0cSJaegeuk Kim 1043a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 104439a53e0cSJaegeuk Kim { 1045a7ffdbe2SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1046a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10474081363fSJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 104839a53e0cSJaegeuk Kim } 104939a53e0cSJaegeuk Kim 105039a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 105139a53e0cSJaegeuk Kim { 105239a53e0cSJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 105339a53e0cSJaegeuk Kim } 105439a53e0cSJaegeuk Kim 1055a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 105639a53e0cSJaegeuk Kim { 10575ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 10585ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 10591fe54f9dSJaegeuk Kim return; 10601fe54f9dSJaegeuk Kim 1061a7ffdbe2SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1062a7ffdbe2SJaegeuk Kim 1063a7ffdbe2SJaegeuk Kim if (S_ISDIR(inode->i_mode)) 10644081363fSJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 106539a53e0cSJaegeuk Kim } 106639a53e0cSJaegeuk Kim 106739a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) 106839a53e0cSJaegeuk Kim { 106939a53e0cSJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 107039a53e0cSJaegeuk Kim } 107139a53e0cSJaegeuk Kim 1072a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1073f8b2c1f9SJaegeuk Kim { 1074a7ffdbe2SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1075f8b2c1f9SJaegeuk Kim } 1076f8b2c1f9SJaegeuk Kim 10775ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 10785ac206cfSNamjae Jeon { 10795ac206cfSNamjae Jeon unsigned int pages_per_sec = sbi->segs_per_sec * 10805ac206cfSNamjae Jeon (1 << sbi->log_blocks_per_seg); 10815ac206cfSNamjae Jeon return ((get_pages(sbi, block_type) + pages_per_sec - 1) 10825ac206cfSNamjae Jeon >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 10835ac206cfSNamjae Jeon } 10845ac206cfSNamjae Jeon 108539a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 108639a53e0cSJaegeuk Kim { 10878b8343faSJaegeuk Kim return sbi->total_valid_block_count; 108839a53e0cSJaegeuk Kim } 108939a53e0cSJaegeuk Kim 109039a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 109139a53e0cSJaegeuk Kim { 109239a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 109339a53e0cSJaegeuk Kim 109439a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 109539a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 109639a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 109739a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 109839a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 109939a53e0cSJaegeuk Kim 110039a53e0cSJaegeuk Kim return 0; 110139a53e0cSJaegeuk Kim } 110239a53e0cSJaegeuk Kim 110355141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 110455141486SWanpeng Li { 110555141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 110655141486SWanpeng Li } 110755141486SWanpeng Li 110839a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 110939a53e0cSJaegeuk Kim { 111039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 11111dbe4152SChangman Lee int offset; 11121dbe4152SChangman Lee 111355141486SWanpeng Li if (__cp_payload(sbi) > 0) { 11141dbe4152SChangman Lee if (flag == NAT_BITMAP) 11151dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 11161dbe4152SChangman Lee else 111765b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 11181dbe4152SChangman Lee } else { 11191dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 112025ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 112139a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 112239a53e0cSJaegeuk Kim } 11231dbe4152SChangman Lee } 112439a53e0cSJaegeuk Kim 112539a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 112639a53e0cSJaegeuk Kim { 112739a53e0cSJaegeuk Kim block_t start_addr; 112839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1129d71b5564SJaegeuk Kim unsigned long long ckpt_version = cur_cp_version(ckpt); 113039a53e0cSJaegeuk Kim 113125ca923bSJaegeuk Kim start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 113239a53e0cSJaegeuk Kim 113339a53e0cSJaegeuk Kim /* 113439a53e0cSJaegeuk Kim * odd numbered checkpoint should at cp segment 0 1135e1c42045Sarter97 * and even segment must be at cp segment 1 113639a53e0cSJaegeuk Kim */ 113739a53e0cSJaegeuk Kim if (!(ckpt_version & 1)) 113839a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 113939a53e0cSJaegeuk Kim 114039a53e0cSJaegeuk Kim return start_addr; 114139a53e0cSJaegeuk Kim } 114239a53e0cSJaegeuk Kim 114339a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 114439a53e0cSJaegeuk Kim { 114539a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 114639a53e0cSJaegeuk Kim } 114739a53e0cSJaegeuk Kim 114839a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1149ef86d709SGu Zheng struct inode *inode) 115039a53e0cSJaegeuk Kim { 115139a53e0cSJaegeuk Kim block_t valid_block_count; 115239a53e0cSJaegeuk Kim unsigned int valid_node_count; 115339a53e0cSJaegeuk Kim 115439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 115539a53e0cSJaegeuk Kim 1156ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1157cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 115839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 115939a53e0cSJaegeuk Kim return false; 116039a53e0cSJaegeuk Kim } 116139a53e0cSJaegeuk Kim 1162ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1163cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 116439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 116539a53e0cSJaegeuk Kim return false; 116639a53e0cSJaegeuk Kim } 116739a53e0cSJaegeuk Kim 116839a53e0cSJaegeuk Kim if (inode) 1169ef86d709SGu Zheng inode->i_blocks++; 1170ef86d709SGu Zheng 1171ef86d709SGu Zheng sbi->alloc_valid_block_count++; 1172ef86d709SGu Zheng sbi->total_valid_node_count++; 1173ef86d709SGu Zheng sbi->total_valid_block_count++; 117439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 117539a53e0cSJaegeuk Kim 117639a53e0cSJaegeuk Kim return true; 117739a53e0cSJaegeuk Kim } 117839a53e0cSJaegeuk Kim 117939a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1180ef86d709SGu Zheng struct inode *inode) 118139a53e0cSJaegeuk Kim { 118239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 118339a53e0cSJaegeuk Kim 11849850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 11859850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 11869850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 118739a53e0cSJaegeuk Kim 1188ef86d709SGu Zheng inode->i_blocks--; 1189ef86d709SGu Zheng sbi->total_valid_node_count--; 1190ef86d709SGu Zheng sbi->total_valid_block_count--; 119139a53e0cSJaegeuk Kim 119239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 119339a53e0cSJaegeuk Kim } 119439a53e0cSJaegeuk Kim 119539a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 119639a53e0cSJaegeuk Kim { 11978b8343faSJaegeuk Kim return sbi->total_valid_node_count; 119839a53e0cSJaegeuk Kim } 119939a53e0cSJaegeuk Kim 120039a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 120139a53e0cSJaegeuk Kim { 120239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12039850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count); 120439a53e0cSJaegeuk Kim sbi->total_valid_inode_count++; 120539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 120639a53e0cSJaegeuk Kim } 120739a53e0cSJaegeuk Kim 12080e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 120939a53e0cSJaegeuk Kim { 121039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12119850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_inode_count); 121239a53e0cSJaegeuk Kim sbi->total_valid_inode_count--; 121339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 121439a53e0cSJaegeuk Kim } 121539a53e0cSJaegeuk Kim 121639a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi) 121739a53e0cSJaegeuk Kim { 12188b8343faSJaegeuk Kim return sbi->total_valid_inode_count; 121939a53e0cSJaegeuk Kim } 122039a53e0cSJaegeuk Kim 122139a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 122239a53e0cSJaegeuk Kim { 1223031fa8ccSJaegeuk Kim if (!page) 122439a53e0cSJaegeuk Kim return; 122539a53e0cSJaegeuk Kim 122639a53e0cSJaegeuk Kim if (unlock) { 12279850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 122839a53e0cSJaegeuk Kim unlock_page(page); 122939a53e0cSJaegeuk Kim } 123039a53e0cSJaegeuk Kim page_cache_release(page); 123139a53e0cSJaegeuk Kim } 123239a53e0cSJaegeuk Kim 123339a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 123439a53e0cSJaegeuk Kim { 123539a53e0cSJaegeuk Kim if (dn->node_page) 123639a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 123739a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 123839a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 123939a53e0cSJaegeuk Kim dn->node_page = NULL; 124039a53e0cSJaegeuk Kim dn->inode_page = NULL; 124139a53e0cSJaegeuk Kim } 124239a53e0cSJaegeuk Kim 124339a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1244e8512d2eSGu Zheng size_t size) 124539a53e0cSJaegeuk Kim { 1246e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 124739a53e0cSJaegeuk Kim } 124839a53e0cSJaegeuk Kim 12497bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 12507bd59381SGu Zheng gfp_t flags) 12517bd59381SGu Zheng { 12527bd59381SGu Zheng void *entry; 12537bd59381SGu Zheng retry: 12547bd59381SGu Zheng entry = kmem_cache_alloc(cachep, flags); 12557bd59381SGu Zheng if (!entry) { 12567bd59381SGu Zheng cond_resched(); 12577bd59381SGu Zheng goto retry; 12587bd59381SGu Zheng } 12597bd59381SGu Zheng 12607bd59381SGu Zheng return entry; 12617bd59381SGu Zheng } 12627bd59381SGu Zheng 1263740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1264740432f8SJaegeuk Kim { 1265740432f8SJaegeuk Kim struct bio *bio; 1266740432f8SJaegeuk Kim 1267740432f8SJaegeuk Kim /* No failure on bio allocation */ 1268740432f8SJaegeuk Kim retry: 1269740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 1270740432f8SJaegeuk Kim if (!bio) { 1271740432f8SJaegeuk Kim cond_resched(); 1272740432f8SJaegeuk Kim goto retry; 1273740432f8SJaegeuk Kim } 1274740432f8SJaegeuk Kim return bio; 1275740432f8SJaegeuk Kim } 1276740432f8SJaegeuk Kim 12779be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 12789be32d72SJaegeuk Kim unsigned long index, void *item) 12799be32d72SJaegeuk Kim { 12809be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 12819be32d72SJaegeuk Kim cond_resched(); 12829be32d72SJaegeuk Kim } 12839be32d72SJaegeuk Kim 128439a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 128539a53e0cSJaegeuk Kim 128639a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 128739a53e0cSJaegeuk Kim { 128845590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 128939a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 129039a53e0cSJaegeuk Kim } 129139a53e0cSJaegeuk Kim 129239a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 129339a53e0cSJaegeuk Kim { 129439a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 129539a53e0cSJaegeuk Kim } 129639a53e0cSJaegeuk Kim 129739a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 129839a53e0cSJaegeuk Kim unsigned int offset) 129939a53e0cSJaegeuk Kim { 130039a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 130139a53e0cSJaegeuk Kim __le32 *addr_array; 130245590710SGu Zheng raw_node = F2FS_NODE(node_page); 130339a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 130439a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 130539a53e0cSJaegeuk Kim } 130639a53e0cSJaegeuk Kim 130739a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 130839a53e0cSJaegeuk Kim { 130939a53e0cSJaegeuk Kim int mask; 131039a53e0cSJaegeuk Kim 131139a53e0cSJaegeuk Kim addr += (nr >> 3); 131239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 131339a53e0cSJaegeuk Kim return mask & *addr; 131439a53e0cSJaegeuk Kim } 131539a53e0cSJaegeuk Kim 1316a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1317a66cdd98SJaegeuk Kim { 1318a66cdd98SJaegeuk Kim int mask; 1319a66cdd98SJaegeuk Kim 1320a66cdd98SJaegeuk Kim addr += (nr >> 3); 1321a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1322a66cdd98SJaegeuk Kim *addr |= mask; 1323a66cdd98SJaegeuk Kim } 1324a66cdd98SJaegeuk Kim 1325a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1326a66cdd98SJaegeuk Kim { 1327a66cdd98SJaegeuk Kim int mask; 1328a66cdd98SJaegeuk Kim 1329a66cdd98SJaegeuk Kim addr += (nr >> 3); 1330a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1331a66cdd98SJaegeuk Kim *addr &= ~mask; 1332a66cdd98SJaegeuk Kim } 1333a66cdd98SJaegeuk Kim 133452aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 133539a53e0cSJaegeuk Kim { 133639a53e0cSJaegeuk Kim int mask; 133739a53e0cSJaegeuk Kim int ret; 133839a53e0cSJaegeuk Kim 133939a53e0cSJaegeuk Kim addr += (nr >> 3); 134039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 134139a53e0cSJaegeuk Kim ret = mask & *addr; 134239a53e0cSJaegeuk Kim *addr |= mask; 134339a53e0cSJaegeuk Kim return ret; 134439a53e0cSJaegeuk Kim } 134539a53e0cSJaegeuk Kim 134652aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 134739a53e0cSJaegeuk Kim { 134839a53e0cSJaegeuk Kim int mask; 134939a53e0cSJaegeuk Kim int ret; 135039a53e0cSJaegeuk Kim 135139a53e0cSJaegeuk Kim addr += (nr >> 3); 135239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 135339a53e0cSJaegeuk Kim ret = mask & *addr; 135439a53e0cSJaegeuk Kim *addr &= ~mask; 135539a53e0cSJaegeuk Kim return ret; 135639a53e0cSJaegeuk Kim } 135739a53e0cSJaegeuk Kim 1358c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1359c6ac4c0eSGu Zheng { 1360c6ac4c0eSGu Zheng int mask; 1361c6ac4c0eSGu Zheng 1362c6ac4c0eSGu Zheng addr += (nr >> 3); 1363c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1364c6ac4c0eSGu Zheng *addr ^= mask; 1365c6ac4c0eSGu Zheng } 1366c6ac4c0eSGu Zheng 136739a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 136839a53e0cSJaegeuk Kim enum { 136939a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1370b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 1371ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 137239a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 137339a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 137439a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1375c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1376699489bbSJaegeuk Kim FI_UPDATE_DIR, /* should update inode block for consistency */ 137774d0b917SJaegeuk Kim FI_DELAY_IPUT, /* used for the recovery */ 1378c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1379444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 13801001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 138134d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1382fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1383fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 138488b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 138588b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 138602a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 13873c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 13881e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1389b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1390510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 139139a53e0cSJaegeuk Kim }; 139239a53e0cSJaegeuk Kim 139339a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) 139439a53e0cSJaegeuk Kim { 139561e0f2d0SJaegeuk Kim if (!test_bit(flag, &fi->flags)) 139639a53e0cSJaegeuk Kim set_bit(flag, &fi->flags); 139739a53e0cSJaegeuk Kim } 139839a53e0cSJaegeuk Kim 139939a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) 140039a53e0cSJaegeuk Kim { 140139a53e0cSJaegeuk Kim return test_bit(flag, &fi->flags); 140239a53e0cSJaegeuk Kim } 140339a53e0cSJaegeuk Kim 140439a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) 140539a53e0cSJaegeuk Kim { 140661e0f2d0SJaegeuk Kim if (test_bit(flag, &fi->flags)) 140739a53e0cSJaegeuk Kim clear_bit(flag, &fi->flags); 140839a53e0cSJaegeuk Kim } 140939a53e0cSJaegeuk Kim 141039a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode) 141139a53e0cSJaegeuk Kim { 141239a53e0cSJaegeuk Kim fi->i_acl_mode = mode; 141339a53e0cSJaegeuk Kim set_inode_flag(fi, FI_ACL_MODE); 141439a53e0cSJaegeuk Kim } 141539a53e0cSJaegeuk Kim 1416444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi, 1417444c580fSJaegeuk Kim struct f2fs_inode *ri) 1418444c580fSJaegeuk Kim { 1419444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1420444c580fSJaegeuk Kim set_inode_flag(fi, FI_INLINE_XATTR); 14211001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 14221001b347SHuajun Li set_inode_flag(fi, FI_INLINE_DATA); 142334d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 142434d67debSChao Yu set_inode_flag(fi, FI_INLINE_DENTRY); 1425b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1426b3d208f9SJaegeuk Kim set_inode_flag(fi, FI_DATA_EXIST); 1427510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1428510022a8SJaegeuk Kim set_inode_flag(fi, FI_INLINE_DOTS); 1429444c580fSJaegeuk Kim } 1430444c580fSJaegeuk Kim 1431444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi, 1432444c580fSJaegeuk Kim struct f2fs_inode *ri) 1433444c580fSJaegeuk Kim { 1434444c580fSJaegeuk Kim ri->i_inline = 0; 1435444c580fSJaegeuk Kim 1436444c580fSJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_XATTR)) 1437444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 14381001b347SHuajun Li if (is_inode_flag_set(fi, FI_INLINE_DATA)) 14391001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 144034d67debSChao Yu if (is_inode_flag_set(fi, FI_INLINE_DENTRY)) 144134d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 1442b3d208f9SJaegeuk Kim if (is_inode_flag_set(fi, FI_DATA_EXIST)) 1443b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 1444510022a8SJaegeuk Kim if (is_inode_flag_set(fi, FI_INLINE_DOTS)) 1445510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1446444c580fSJaegeuk Kim } 1447444c580fSJaegeuk Kim 1448987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1449987c7c31SChao Yu { 1450987c7c31SChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR); 1451987c7c31SChao Yu } 1452987c7c31SChao Yu 1453de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi) 1454de93653fSJaegeuk Kim { 1455987c7c31SChao Yu if (f2fs_has_inline_xattr(&fi->vfs_inode)) 1456de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1457de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1458de93653fSJaegeuk Kim } 1459de93653fSJaegeuk Kim 146065985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 146165985d93SJaegeuk Kim { 1462695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 146365985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 146465985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 146565985d93SJaegeuk Kim } 146665985d93SJaegeuk Kim 146765985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 146865985d93SJaegeuk Kim { 1469987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 147065985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 147165985d93SJaegeuk Kim else 147265985d93SJaegeuk Kim return 0; 147365985d93SJaegeuk Kim } 147465985d93SJaegeuk Kim 14750dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 14760dbdc2aeSJaegeuk Kim { 14770dbdc2aeSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA); 14780dbdc2aeSJaegeuk Kim } 14790dbdc2aeSJaegeuk Kim 1480b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1481b3d208f9SJaegeuk Kim { 1482b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 1483b3d208f9SJaegeuk Kim clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1484b3d208f9SJaegeuk Kim } 1485b3d208f9SJaegeuk Kim 1486b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1487b3d208f9SJaegeuk Kim { 1488b3d208f9SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST); 1489b3d208f9SJaegeuk Kim } 1490b3d208f9SJaegeuk Kim 1491510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1492510022a8SJaegeuk Kim { 1493510022a8SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS); 1494510022a8SJaegeuk Kim } 1495510022a8SJaegeuk Kim 149688b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 149788b88a66SJaegeuk Kim { 149888b88a66SJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE); 149988b88a66SJaegeuk Kim } 150088b88a66SJaegeuk Kim 150102a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 150202a1335fSJaegeuk Kim { 150302a1335fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE); 150402a1335fSJaegeuk Kim } 150502a1335fSJaegeuk Kim 15063c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 15073c6c2bebSJaegeuk Kim { 15083c6c2bebSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN); 15093c6c2bebSJaegeuk Kim } 15103c6c2bebSJaegeuk Kim 15111e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 15121e84371fSJaegeuk Kim { 15131e84371fSJaegeuk Kim return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE); 15141e84371fSJaegeuk Kim } 15151e84371fSJaegeuk Kim 15161001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 15171001b347SHuajun Li { 1518695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 15191001b347SHuajun Li return (void *)&(ri->i_addr[1]); 15201001b347SHuajun Li } 15211001b347SHuajun Li 152234d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 152334d67debSChao Yu { 152434d67debSChao Yu return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY); 152534d67debSChao Yu } 152634d67debSChao Yu 15279486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 15289486ba44SJaegeuk Kim { 15299486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 15309486ba44SJaegeuk Kim kunmap(page); 15319486ba44SJaegeuk Kim } 15329486ba44SJaegeuk Kim 1533b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1534b5492af7SJaegeuk Kim { 1535b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1536b5492af7SJaegeuk Kim } 1537b5492af7SJaegeuk Kim 1538b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1539b5492af7SJaegeuk Kim { 1540b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 1541b5492af7SJaegeuk Kim } 1542b5492af7SJaegeuk Kim 1543b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1544b5492af7SJaegeuk Kim { 1545b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 1546b5492af7SJaegeuk Kim } 1547b5492af7SJaegeuk Kim 154877888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb) 154977888c1eSJaegeuk Kim { 155077888c1eSJaegeuk Kim return sb->s_flags & MS_RDONLY; 155177888c1eSJaegeuk Kim } 155277888c1eSJaegeuk Kim 15531e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 15541e968fdfSJaegeuk Kim { 15551e968fdfSJaegeuk Kim return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 15561e968fdfSJaegeuk Kim } 15571e968fdfSJaegeuk Kim 1558744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) 1559744602cfSJaegeuk Kim { 1560744602cfSJaegeuk Kim set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); 1561744602cfSJaegeuk Kim sbi->sb->s_flags |= MS_RDONLY; 1562744602cfSJaegeuk Kim } 1563744602cfSJaegeuk Kim 1564eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1565eaa693f4SJaegeuk Kim { 1566eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1567eaa693f4SJaegeuk Kim return true; 1568eaa693f4SJaegeuk Kim 1569eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1570eaa693f4SJaegeuk Kim return true; 1571eaa693f4SJaegeuk Kim 1572eaa693f4SJaegeuk Kim return false; 1573eaa693f4SJaegeuk Kim } 1574eaa693f4SJaegeuk Kim 15753e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 15763e72f721SJaegeuk Kim { 15773e72f721SJaegeuk Kim mode_t mode = inode->i_mode; 15783e72f721SJaegeuk Kim 15793e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 15803e72f721SJaegeuk Kim is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT)) 15813e72f721SJaegeuk Kim return false; 15823e72f721SJaegeuk Kim 15833e72f721SJaegeuk Kim return S_ISREG(mode); 15843e72f721SJaegeuk Kim } 15853e72f721SJaegeuk Kim 1586a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 1587a6dda0e6SChristoph Hellwig ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \ 1588a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 1589a6dda0e6SChristoph Hellwig 1590267378d4SChao Yu /* get offset of first page in next direct node */ 1591267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \ 1592267378d4SChao Yu ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \ 1593267378d4SChao Yu (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \ 1594267378d4SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi)) 1595267378d4SChao Yu 159639a53e0cSJaegeuk Kim /* 159739a53e0cSJaegeuk Kim * file.c 159839a53e0cSJaegeuk Kim */ 159939a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int); 160039a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *); 1601764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool); 160255f57d2cSChao Yu void f2fs_truncate(struct inode *, bool); 16032d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 160439a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *); 160539a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t); 1606b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int); 160739a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long); 1608e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); 160939a53e0cSJaegeuk Kim 161039a53e0cSJaegeuk Kim /* 161139a53e0cSJaegeuk Kim * inode.c 161239a53e0cSJaegeuk Kim */ 161339a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *); 161439a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long); 16154660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int); 161639a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *); 1617744602cfSJaegeuk Kim void update_inode_page(struct inode *); 161839a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *); 161939a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *); 162044c16156SJaegeuk Kim void handle_failed_inode(struct inode *); 162139a53e0cSJaegeuk Kim 162239a53e0cSJaegeuk Kim /* 162339a53e0cSJaegeuk Kim * namei.c 162439a53e0cSJaegeuk Kim */ 162539a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 162639a53e0cSJaegeuk Kim 162739a53e0cSJaegeuk Kim /* 162839a53e0cSJaegeuk Kim * dir.c 162939a53e0cSJaegeuk Kim */ 1630dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1631510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t); 16326e22c691SJaegeuk Kim 16336e22c691SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct f2fs_filename *, 16346e22c691SJaegeuk Kim f2fs_hash_t, int *, struct f2fs_dentry_ptr *); 16357b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 1636d8c6822aSJaegeuk Kim unsigned int, struct f2fs_str *); 1637062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *, 1638062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr *); 1639dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *, 1640bce8d112SJaegeuk Kim const struct qstr *, struct page *); 1641dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int); 1642a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int); 1643dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *); 164439a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, 164539a53e0cSJaegeuk Kim struct page **); 164639a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); 164739a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *); 164839a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, 164939a53e0cSJaegeuk Kim struct page *, struct inode *); 1650e7d55452SJaegeuk Kim int update_dent_inode(struct inode *, struct inode *, const struct qstr *); 1651510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *, 16523b4d732aSChao Yu const struct qstr *, f2fs_hash_t , unsigned int); 1653510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t, 1654510022a8SJaegeuk Kim umode_t); 1655dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *, 1656dbeacf02SChao Yu struct inode *); 1657b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *); 165839a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *); 165939a53e0cSJaegeuk Kim 1660b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 1661b7f7a5e0SAl Viro { 16622b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 1663510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 1664b7f7a5e0SAl Viro } 1665b7f7a5e0SAl Viro 166639a53e0cSJaegeuk Kim /* 166739a53e0cSJaegeuk Kim * super.c 166839a53e0cSJaegeuk Kim */ 1669c5bda1c8SChao Yu int f2fs_commit_super(struct f2fs_sb_info *, bool); 167039a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int); 1671a07ef784SNamjae Jeon extern __printf(3, 4) 1672a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...); 167339a53e0cSJaegeuk Kim 167439a53e0cSJaegeuk Kim /* 167539a53e0cSJaegeuk Kim * hash.c 167639a53e0cSJaegeuk Kim */ 1677eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *); 167839a53e0cSJaegeuk Kim 167939a53e0cSJaegeuk Kim /* 168039a53e0cSJaegeuk Kim * node.c 168139a53e0cSJaegeuk Kim */ 168239a53e0cSJaegeuk Kim struct dnode_of_data; 168339a53e0cSJaegeuk Kim struct node_info; 168439a53e0cSJaegeuk Kim 16856fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int); 16862dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t); 168788bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t); 168888bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t); 168939a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); 169039a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); 169139a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t); 16924f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *); 1693cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t); 169458e674d6SGu Zheng void remove_inode_page(struct inode *); 1695a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *); 16968ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); 169739a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t); 169839a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); 169939a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int); 170039a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *); 170139a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); 170239a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *); 170339a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t); 170439a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t); 170531696580SChao Yu int try_to_free_nids(struct f2fs_sb_info *, int); 170670cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *); 17071c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t); 170839a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *); 170939a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int, 171039a53e0cSJaegeuk Kim struct f2fs_summary_block *); 171139a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *); 171239a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *); 171339a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *); 17146e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 171539a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 171639a53e0cSJaegeuk Kim 171739a53e0cSJaegeuk Kim /* 171839a53e0cSJaegeuk Kim * segment.c 171939a53e0cSJaegeuk Kim */ 172088b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *); 1721edb27deeSJaegeuk Kim int commit_inmem_pages(struct inode *, bool); 172239a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *); 17234660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *); 17246b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *); 17252163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *); 17262163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *); 172739a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t); 17285e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); 1729836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); 17304b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *); 1731e90c2d28SChao Yu bool discard_next_dnode(struct f2fs_sb_info *, block_t); 17323fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool); 173339a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *); 17344b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *); 173539a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); 1736381722d2SChao Yu void update_meta_page(struct f2fs_sb_info *, void *, block_t); 1737577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *); 173805ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *); 173905ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); 174005ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *); 1741528e3459SChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *, 1742528e3459SChao Yu block_t, block_t, unsigned char, bool); 1743bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *, 1744bfad7c2dSJaegeuk Kim block_t, block_t *, struct f2fs_summary *, int); 17455514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type); 174639a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t); 174739a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t); 174839a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *, 174939a53e0cSJaegeuk Kim int, unsigned int, int); 17504b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *); 175139a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *); 175239a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *); 17537fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 17547fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 175539a53e0cSJaegeuk Kim 175639a53e0cSJaegeuk Kim /* 175739a53e0cSJaegeuk Kim * checkpoint.c 175839a53e0cSJaegeuk Kim */ 175939a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); 176039a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); 1761f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int); 17624c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int); 1763635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 176439a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1765fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1766fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 17676f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *); 1768fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1769cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *); 1770cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *); 177139a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t); 177239a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t); 17738c14bfadSChao Yu int recover_orphan_inodes(struct f2fs_sb_info *); 177439a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *); 1775a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *); 17765deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *); 177739a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *); 177839a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *); 177975ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 17806451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *); 17816e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 178239a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 178339a53e0cSJaegeuk Kim 178439a53e0cSJaegeuk Kim /* 178539a53e0cSJaegeuk Kim * data.c 178639a53e0cSJaegeuk Kim */ 1787458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int); 178805ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *); 178905ca3632SJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_io_info *); 1790216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *); 179139a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *); 1792759af1c9SFan Li int f2fs_get_block(struct dnode_of_data *, pgoff_t); 1793b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t); 179443f3eae1SJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int); 179543f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t); 179639a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t); 179764aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 179805ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *); 17999ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1800487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1801487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t); 180239a53e0cSJaegeuk Kim 180339a53e0cSJaegeuk Kim /* 180439a53e0cSJaegeuk Kim * gc.c 180539a53e0cSJaegeuk Kim */ 180639a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *); 180739a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *); 1808de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *); 1809408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *); 181039a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *); 181139a53e0cSJaegeuk Kim 181239a53e0cSJaegeuk Kim /* 181339a53e0cSJaegeuk Kim * recovery.c 181439a53e0cSJaegeuk Kim */ 18156ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *); 181639a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *); 181739a53e0cSJaegeuk Kim 181839a53e0cSJaegeuk Kim /* 181939a53e0cSJaegeuk Kim * debug.c 182039a53e0cSJaegeuk Kim */ 182139a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 182239a53e0cSJaegeuk Kim struct f2fs_stat_info { 182339a53e0cSJaegeuk Kim struct list_head stat_list; 182439a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 182539a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 182639a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 18274bf6fd9fSChao Yu int hit_ext, total_ext, ext_tree, ext_node; 182839a53e0cSJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 1829dd4e4b59SJaegeuk Kim int nats, dirty_nats, sits, dirty_sits, fnids; 183039a53e0cSJaegeuk Kim int total_count, utilization; 1831d5e8f6c9SChao Yu int bg_gc, inmem_pages, wb_pages; 1832d5e8f6c9SChao Yu int inline_xattr, inline_inode, inline_dir; 183339a53e0cSJaegeuk Kim unsigned int valid_count, valid_node_count, valid_inode_count; 183439a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 183539a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 183639a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 183739a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 1838942e0be6SChangman Lee int prefree_count, call_count, cp_count; 183939a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 1840e1235983SChangman Lee int bg_node_segs, bg_data_segs; 184139a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 1842e1235983SChangman Lee int bg_data_blks, bg_node_blks; 184339a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 184439a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 184539a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 184639a53e0cSJaegeuk Kim 184739a53e0cSJaegeuk Kim unsigned int segment_count[2]; 184839a53e0cSJaegeuk Kim unsigned int block_count[2]; 1849b9a2c252SChangman Lee unsigned int inplace_count; 18506f0aacbcSJaegeuk Kim unsigned base_mem, cache_mem, page_mem; 185139a53e0cSJaegeuk Kim }; 185239a53e0cSJaegeuk Kim 1853963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 1854963d4f7dSGu Zheng { 1855963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 1856963d4f7dSGu Zheng } 1857963d4f7dSGu Zheng 1858942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 185939a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 1860dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1861dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1862dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 1863727edac5SChao Yu #define stat_inc_total_hit(sbi) (atomic_inc(&(sbi)->total_hit_ext)) 1864727edac5SChao Yu #define stat_inc_read_hit(sbi) (atomic_inc(&(sbi)->read_hit_ext)) 1865d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 1866d5e8f6c9SChao Yu do { \ 1867d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1868d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 1869d5e8f6c9SChao Yu } while (0) 1870d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 1871d5e8f6c9SChao Yu do { \ 1872d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 1873d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 1874d5e8f6c9SChao Yu } while (0) 18750dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 18760dbdc2aeSJaegeuk Kim do { \ 18770dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 187803e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 18790dbdc2aeSJaegeuk Kim } while (0) 18800dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 18810dbdc2aeSJaegeuk Kim do { \ 18820dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 188303e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 18840dbdc2aeSJaegeuk Kim } while (0) 18853289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 18863289c061SJaegeuk Kim do { \ 18873289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 188803e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 18893289c061SJaegeuk Kim } while (0) 18903289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 18913289c061SJaegeuk Kim do { \ 18923289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 189303e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 18943289c061SJaegeuk Kim } while (0) 1895dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 1896dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 1897dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 1898dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 1899b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 1900b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 1901e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 190239a53e0cSJaegeuk Kim do { \ 1903963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 190439a53e0cSJaegeuk Kim (si)->tot_segs++; \ 1905e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 190639a53e0cSJaegeuk Kim si->data_segs++; \ 1907e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 1908e1235983SChangman Lee } else { \ 190939a53e0cSJaegeuk Kim si->node_segs++; \ 1910e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 1911e1235983SChangman Lee } \ 191239a53e0cSJaegeuk Kim } while (0) 191339a53e0cSJaegeuk Kim 191439a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 191539a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 191639a53e0cSJaegeuk Kim 1917e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 191839a53e0cSJaegeuk Kim do { \ 1919963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 192039a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 192139a53e0cSJaegeuk Kim si->data_blks += (blks); \ 1922e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 192339a53e0cSJaegeuk Kim } while (0) 192439a53e0cSJaegeuk Kim 1925e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 192639a53e0cSJaegeuk Kim do { \ 1927963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 192839a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 192939a53e0cSJaegeuk Kim si->node_blks += (blks); \ 1930e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 193139a53e0cSJaegeuk Kim } while (0) 193239a53e0cSJaegeuk Kim 193339a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *); 193439a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *); 19356e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void); 19364589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 193739a53e0cSJaegeuk Kim #else 1938942e0be6SChangman Lee #define stat_inc_cp_count(si) 193939a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 1940dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 1941dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi) 1942dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi) 1943dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 1944dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb) 1945d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 1946d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 19470dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 19480dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 19493289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 19503289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 1951dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 1952dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 1953b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 1954e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 195539a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 1956e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 1957e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 195839a53e0cSJaegeuk Kim 195939a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 196039a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 19616e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { } 19624589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 196339a53e0cSJaegeuk Kim #endif 196439a53e0cSJaegeuk Kim 196539a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 196639a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 196739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 196839a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 196939a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 197039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 197139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 197239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 1973cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 197439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 197529e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 19761001b347SHuajun Li 1977e18c65b2SHuajun Li /* 1978e18c65b2SHuajun Li * inline.c 1979e18c65b2SHuajun Li */ 198001b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *); 198101b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *); 1982b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *); 19830bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64); 1984e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *); 1985b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *); 1986b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *); 1987b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *); 19880342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *); 19896e22c691SJaegeuk Kim struct f2fs_dir_entry *find_in_inline_dir(struct inode *, 19906e22c691SJaegeuk Kim struct f2fs_filename *, struct page **); 1991201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 1992201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 1993510022a8SJaegeuk Kim int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 1994510022a8SJaegeuk Kim nid_t, umode_t); 1995201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, 1996201a05beSChao Yu struct inode *, struct inode *); 1997201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *); 1998d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *, struct dir_context *, 1999d8c6822aSJaegeuk Kim struct f2fs_str *); 2000cde4de12SJaegeuk Kim 2001cde4de12SJaegeuk Kim /* 20022658e50dSJaegeuk Kim * shrinker.c 20032658e50dSJaegeuk Kim */ 20042658e50dSJaegeuk Kim unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *); 20052658e50dSJaegeuk Kim unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *); 20062658e50dSJaegeuk Kim void f2fs_join_shrinker(struct f2fs_sb_info *); 20072658e50dSJaegeuk Kim void f2fs_leave_shrinker(struct f2fs_sb_info *); 20082658e50dSJaegeuk Kim 20092658e50dSJaegeuk Kim /* 2010a28ef1f5SChao Yu * extent_cache.c 2011a28ef1f5SChao Yu */ 2012a28ef1f5SChao Yu unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 2013a28ef1f5SChao Yu void f2fs_drop_largest_extent(struct inode *, pgoff_t); 2014a28ef1f5SChao Yu void f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 2015a28ef1f5SChao Yu unsigned int f2fs_destroy_extent_node(struct inode *); 2016a28ef1f5SChao Yu void f2fs_destroy_extent_tree(struct inode *); 2017a28ef1f5SChao Yu bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *); 2018a28ef1f5SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *); 2019a28ef1f5SChao Yu void init_extent_cache_info(struct f2fs_sb_info *); 2020a28ef1f5SChao Yu int __init create_extent_cache(void); 2021a28ef1f5SChao Yu void destroy_extent_cache(void); 2022a28ef1f5SChao Yu 2023a28ef1f5SChao Yu /* 2024cde4de12SJaegeuk Kim * crypto support 2025cde4de12SJaegeuk Kim */ 2026cde4de12SJaegeuk Kim static inline int f2fs_encrypted_inode(struct inode *inode) 2027cde4de12SJaegeuk Kim { 2028cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2029cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2030cde4de12SJaegeuk Kim #else 2031cde4de12SJaegeuk Kim return 0; 2032cde4de12SJaegeuk Kim #endif 2033cde4de12SJaegeuk Kim } 2034cde4de12SJaegeuk Kim 2035cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2036cde4de12SJaegeuk Kim { 2037cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2038cde4de12SJaegeuk Kim file_set_encrypt(inode); 2039cde4de12SJaegeuk Kim #endif 2040cde4de12SJaegeuk Kim } 2041cde4de12SJaegeuk Kim 2042cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2043cde4de12SJaegeuk Kim { 2044cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2045cde4de12SJaegeuk Kim return unlikely(bio->bi_private != NULL); 2046cde4de12SJaegeuk Kim #else 2047cde4de12SJaegeuk Kim return false; 2048cde4de12SJaegeuk Kim #endif 2049cde4de12SJaegeuk Kim } 2050cde4de12SJaegeuk Kim 2051cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2052cde4de12SJaegeuk Kim { 2053cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2054cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2055cde4de12SJaegeuk Kim #else 2056cde4de12SJaegeuk Kim return 0; 2057cde4de12SJaegeuk Kim #endif 2058cde4de12SJaegeuk Kim } 2059f424f664SJaegeuk Kim 2060fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2061fcc85a4dSJaegeuk Kim { 2062fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2063fcc85a4dSJaegeuk Kim mode_t mode = inode->i_mode; 2064fcc85a4dSJaegeuk Kim 2065fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2066fcc85a4dSJaegeuk Kim #else 2067fcc85a4dSJaegeuk Kim return 0; 2068fcc85a4dSJaegeuk Kim #endif 2069fcc85a4dSJaegeuk Kim } 2070fcc85a4dSJaegeuk Kim 2071f424f664SJaegeuk Kim /* crypto_policy.c */ 2072f424f664SJaegeuk Kim int f2fs_is_child_context_consistent_with_parent(struct inode *, 2073f424f664SJaegeuk Kim struct inode *); 2074f424f664SJaegeuk Kim int f2fs_inherit_context(struct inode *, struct inode *, struct page *); 2075f424f664SJaegeuk Kim int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *); 2076f424f664SJaegeuk Kim int f2fs_get_policy(struct inode *, struct f2fs_encryption_policy *); 207757e5055bSJaegeuk Kim 207857e5055bSJaegeuk Kim /* crypt.c */ 20798bacf6deSJaegeuk Kim extern struct kmem_cache *f2fs_crypt_info_cachep; 208057e5055bSJaegeuk Kim bool f2fs_valid_contents_enc_mode(uint32_t); 208157e5055bSJaegeuk Kim uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t); 208257e5055bSJaegeuk Kim struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *); 208357e5055bSJaegeuk Kim void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *); 208457e5055bSJaegeuk Kim struct page *f2fs_encrypt(struct inode *, struct page *); 208557e5055bSJaegeuk Kim int f2fs_decrypt(struct f2fs_crypto_ctx *, struct page *); 208657e5055bSJaegeuk Kim int f2fs_decrypt_one(struct inode *, struct page *); 208757e5055bSJaegeuk Kim void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *); 208857e5055bSJaegeuk Kim 20890adda907SJaegeuk Kim /* crypto_key.c */ 209026bf3dc7SJaegeuk Kim void f2fs_free_encryption_info(struct inode *, struct f2fs_crypt_info *); 20910adda907SJaegeuk Kim int _f2fs_get_encryption_info(struct inode *inode); 20920adda907SJaegeuk Kim 20936b3bd08fSJaegeuk Kim /* crypto_fname.c */ 20946b3bd08fSJaegeuk Kim bool f2fs_valid_filenames_enc_mode(uint32_t); 20956b3bd08fSJaegeuk Kim u32 f2fs_fname_crypto_round_up(u32, u32); 20966b3bd08fSJaegeuk Kim int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *); 20976b3bd08fSJaegeuk Kim int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *, 20986b3bd08fSJaegeuk Kim const struct f2fs_str *, struct f2fs_str *); 20996b3bd08fSJaegeuk Kim int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *, 21006b3bd08fSJaegeuk Kim struct f2fs_str *); 21016b3bd08fSJaegeuk Kim 210257e5055bSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 210357e5055bSJaegeuk Kim void f2fs_restore_and_release_control_page(struct page **); 210457e5055bSJaegeuk Kim void f2fs_restore_control_page(struct page *); 210557e5055bSJaegeuk Kim 2106cfc4d971SJaegeuk Kim int __init f2fs_init_crypto(void); 2107cfc4d971SJaegeuk Kim int f2fs_crypto_initialize(void); 210857e5055bSJaegeuk Kim void f2fs_exit_crypto(void); 21090adda907SJaegeuk Kim 21100adda907SJaegeuk Kim int f2fs_has_encryption_key(struct inode *); 21110adda907SJaegeuk Kim 21120adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *inode) 21130adda907SJaegeuk Kim { 21140adda907SJaegeuk Kim struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info; 21150adda907SJaegeuk Kim 21160adda907SJaegeuk Kim if (!ci || 21170adda907SJaegeuk Kim (ci->ci_keyring_key && 21180adda907SJaegeuk Kim (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | 21190adda907SJaegeuk Kim (1 << KEY_FLAG_REVOKED) | 21200adda907SJaegeuk Kim (1 << KEY_FLAG_DEAD))))) 21210adda907SJaegeuk Kim return _f2fs_get_encryption_info(inode); 21220adda907SJaegeuk Kim return 0; 21230adda907SJaegeuk Kim } 21246b3bd08fSJaegeuk Kim 21256b3bd08fSJaegeuk Kim void f2fs_fname_crypto_free_buffer(struct f2fs_str *); 21266b3bd08fSJaegeuk Kim int f2fs_fname_setup_filename(struct inode *, const struct qstr *, 21276b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *); 21286b3bd08fSJaegeuk Kim void f2fs_fname_free_filename(struct f2fs_filename *); 212957e5055bSJaegeuk Kim #else 213057e5055bSJaegeuk Kim static inline void f2fs_restore_and_release_control_page(struct page **p) { } 213157e5055bSJaegeuk Kim static inline void f2fs_restore_control_page(struct page *p) { } 213257e5055bSJaegeuk Kim 2133cfc4d971SJaegeuk Kim static inline int __init f2fs_init_crypto(void) { return 0; } 213457e5055bSJaegeuk Kim static inline void f2fs_exit_crypto(void) { } 21350adda907SJaegeuk Kim 21360adda907SJaegeuk Kim static inline int f2fs_has_encryption_key(struct inode *i) { return 0; } 21370adda907SJaegeuk Kim static inline int f2fs_get_encryption_info(struct inode *i) { return 0; } 21386b3bd08fSJaegeuk Kim static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { } 21396b3bd08fSJaegeuk Kim 21406b3bd08fSJaegeuk Kim static inline int f2fs_fname_setup_filename(struct inode *dir, 21416b3bd08fSJaegeuk Kim const struct qstr *iname, 21426b3bd08fSJaegeuk Kim int lookup, struct f2fs_filename *fname) 21436b3bd08fSJaegeuk Kim { 21446b3bd08fSJaegeuk Kim memset(fname, 0, sizeof(struct f2fs_filename)); 21456b3bd08fSJaegeuk Kim fname->usr_fname = iname; 21466b3bd08fSJaegeuk Kim fname->disk_name.name = (unsigned char *)iname->name; 21476b3bd08fSJaegeuk Kim fname->disk_name.len = iname->len; 21486b3bd08fSJaegeuk Kim return 0; 21496b3bd08fSJaegeuk Kim } 21506b3bd08fSJaegeuk Kim 21516b3bd08fSJaegeuk Kim static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { } 215257e5055bSJaegeuk Kim #endif 215339a53e0cSJaegeuk Kim #endif 2154