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> 2239307a8eSJaegeuk Kim #include <linux/vmalloc.h> 23740432f8SJaegeuk Kim #include <linux/bio.h> 24d0239e1bSJaegeuk Kim #include <linux/blkdev.h> 2546f47e48SEric Biggers #ifdef CONFIG_F2FS_FS_ENCRYPTION 2646f47e48SEric Biggers #include <linux/fscrypt_supp.h> 2746f47e48SEric Biggers #else 2846f47e48SEric Biggers #include <linux/fscrypt_notsupp.h> 2946f47e48SEric Biggers #endif 3043b6573bSKeith Mok #include <crypto/hash.h> 3139a53e0cSJaegeuk Kim 325d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 339850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 345d56b671SJaegeuk Kim #else 359850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 369850cf4aSJaegeuk Kim do { \ 379850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 389850cf4aSJaegeuk Kim WARN_ON(1); \ 39caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 409850cf4aSJaegeuk Kim } \ 419850cf4aSJaegeuk Kim } while (0) 425d56b671SJaegeuk Kim #endif 435d56b671SJaegeuk Kim 442c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 452c63feadSJaegeuk Kim enum { 462c63feadSJaegeuk Kim FAULT_KMALLOC, 47c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 48cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 49cb78942bSJaegeuk Kim FAULT_ORPHAN, 50cb78942bSJaegeuk Kim FAULT_BLOCK, 51cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5253aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 538b038c70SChao Yu FAULT_IO, 540f348028SChao Yu FAULT_CHECKPOINT, 552c63feadSJaegeuk Kim FAULT_MAX, 562c63feadSJaegeuk Kim }; 572c63feadSJaegeuk Kim 5808796897SSheng Yong struct f2fs_fault_info { 5908796897SSheng Yong atomic_t inject_ops; 6008796897SSheng Yong unsigned int inject_rate; 6108796897SSheng Yong unsigned int inject_type; 6208796897SSheng Yong }; 6308796897SSheng Yong 642c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX]; 651ecc0c5cSChao Yu #define IS_FAULT_SET(fi, type) (fi->inject_type & (1 << (type))) 662c63feadSJaegeuk Kim #endif 672c63feadSJaegeuk Kim 6839a53e0cSJaegeuk Kim /* 6939a53e0cSJaegeuk Kim * For mount options 7039a53e0cSJaegeuk Kim */ 7139a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 7239a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7439a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 7539a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 78444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 791001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8034d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8134d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8234d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 83d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8489672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 856aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 86343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 8773faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 8836abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 8936abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 9039a53e0cSJaegeuk Kim 9139a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 9239a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 9339a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 9439a53e0cSJaegeuk Kim 9539a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 9639a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 9739a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 9839a53e0cSJaegeuk Kim 99a9841c4dSJaegeuk Kim typedef u32 block_t; /* 100a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 101a9841c4dSJaegeuk Kim * address format, __le32. 102a9841c4dSJaegeuk Kim */ 10339a53e0cSJaegeuk Kim typedef u32 nid_t; 10439a53e0cSJaegeuk Kim 10539a53e0cSJaegeuk Kim struct f2fs_mount_info { 10639a53e0cSJaegeuk Kim unsigned int opt; 10739a53e0cSJaegeuk Kim }; 10839a53e0cSJaegeuk Kim 109cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1100bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 111cde4de12SJaegeuk Kim 11276f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 11376f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 11476f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 115c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 11676f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 117c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 11876f105a2SJaegeuk Kim 11939a53e0cSJaegeuk Kim /* 12039a53e0cSJaegeuk Kim * For checkpoint manager 12139a53e0cSJaegeuk Kim */ 12239a53e0cSJaegeuk Kim enum { 12339a53e0cSJaegeuk Kim NAT_BITMAP, 12439a53e0cSJaegeuk Kim SIT_BITMAP 12539a53e0cSJaegeuk Kim }; 12639a53e0cSJaegeuk Kim 12775ab4cb8SJaegeuk Kim enum { 12875ab4cb8SJaegeuk Kim CP_UMOUNT, 129119ee914SJaegeuk Kim CP_FASTBOOT, 13075ab4cb8SJaegeuk Kim CP_SYNC, 13110027551SJaegeuk Kim CP_RECOVERY, 1324b2fecc8SJaegeuk Kim CP_DISCARD, 13375ab4cb8SJaegeuk Kim }; 13475ab4cb8SJaegeuk Kim 13547b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 136bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 137bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 138a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 139a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 140ad4d307fSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) \ 141ad4d307fSJaegeuk Kim ((1 << (sbi)->log_blocks_per_seg) * (sbi)->segs_per_sec) 14215469963SJaegeuk Kim #define DISCARD_ISSUE_RATE 8 14360b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 144dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 145bba681cbSJaegeuk Kim 14675ab4cb8SJaegeuk Kim struct cp_control { 14775ab4cb8SJaegeuk Kim int reason; 1484b2fecc8SJaegeuk Kim __u64 trim_start; 1494b2fecc8SJaegeuk Kim __u64 trim_end; 1504b2fecc8SJaegeuk Kim __u64 trim_minlen; 1514b2fecc8SJaegeuk Kim __u64 trimmed; 15275ab4cb8SJaegeuk Kim }; 15375ab4cb8SJaegeuk Kim 154662befdaSChao Yu /* 15581c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 156662befdaSChao Yu */ 157662befdaSChao Yu enum { 158662befdaSChao Yu META_CP, 159662befdaSChao Yu META_NAT, 16081c1a0f1SChao Yu META_SIT, 1614c521f49SJaegeuk Kim META_SSA, 1624c521f49SJaegeuk Kim META_POR, 163662befdaSChao Yu }; 164662befdaSChao Yu 1656451e041SJaegeuk Kim /* for the list of ino */ 1666451e041SJaegeuk Kim enum { 1676451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 168fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 169fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1706451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1716451e041SJaegeuk Kim }; 1726451e041SJaegeuk Kim 1736451e041SJaegeuk Kim struct ino_entry { 17439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17539a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 17639a53e0cSJaegeuk Kim }; 17739a53e0cSJaegeuk Kim 1782710fd7eSChao Yu /* for the list of inodes to be GCed */ 17906292073SChao Yu struct inode_entry { 18039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 18239a53e0cSJaegeuk Kim }; 18339a53e0cSJaegeuk Kim 1847fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1857fd9e544SJaegeuk Kim struct discard_entry { 1867fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1877fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1887fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1897fd9e544SJaegeuk Kim }; 1907fd9e544SJaegeuk Kim 19115469963SJaegeuk Kim enum { 19215469963SJaegeuk Kim D_PREP, 19315469963SJaegeuk Kim D_SUBMIT, 19415469963SJaegeuk Kim D_DONE, 19515469963SJaegeuk Kim }; 19615469963SJaegeuk Kim 197b01a9201SJaegeuk Kim struct discard_cmd { 198b01a9201SJaegeuk Kim struct list_head list; /* command list */ 199b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 200b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 201b01a9201SJaegeuk Kim block_t len; /* length */ 202b01a9201SJaegeuk Kim struct bio *bio; /* bio */ 20315469963SJaegeuk Kim int state; /* state */ 204275b66b0SChao Yu }; 205275b66b0SChao Yu 2060b54fb84SJaegeuk Kim struct discard_cmd_control { 20715469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 2080b54fb84SJaegeuk Kim struct list_head discard_entry_list; /* 4KB discard entry list */ 2090b54fb84SJaegeuk Kim int nr_discards; /* # of discards in the list */ 2100b54fb84SJaegeuk Kim struct list_head discard_cmd_list; /* discard cmd list */ 21115469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 21215469963SJaegeuk Kim struct mutex cmd_lock; 2130b54fb84SJaegeuk Kim int max_discards; /* max. discards to be issued */ 214dcc9165dSJaegeuk Kim atomic_t submit_discard; /* # of issued discard */ 21539a53e0cSJaegeuk Kim }; 21639a53e0cSJaegeuk Kim 21739a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 21839a53e0cSJaegeuk Kim struct fsync_inode_entry { 21939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 22039a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 221c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 222c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 22339a53e0cSJaegeuk Kim }; 22439a53e0cSJaegeuk Kim 225dfc08a12SChao Yu #define nats_in_cursum(jnl) (le16_to_cpu(jnl->n_nats)) 226dfc08a12SChao Yu #define sits_in_cursum(jnl) (le16_to_cpu(jnl->n_sits)) 22739a53e0cSJaegeuk Kim 228dfc08a12SChao Yu #define nat_in_journal(jnl, i) (jnl->nat_j.entries[i].ne) 229dfc08a12SChao Yu #define nid_in_journal(jnl, i) (jnl->nat_j.entries[i].nid) 230dfc08a12SChao Yu #define sit_in_journal(jnl, i) (jnl->sit_j.entries[i].se) 231dfc08a12SChao Yu #define segno_in_journal(jnl, i) (jnl->sit_j.entries[i].segno) 23239a53e0cSJaegeuk Kim 233dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 234dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 235309cc2b6SJaegeuk Kim 236dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 23739a53e0cSJaegeuk Kim { 238dfc08a12SChao Yu int before = nats_in_cursum(journal); 239cac5a3d8SDongOh Shin 240dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 24139a53e0cSJaegeuk Kim return before; 24239a53e0cSJaegeuk Kim } 24339a53e0cSJaegeuk Kim 244dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 24539a53e0cSJaegeuk Kim { 246dfc08a12SChao Yu int before = sits_in_cursum(journal); 247cac5a3d8SDongOh Shin 248dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 24939a53e0cSJaegeuk Kim return before; 25039a53e0cSJaegeuk Kim } 25139a53e0cSJaegeuk Kim 252dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 253dfc08a12SChao Yu int size, int type) 254184a5cd2SChao Yu { 255184a5cd2SChao Yu if (type == NAT_JOURNAL) 256dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 257dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 258184a5cd2SChao Yu } 259184a5cd2SChao Yu 26039a53e0cSJaegeuk Kim /* 261e9750824SNamjae Jeon * ioctl commands 262e9750824SNamjae Jeon */ 263e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 264e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 265d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 266e9750824SNamjae Jeon 26788b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 26888b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 26988b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 27002a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2711e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2721e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 273c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 274456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 275d323d005SChao Yu #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) 2764dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 2774dd6f977SJaegeuk Kim struct f2fs_move_range) 27888b88a66SJaegeuk Kim 2790b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 2800b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 2810b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 282f424f664SJaegeuk Kim 2831abff93dSJaegeuk Kim /* 2841abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2851abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2861abff93dSJaegeuk Kim */ 2871abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2881abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2891abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2901abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 291c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 2921abff93dSJaegeuk Kim 293e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 294e9750824SNamjae Jeon /* 295e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 296e9750824SNamjae Jeon */ 297e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 298e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 29904ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 300e9750824SNamjae Jeon #endif 301e9750824SNamjae Jeon 302d323d005SChao Yu struct f2fs_defragment { 303d323d005SChao Yu u64 start; 304d323d005SChao Yu u64 len; 305d323d005SChao Yu }; 306d323d005SChao Yu 3074dd6f977SJaegeuk Kim struct f2fs_move_range { 3084dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3094dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3104dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3114dd6f977SJaegeuk Kim u64 len; /* size to move */ 3124dd6f977SJaegeuk Kim }; 3134dd6f977SJaegeuk Kim 314e9750824SNamjae Jeon /* 31539a53e0cSJaegeuk Kim * For INODE and NODE manager 31639a53e0cSJaegeuk Kim */ 3177b3cd7d6SJaegeuk Kim /* for directory operations */ 3187b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 319d8c6822aSJaegeuk Kim struct inode *inode; 3207b3cd7d6SJaegeuk Kim const void *bitmap; 3217b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 3227b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 3237b3cd7d6SJaegeuk Kim int max; 3247b3cd7d6SJaegeuk Kim }; 3257b3cd7d6SJaegeuk Kim 326d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode, 327d8c6822aSJaegeuk Kim struct f2fs_dentry_ptr *d, void *src, int type) 3287b3cd7d6SJaegeuk Kim { 329d8c6822aSJaegeuk Kim d->inode = inode; 330d8c6822aSJaegeuk Kim 3317b3cd7d6SJaegeuk Kim if (type == 1) { 3327b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 333cac5a3d8SDongOh Shin 3347b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 3357b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3367b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3377b3cd7d6SJaegeuk Kim d->filename = t->filename; 3387b3cd7d6SJaegeuk Kim } else { 3397b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 340cac5a3d8SDongOh Shin 3417b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3427b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3437b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3447b3cd7d6SJaegeuk Kim d->filename = t->filename; 3457b3cd7d6SJaegeuk Kim } 3467b3cd7d6SJaegeuk Kim } 3477b3cd7d6SJaegeuk Kim 348dbe6a5ffSJaegeuk Kim /* 349dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 350dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 351dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 35239a53e0cSJaegeuk Kim */ 353dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 354dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 355266e97a8SJaegeuk Kim enum { 356266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 357266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 358266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 359266e97a8SJaegeuk Kim * look up a node with readahead called 3604f4124d0SChao Yu * by get_data_block. 36139a53e0cSJaegeuk Kim */ 362266e97a8SJaegeuk Kim }; 363266e97a8SJaegeuk Kim 364a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 36539a53e0cSJaegeuk Kim 366817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 367817202d9SChao Yu 36813054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 36913054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 37013054c54SChao Yu 37139a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 37213054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 37313054c54SChao Yu 37413054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 37513054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 376c11abd1aSJaegeuk Kim 37739a53e0cSJaegeuk Kim struct extent_info { 37839a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3794d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 380111d2495SMasanari Iida unsigned int len; /* length of the extent */ 38139a53e0cSJaegeuk Kim }; 38239a53e0cSJaegeuk Kim 38313054c54SChao Yu struct extent_node { 38413054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 38513054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 38613054c54SChao Yu struct extent_info ei; /* extent info */ 387201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 38813054c54SChao Yu }; 38913054c54SChao Yu 39013054c54SChao Yu struct extent_tree { 39113054c54SChao Yu nid_t ino; /* inode number */ 39213054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 39362c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 3943e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 395137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 39613054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 39768e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 39813054c54SChao Yu }; 39913054c54SChao Yu 40039a53e0cSJaegeuk Kim /* 401003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 402003a3e1dSJaegeuk Kim * 403003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 404003a3e1dSJaegeuk Kim */ 405003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 406003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 4077f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 4087f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 4097f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 410003a3e1dSJaegeuk Kim 411003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 412003a3e1dSJaegeuk Kim block_t m_pblk; 413003a3e1dSJaegeuk Kim block_t m_lblk; 414003a3e1dSJaegeuk Kim unsigned int m_len; 415003a3e1dSJaegeuk Kim unsigned int m_flags; 416da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 417003a3e1dSJaegeuk Kim }; 418003a3e1dSJaegeuk Kim 419e2b4e2bcSChao Yu /* for flag in get_data_block */ 420e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 421e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 422e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 423e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 424b439b103SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_DIO 4 42524b84912SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_AIO 5 426e2b4e2bcSChao Yu 427003a3e1dSJaegeuk Kim /* 42839a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 42939a53e0cSJaegeuk Kim */ 43039a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 431354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 432cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 433e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 43426787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 43539a53e0cSJaegeuk Kim 436b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 437b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 438b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 439b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 440b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 441b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 442cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 443cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 444cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 445e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 446e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 44726787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 44826787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 449cde4de12SJaegeuk Kim 450ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 451ab9fa662SJaegeuk Kim 45239a53e0cSJaegeuk Kim struct f2fs_inode_info { 45339a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 45439a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 45539a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 45638431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 45739a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4586666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 45939a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 46039a53e0cSJaegeuk Kim 46139a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 46239a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 463d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 464204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 46539a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 46639a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 46788c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 46839a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 46926de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 47088b88a66SJaegeuk Kim 4710f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 4720f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 47388b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 47488b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 4753e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 47682e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 47739a53e0cSJaegeuk Kim }; 47839a53e0cSJaegeuk Kim 47939a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 480bd933d4fSChao Yu struct f2fs_extent *i_ext) 48139a53e0cSJaegeuk Kim { 482bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 483bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 484bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 48539a53e0cSJaegeuk Kim } 48639a53e0cSJaegeuk Kim 48739a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 48839a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 48939a53e0cSJaegeuk Kim { 49039a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4914d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 49239a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 49339a53e0cSJaegeuk Kim } 49439a53e0cSJaegeuk Kim 495429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 496429511cdSChao Yu u32 blk, unsigned int len) 497429511cdSChao Yu { 498429511cdSChao Yu ei->fofs = fofs; 499429511cdSChao Yu ei->blk = blk; 500429511cdSChao Yu ei->len = len; 501429511cdSChao Yu } 502429511cdSChao Yu 503429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 504429511cdSChao Yu struct extent_info *front) 505429511cdSChao Yu { 506429511cdSChao Yu return (back->fofs + back->len == front->fofs && 507429511cdSChao Yu back->blk + back->len == front->blk); 508429511cdSChao Yu } 509429511cdSChao Yu 510429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 511429511cdSChao Yu struct extent_info *back) 512429511cdSChao Yu { 513429511cdSChao Yu return __is_extent_mergeable(back, cur); 514429511cdSChao Yu } 515429511cdSChao Yu 516429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 517429511cdSChao Yu struct extent_info *front) 518429511cdSChao Yu { 519429511cdSChao Yu return __is_extent_mergeable(cur, front); 520429511cdSChao Yu } 521429511cdSChao Yu 522cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 523205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 524205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 5254abd3f5aSChao Yu { 526205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 5274abd3f5aSChao Yu et->largest = en->ei; 5287c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 529205b9822SJaegeuk Kim } 5304abd3f5aSChao Yu } 5314abd3f5aSChao Yu 532b8559dc2SChao Yu enum nid_list { 533b8559dc2SChao Yu FREE_NID_LIST, 534b8559dc2SChao Yu ALLOC_NID_LIST, 535b8559dc2SChao Yu MAX_NID_LIST, 536b8559dc2SChao Yu }; 537b8559dc2SChao Yu 53839a53e0cSJaegeuk Kim struct f2fs_nm_info { 53939a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 54039a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 54104d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 54239a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 543cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 544ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 5452304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 54639a53e0cSJaegeuk Kim 54739a53e0cSJaegeuk Kim /* NAT cache management */ 54839a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 549309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 550b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 55139a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 552309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 553aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 55422ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 55539a53e0cSJaegeuk Kim 55639a53e0cSJaegeuk Kim /* free node ids management */ 5578a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 558b8559dc2SChao Yu struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ 559b8559dc2SChao Yu unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 560b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 56139a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 5624ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 5634ac91242SChao Yu unsigned char *nat_block_bitmap; 56439a53e0cSJaegeuk Kim 56539a53e0cSJaegeuk Kim /* for checkpoint */ 56639a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 56722ad0b6aSJaegeuk Kim 56822ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 56922ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 57022ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 57122ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 572599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 573599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 574599a09b2SChao Yu #endif 57539a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 57639a53e0cSJaegeuk Kim }; 57739a53e0cSJaegeuk Kim 57839a53e0cSJaegeuk Kim /* 57939a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 58039a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 58139a53e0cSJaegeuk Kim * by the data offset in a file. 58239a53e0cSJaegeuk Kim */ 58339a53e0cSJaegeuk Kim struct dnode_of_data { 58439a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 58539a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 58639a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 58739a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 58839a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 58939a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 59093bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 5913cf45747SChao Yu char cur_level; /* level of hole node page */ 5923cf45747SChao Yu char max_level; /* level of current page located */ 59339a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 59439a53e0cSJaegeuk Kim }; 59539a53e0cSJaegeuk Kim 59639a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 59739a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 59839a53e0cSJaegeuk Kim { 599d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 60039a53e0cSJaegeuk Kim dn->inode = inode; 60139a53e0cSJaegeuk Kim dn->inode_page = ipage; 60239a53e0cSJaegeuk Kim dn->node_page = npage; 60339a53e0cSJaegeuk Kim dn->nid = nid; 60439a53e0cSJaegeuk Kim } 60539a53e0cSJaegeuk Kim 60639a53e0cSJaegeuk Kim /* 60739a53e0cSJaegeuk Kim * For SIT manager 60839a53e0cSJaegeuk Kim * 60939a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 61039a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 61139a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 61239a53e0cSJaegeuk Kim * respectively. 61339a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 61439a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 61539a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 61639a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 61739a53e0cSJaegeuk Kim * data and 8 for node logs. 61839a53e0cSJaegeuk Kim */ 61939a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 62039a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 62139a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 62239a53e0cSJaegeuk Kim 62339a53e0cSJaegeuk Kim enum { 62439a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 62539a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 62639a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 62739a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 62839a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 62939a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 63038aa0889SJaegeuk Kim NO_CHECK_TYPE, 63139a53e0cSJaegeuk Kim }; 63239a53e0cSJaegeuk Kim 6336b4afdd7SJaegeuk Kim struct flush_cmd { 6346b4afdd7SJaegeuk Kim struct completion wait; 635721bd4d5SGu Zheng struct llist_node llnode; 6366b4afdd7SJaegeuk Kim int ret; 6376b4afdd7SJaegeuk Kim }; 6386b4afdd7SJaegeuk Kim 639a688b9d9SGu Zheng struct flush_cmd_control { 640a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 641a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 6420a87f664SJaegeuk Kim atomic_t submit_flush; /* # of issued flushes */ 643721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 644721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 645a688b9d9SGu Zheng }; 646a688b9d9SGu Zheng 64739a53e0cSJaegeuk Kim struct f2fs_sm_info { 64839a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 64939a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 65039a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 65139a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 65239a53e0cSJaegeuk Kim 65339a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 65439a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 65539a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 65639a53e0cSJaegeuk Kim 65739a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 65839a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 65939a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 66039a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 66181eb8d6eSJaegeuk Kim 66281eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 66381eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 6647fd9e544SJaegeuk Kim 665bba681cbSJaegeuk Kim /* for batched trimming */ 666bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 667bba681cbSJaegeuk Kim 668184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 669184a5cd2SChao Yu 670216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 671216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 672c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 6736b4afdd7SJaegeuk Kim 6746b4afdd7SJaegeuk Kim /* for flush command control */ 675b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 676a688b9d9SGu Zheng 6770b54fb84SJaegeuk Kim /* for discard command control */ 6780b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 67939a53e0cSJaegeuk Kim }; 68039a53e0cSJaegeuk Kim 68139a53e0cSJaegeuk Kim /* 68239a53e0cSJaegeuk Kim * For superblock 68339a53e0cSJaegeuk Kim */ 68439a53e0cSJaegeuk Kim /* 68539a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 68639a53e0cSJaegeuk Kim * 68739a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 68839a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 68939a53e0cSJaegeuk Kim */ 69036951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 69139a53e0cSJaegeuk Kim enum count_type { 69239a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 693c227f912SChao Yu F2FS_DIRTY_DATA, 69439a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 69539a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6968dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 6970f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 69836951b38SChao Yu F2FS_WB_CP_DATA, 69936951b38SChao Yu F2FS_WB_DATA, 70039a53e0cSJaegeuk Kim NR_COUNT_TYPE, 70139a53e0cSJaegeuk Kim }; 70239a53e0cSJaegeuk Kim 70339a53e0cSJaegeuk Kim /* 704e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 70539a53e0cSJaegeuk Kim * The available types are: 70639a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 70739a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 70839a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 70939a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 71039a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 71139a53e0cSJaegeuk Kim * with waiting the bio's completion 71239a53e0cSJaegeuk Kim * ... Only can be used with META. 71339a53e0cSJaegeuk Kim */ 7147d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 71539a53e0cSJaegeuk Kim enum page_type { 71639a53e0cSJaegeuk Kim DATA, 71739a53e0cSJaegeuk Kim NODE, 71839a53e0cSJaegeuk Kim META, 71939a53e0cSJaegeuk Kim NR_PAGE_TYPE, 72039a53e0cSJaegeuk Kim META_FLUSH, 7218ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 7228ce67cb0SJaegeuk Kim INMEM_DROP, 72328bc106bSChao Yu INMEM_REVOKE, 7248ce67cb0SJaegeuk Kim IPU, 7258ce67cb0SJaegeuk Kim OPU, 72639a53e0cSJaegeuk Kim }; 72739a53e0cSJaegeuk Kim 728458e6197SJaegeuk Kim struct f2fs_io_info { 72905ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 730458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 73104d328deSMike Christie int op; /* contains REQ_OP_ */ 732ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 7337a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 73428bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 73505ca3632SJaegeuk Kim struct page *page; /* page to be written */ 7364375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 737d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 738458e6197SJaegeuk Kim }; 739458e6197SJaegeuk Kim 74004d328deSMike Christie #define is_read_io(rw) (rw == READ) 7411ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 742458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 7431ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 7441ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 745458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 746df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 7471ff7bd3bSJaegeuk Kim }; 7481ff7bd3bSJaegeuk Kim 7493c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 7503c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 7513c62be17SJaegeuk Kim struct f2fs_dev_info { 7523c62be17SJaegeuk Kim struct block_device *bdev; 7533c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 7543c62be17SJaegeuk Kim unsigned int total_segments; 7553c62be17SJaegeuk Kim block_t start_blk; 7563c62be17SJaegeuk Kim block_t end_blk; 7573c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 7583c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 7593c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 7603c62be17SJaegeuk Kim #endif 7613c62be17SJaegeuk Kim }; 7623c62be17SJaegeuk Kim 763c227f912SChao Yu enum inode_type { 764c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 765c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 7660f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 767c227f912SChao Yu NR_INODE_TYPE, 768c227f912SChao Yu }; 769c227f912SChao Yu 77067298804SChao Yu /* for inner inode cache management */ 77167298804SChao Yu struct inode_management { 77267298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 77367298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 77467298804SChao Yu struct list_head ino_list; /* inode list head */ 77567298804SChao Yu unsigned long ino_num; /* number of entries */ 77667298804SChao Yu }; 77767298804SChao Yu 778caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 779caf0047eSChao Yu enum { 780caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 781caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 782caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 783caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 784df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 785bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 786caf0047eSChao Yu }; 787caf0047eSChao Yu 7886beceb54SJaegeuk Kim enum { 7896beceb54SJaegeuk Kim CP_TIME, 790d0239e1bSJaegeuk Kim REQ_TIME, 7916beceb54SJaegeuk Kim MAX_TIME, 7926beceb54SJaegeuk Kim }; 7936beceb54SJaegeuk Kim 79439a53e0cSJaegeuk Kim struct f2fs_sb_info { 79539a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 7965e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 79739a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 798e8240f65SChao Yu int valid_super_block; /* valid super block no */ 799fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 80039a53e0cSJaegeuk Kim 801178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 802178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 803178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 804178053e2SDamien Le Moal #endif 805178053e2SDamien Le Moal 80639a53e0cSJaegeuk Kim /* for node-related operations */ 80739a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 80839a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 80939a53e0cSJaegeuk Kim 81039a53e0cSJaegeuk Kim /* for segment-related operations */ 81139a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 8121ff7bd3bSJaegeuk Kim 8131ff7bd3bSJaegeuk Kim /* for bio operations */ 814924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 8151ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 8167dfeaa32SJaegeuk Kim struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ 8170a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 8180a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 81939a53e0cSJaegeuk Kim 82039a53e0cSJaegeuk Kim /* for checkpoint */ 82139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 8228508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 823aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 82439a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 82539936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 826b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 827b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 828fb51b5efSChangman Lee wait_queue_head_t cp_wait; 8296beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 8306beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 83139a53e0cSJaegeuk Kim 83267298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 8336451e041SJaegeuk Kim 8346451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 8350d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 83639a53e0cSJaegeuk Kim 837c227f912SChao Yu /* for inode management */ 838c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 839c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 84039a53e0cSJaegeuk Kim 84113054c54SChao Yu /* for extent tree cache */ 84213054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 8435e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 84413054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 84513054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 8467441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 847137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 84874fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 84913054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 85013054c54SChao Yu 85139a53e0cSJaegeuk Kim /* basic filesystem units */ 85239a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 85339a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 85439a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 85539a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 85639a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 85739a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 85839a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 85939a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 86039a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 86139a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 86239a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 86339a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 86439a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 865e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 86639a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 867ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 86839a53e0cSJaegeuk Kim 86939a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 87039a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 871a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 87239a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 87339a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 874523be8a6SJaegeuk Kim 875523be8a6SJaegeuk Kim /* # of pages, see count_type */ 87635782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 87741382ec4SJaegeuk Kim /* # of allocated blocks */ 87841382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 87939a53e0cSJaegeuk Kim 880513c5f37SJaegeuk Kim /* valid inode count */ 881513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 882513c5f37SJaegeuk Kim 88339a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 88439a53e0cSJaegeuk Kim 88539a53e0cSJaegeuk Kim /* for cleaning operations */ 88639a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 88739a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 8885ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 88939a53e0cSJaegeuk Kim 890e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 891e93b9865SHou Pengyang u64 fggc_threshold; 892e93b9865SHou Pengyang 893b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 894b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 895b1c57c1cSJaegeuk Kim 89639a53e0cSJaegeuk Kim /* 89739a53e0cSJaegeuk Kim * for stat information. 89839a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 89939a53e0cSJaegeuk Kim */ 90035b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 90139a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 90239a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 90339a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 904b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 9055b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 9065b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 9075b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 9085b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 909d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 91003e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 91103e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 91226a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 91326a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 91439a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 91533fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 91635b09d82SNamjae Jeon #endif 91735b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 91839a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 919b59d0baeSNamjae Jeon 920b59d0baeSNamjae Jeon /* For sysfs suppport */ 921b59d0baeSNamjae Jeon struct kobject s_kobj; 922b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 9232658e50dSJaegeuk Kim 9242658e50dSJaegeuk Kim /* For shrinker support */ 9252658e50dSJaegeuk Kim struct list_head s_list; 9263c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 9273c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 9282658e50dSJaegeuk Kim struct mutex umount_mutex; 9292658e50dSJaegeuk Kim unsigned int shrinker_run_no; 9308f1dbbbbSShuoran Liu 9318f1dbbbbSShuoran Liu /* For write statistics */ 9328f1dbbbbSShuoran Liu u64 sectors_written_start; 9338f1dbbbbSShuoran Liu u64 kbytes_written; 93443b6573bSKeith Mok 93543b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 93643b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 9371ecc0c5cSChao Yu 9381ecc0c5cSChao Yu /* For fault injection */ 9391ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 9401ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 9411ecc0c5cSChao Yu #endif 94239a53e0cSJaegeuk Kim }; 94339a53e0cSJaegeuk Kim 9441ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 94555523519SChao Yu #define f2fs_show_injection_info(type) \ 94655523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 94755523519SChao Yu KERN_INFO, fault_name[type], \ 94855523519SChao Yu __func__, __builtin_return_address(0)) 9491ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 9501ecc0c5cSChao Yu { 9511ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 9521ecc0c5cSChao Yu 9531ecc0c5cSChao Yu if (!ffi->inject_rate) 9541ecc0c5cSChao Yu return false; 9551ecc0c5cSChao Yu 9561ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 9571ecc0c5cSChao Yu return false; 9581ecc0c5cSChao Yu 9591ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 9601ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 9611ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 9621ecc0c5cSChao Yu return true; 9631ecc0c5cSChao Yu } 9641ecc0c5cSChao Yu return false; 9651ecc0c5cSChao Yu } 9661ecc0c5cSChao Yu #endif 9671ecc0c5cSChao Yu 9688f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 9698f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 9708f1dbbbbSShuoran Liu */ 9718f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 9728f1dbbbbSShuoran Liu (((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) - \ 9738f1dbbbbSShuoran Liu s->sectors_written_start) >> 1) 9748f1dbbbbSShuoran Liu 9756beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 9766beceb54SJaegeuk Kim { 9776beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 9786beceb54SJaegeuk Kim } 9796beceb54SJaegeuk Kim 9806beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 9816beceb54SJaegeuk Kim { 9826beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 9836beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 9846beceb54SJaegeuk Kim 9856beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 9866beceb54SJaegeuk Kim } 9876beceb54SJaegeuk Kim 988d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 989d0239e1bSJaegeuk Kim { 990d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 991d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 992d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 993d0239e1bSJaegeuk Kim 994d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 995d0239e1bSJaegeuk Kim return 0; 996d0239e1bSJaegeuk Kim 997d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 998d0239e1bSJaegeuk Kim } 999d0239e1bSJaegeuk Kim 100039a53e0cSJaegeuk Kim /* 100139a53e0cSJaegeuk Kim * Inline functions 100239a53e0cSJaegeuk Kim */ 100343b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 100443b6573bSKeith Mok unsigned int length) 100543b6573bSKeith Mok { 100643b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 100743b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 100843b6573bSKeith Mok int err; 100943b6573bSKeith Mok 101043b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 101143b6573bSKeith Mok shash->flags = 0; 101243b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 101343b6573bSKeith Mok 101443b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 101543b6573bSKeith Mok BUG_ON(err); 101643b6573bSKeith Mok 101743b6573bSKeith Mok return *ctx; 101843b6573bSKeith Mok } 101943b6573bSKeith Mok 102043b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 102143b6573bSKeith Mok void *buf, size_t buf_size) 102243b6573bSKeith Mok { 102343b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 102443b6573bSKeith Mok } 102543b6573bSKeith Mok 102639a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 102739a53e0cSJaegeuk Kim { 102839a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 102939a53e0cSJaegeuk Kim } 103039a53e0cSJaegeuk Kim 103139a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 103239a53e0cSJaegeuk Kim { 103339a53e0cSJaegeuk Kim return sb->s_fs_info; 103439a53e0cSJaegeuk Kim } 103539a53e0cSJaegeuk Kim 10364081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 10374081363fSJaegeuk Kim { 10384081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 10394081363fSJaegeuk Kim } 10404081363fSJaegeuk Kim 10414081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 10424081363fSJaegeuk Kim { 10434081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 10444081363fSJaegeuk Kim } 10454081363fSJaegeuk Kim 10464081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 10474081363fSJaegeuk Kim { 10484081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 10494081363fSJaegeuk Kim } 10504081363fSJaegeuk Kim 105139a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 105239a53e0cSJaegeuk Kim { 105339a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 105439a53e0cSJaegeuk Kim } 105539a53e0cSJaegeuk Kim 105639a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 105739a53e0cSJaegeuk Kim { 105839a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 105939a53e0cSJaegeuk Kim } 106039a53e0cSJaegeuk Kim 106145590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 106245590710SGu Zheng { 106345590710SGu Zheng return (struct f2fs_node *)page_address(page); 106445590710SGu Zheng } 106545590710SGu Zheng 106658bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 106758bfaf44SJaegeuk Kim { 106858bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 106958bfaf44SJaegeuk Kim } 107058bfaf44SJaegeuk Kim 107139a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 107239a53e0cSJaegeuk Kim { 107339a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 107439a53e0cSJaegeuk Kim } 107539a53e0cSJaegeuk Kim 107639a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 107739a53e0cSJaegeuk Kim { 107839a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 107939a53e0cSJaegeuk Kim } 108039a53e0cSJaegeuk Kim 108139a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 108239a53e0cSJaegeuk Kim { 108339a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 108439a53e0cSJaegeuk Kim } 108539a53e0cSJaegeuk Kim 108639a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 108739a53e0cSJaegeuk Kim { 108839a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 108939a53e0cSJaegeuk Kim } 109039a53e0cSJaegeuk Kim 109139a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 109239a53e0cSJaegeuk Kim { 109339a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 109439a53e0cSJaegeuk Kim } 109539a53e0cSJaegeuk Kim 10969df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 10979df27d98SGu Zheng { 10989df27d98SGu Zheng return sbi->meta_inode->i_mapping; 10999df27d98SGu Zheng } 11009df27d98SGu Zheng 11014ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 11024ef51a8fSJaegeuk Kim { 11034ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 11044ef51a8fSJaegeuk Kim } 11054ef51a8fSJaegeuk Kim 1106caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 110739a53e0cSJaegeuk Kim { 1108fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 110939a53e0cSJaegeuk Kim } 111039a53e0cSJaegeuk Kim 1111caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 111239a53e0cSJaegeuk Kim { 1113fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1114caf0047eSChao Yu } 1115caf0047eSChao Yu 1116caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1117caf0047eSChao Yu { 1118fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 111939a53e0cSJaegeuk Kim } 112039a53e0cSJaegeuk Kim 1121d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1122d71b5564SJaegeuk Kim { 1123d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1124d71b5564SJaegeuk Kim } 1125d71b5564SJaegeuk Kim 1126ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1127ced2c7eaSKinglong Mee { 1128ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1129ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1130ced2c7eaSKinglong Mee } 1131ced2c7eaSKinglong Mee 1132aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 113325ca923bSJaegeuk Kim { 113425ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1135aaec2b1dSChao Yu 113625ca923bSJaegeuk Kim return ckpt_flags & f; 113725ca923bSJaegeuk Kim } 113825ca923bSJaegeuk Kim 1139aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 114025ca923bSJaegeuk Kim { 1141aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1142aaec2b1dSChao Yu } 1143aaec2b1dSChao Yu 1144aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1145aaec2b1dSChao Yu { 1146aaec2b1dSChao Yu unsigned int ckpt_flags; 1147aaec2b1dSChao Yu 1148aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 114925ca923bSJaegeuk Kim ckpt_flags |= f; 115025ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 115125ca923bSJaegeuk Kim } 115225ca923bSJaegeuk Kim 1153aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 115425ca923bSJaegeuk Kim { 1155aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1156aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1157aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1158aaec2b1dSChao Yu } 1159aaec2b1dSChao Yu 1160aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1161aaec2b1dSChao Yu { 1162aaec2b1dSChao Yu unsigned int ckpt_flags; 1163aaec2b1dSChao Yu 1164aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 116525ca923bSJaegeuk Kim ckpt_flags &= (~f); 116625ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 116725ca923bSJaegeuk Kim } 116825ca923bSJaegeuk Kim 1169aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1170aaec2b1dSChao Yu { 1171aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1172aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1173aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1174aaec2b1dSChao Yu } 1175aaec2b1dSChao Yu 117622ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 117722ad0b6aSJaegeuk Kim { 117822ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 117922ad0b6aSJaegeuk Kim 118022ad0b6aSJaegeuk Kim if (lock) 118122ad0b6aSJaegeuk Kim spin_lock(&sbi->cp_lock); 118222ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 118322ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 118422ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 118522ad0b6aSJaegeuk Kim if (lock) 118622ad0b6aSJaegeuk Kim spin_unlock(&sbi->cp_lock); 118722ad0b6aSJaegeuk Kim } 118822ad0b6aSJaegeuk Kim 118922ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 119022ad0b6aSJaegeuk Kim struct cp_control *cpc) 119122ad0b6aSJaegeuk Kim { 119222ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 119322ad0b6aSJaegeuk Kim 119422ad0b6aSJaegeuk Kim return (cpc) ? (cpc->reason == CP_UMOUNT) && set : set; 119522ad0b6aSJaegeuk Kim } 119622ad0b6aSJaegeuk Kim 1197e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 119839a53e0cSJaegeuk Kim { 1199b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 120039a53e0cSJaegeuk Kim } 120139a53e0cSJaegeuk Kim 1202e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 120339a53e0cSJaegeuk Kim { 1204b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 120539936837SJaegeuk Kim } 120639936837SJaegeuk Kim 1207e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 120839936837SJaegeuk Kim { 1209b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 121039936837SJaegeuk Kim } 121139936837SJaegeuk Kim 1212e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 121339936837SJaegeuk Kim { 1214b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 121539a53e0cSJaegeuk Kim } 121639a53e0cSJaegeuk Kim 1217119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1218119ee914SJaegeuk Kim { 1219119ee914SJaegeuk Kim int reason = CP_SYNC; 1220119ee914SJaegeuk Kim 1221119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1222119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1223119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1224119ee914SJaegeuk Kim reason = CP_UMOUNT; 1225119ee914SJaegeuk Kim return reason; 1226119ee914SJaegeuk Kim } 1227119ee914SJaegeuk Kim 1228119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1229119ee914SJaegeuk Kim { 1230119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 1231119ee914SJaegeuk Kim } 1232119ee914SJaegeuk Kim 1233119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1234119ee914SJaegeuk Kim { 1235aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1236aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1237119ee914SJaegeuk Kim } 1238119ee914SJaegeuk Kim 123939a53e0cSJaegeuk Kim /* 124039a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 124139a53e0cSJaegeuk Kim */ 1242064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 124339a53e0cSJaegeuk Kim { 1244d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1245d6b7d4b3SChao Yu return -EINVAL; 1246cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1247064e0823SNamjae Jeon return -EINVAL; 1248064e0823SNamjae Jeon return 0; 124939a53e0cSJaegeuk Kim } 125039a53e0cSJaegeuk Kim 125139a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 125239a53e0cSJaegeuk Kim 125339a53e0cSJaegeuk Kim /* 125439a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 125539a53e0cSJaegeuk Kim */ 125639a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 125739a53e0cSJaegeuk Kim { 125839a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 12596c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 126039a53e0cSJaegeuk Kim else 12616c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 126239a53e0cSJaegeuk Kim } 126339a53e0cSJaegeuk Kim 12644bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 12654bc8e9bcSChao Yu { 12664bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 12674bc8e9bcSChao Yu } 12684bc8e9bcSChao Yu 12698edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 127039a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 127146008c6dSChao Yu struct inode *inode, blkcnt_t *count) 127239a53e0cSJaegeuk Kim { 1273dd11a5dfSJaegeuk Kim blkcnt_t diff; 1274dd11a5dfSJaegeuk Kim 1275cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 127655523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 127755523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 1278cb78942bSJaegeuk Kim return false; 127955523519SChao Yu } 1280cb78942bSJaegeuk Kim #endif 1281dd11a5dfSJaegeuk Kim /* 1282dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1283dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1284dd11a5dfSJaegeuk Kim */ 1285dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1286cfb271d4SChao Yu 128739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12882555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 12892555a2d5SJaegeuk Kim if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { 1290dd11a5dfSJaegeuk Kim diff = sbi->total_valid_block_count - sbi->user_block_count; 1291dd11a5dfSJaegeuk Kim *count -= diff; 12922555a2d5SJaegeuk Kim sbi->total_valid_block_count = sbi->user_block_count; 129346008c6dSChao Yu if (!*count) { 129439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1295dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 129639a53e0cSJaegeuk Kim return false; 129739a53e0cSJaegeuk Kim } 129846008c6dSChao Yu } 129939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 130041382ec4SJaegeuk Kim 13012555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, *count, true); 130239a53e0cSJaegeuk Kim return true; 130339a53e0cSJaegeuk Kim } 130439a53e0cSJaegeuk Kim 1305da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 130639a53e0cSJaegeuk Kim struct inode *inode, 130739a53e0cSJaegeuk Kim blkcnt_t count) 130839a53e0cSJaegeuk Kim { 130939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13109850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 13119850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 131239a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 131339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 13142555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, count, false); 131539a53e0cSJaegeuk Kim } 131639a53e0cSJaegeuk Kim 131739a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 131839a53e0cSJaegeuk Kim { 131935782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 13207c4abcbeSChao Yu 132136951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 132236951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 13237c4abcbeSChao Yu return; 13247c4abcbeSChao Yu 1325caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 132639a53e0cSJaegeuk Kim } 132739a53e0cSJaegeuk Kim 1328a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 132939a53e0cSJaegeuk Kim { 1330204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1331c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1332c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 133339a53e0cSJaegeuk Kim } 133439a53e0cSJaegeuk Kim 133539a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 133639a53e0cSJaegeuk Kim { 133735782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 133839a53e0cSJaegeuk Kim } 133939a53e0cSJaegeuk Kim 1340a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 134139a53e0cSJaegeuk Kim { 13425ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 13435ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 13441fe54f9dSJaegeuk Kim return; 13451fe54f9dSJaegeuk Kim 1346204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1347c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1348c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 134939a53e0cSJaegeuk Kim } 135039a53e0cSJaegeuk Kim 1351523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 135239a53e0cSJaegeuk Kim { 135335782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 135439a53e0cSJaegeuk Kim } 135539a53e0cSJaegeuk Kim 1356204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1357f8b2c1f9SJaegeuk Kim { 1358204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1359f8b2c1f9SJaegeuk Kim } 1360f8b2c1f9SJaegeuk Kim 13615ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 13625ac206cfSNamjae Jeon { 13633519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1364523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1365523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1366523be8a6SJaegeuk Kim 1367523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 13685ac206cfSNamjae Jeon } 13695ac206cfSNamjae Jeon 137039a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 137139a53e0cSJaegeuk Kim { 13728b8343faSJaegeuk Kim return sbi->total_valid_block_count; 137339a53e0cSJaegeuk Kim } 137439a53e0cSJaegeuk Kim 1375f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1376f83a2584SYunlei He { 1377f83a2584SYunlei He return sbi->discard_blks; 1378f83a2584SYunlei He } 1379f83a2584SYunlei He 138039a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 138139a53e0cSJaegeuk Kim { 138239a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 138339a53e0cSJaegeuk Kim 138439a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 138539a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 138639a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 138739a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 138839a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 138939a53e0cSJaegeuk Kim 139039a53e0cSJaegeuk Kim return 0; 139139a53e0cSJaegeuk Kim } 139239a53e0cSJaegeuk Kim 139355141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 139455141486SWanpeng Li { 139555141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 139655141486SWanpeng Li } 139755141486SWanpeng Li 139839a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 139939a53e0cSJaegeuk Kim { 140039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 14011dbe4152SChangman Lee int offset; 14021dbe4152SChangman Lee 140355141486SWanpeng Li if (__cp_payload(sbi) > 0) { 14041dbe4152SChangman Lee if (flag == NAT_BITMAP) 14051dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 14061dbe4152SChangman Lee else 140765b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 14081dbe4152SChangman Lee } else { 14091dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 141025ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 141139a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 141239a53e0cSJaegeuk Kim } 14131dbe4152SChangman Lee } 141439a53e0cSJaegeuk Kim 141539a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 141639a53e0cSJaegeuk Kim { 14178508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 141839a53e0cSJaegeuk Kim 14198508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 142039a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 142139a53e0cSJaegeuk Kim return start_addr; 142239a53e0cSJaegeuk Kim } 142339a53e0cSJaegeuk Kim 14248508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 14258508e44aSJaegeuk Kim { 14268508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 14278508e44aSJaegeuk Kim 14288508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 14298508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 14308508e44aSJaegeuk Kim return start_addr; 14318508e44aSJaegeuk Kim } 14328508e44aSJaegeuk Kim 14338508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 14348508e44aSJaegeuk Kim { 14358508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 14368508e44aSJaegeuk Kim } 14378508e44aSJaegeuk Kim 143839a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 143939a53e0cSJaegeuk Kim { 144039a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 144139a53e0cSJaegeuk Kim } 144239a53e0cSJaegeuk Kim 144339a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1444ef86d709SGu Zheng struct inode *inode) 144539a53e0cSJaegeuk Kim { 144639a53e0cSJaegeuk Kim block_t valid_block_count; 144739a53e0cSJaegeuk Kim unsigned int valid_node_count; 144839a53e0cSJaegeuk Kim 144939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 145039a53e0cSJaegeuk Kim 1451ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1452cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 145339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 145439a53e0cSJaegeuk Kim return false; 145539a53e0cSJaegeuk Kim } 145639a53e0cSJaegeuk Kim 1457ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1458cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 145939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 146039a53e0cSJaegeuk Kim return false; 146139a53e0cSJaegeuk Kim } 146239a53e0cSJaegeuk Kim 146339a53e0cSJaegeuk Kim if (inode) 14648edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, true); 1465ef86d709SGu Zheng 1466ef86d709SGu Zheng sbi->total_valid_node_count++; 1467ef86d709SGu Zheng sbi->total_valid_block_count++; 146839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 146939a53e0cSJaegeuk Kim 147041382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 147139a53e0cSJaegeuk Kim return true; 147239a53e0cSJaegeuk Kim } 147339a53e0cSJaegeuk Kim 147439a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1475ef86d709SGu Zheng struct inode *inode) 147639a53e0cSJaegeuk Kim { 147739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 147839a53e0cSJaegeuk Kim 14799850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 14809850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 14819850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 148239a53e0cSJaegeuk Kim 14838edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, false); 1484ef86d709SGu Zheng sbi->total_valid_node_count--; 1485ef86d709SGu Zheng sbi->total_valid_block_count--; 148639a53e0cSJaegeuk Kim 148739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 148839a53e0cSJaegeuk Kim } 148939a53e0cSJaegeuk Kim 149039a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 149139a53e0cSJaegeuk Kim { 14928b8343faSJaegeuk Kim return sbi->total_valid_node_count; 149339a53e0cSJaegeuk Kim } 149439a53e0cSJaegeuk Kim 149539a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 149639a53e0cSJaegeuk Kim { 1497513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 149839a53e0cSJaegeuk Kim } 149939a53e0cSJaegeuk Kim 15000e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 150139a53e0cSJaegeuk Kim { 1502513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 150339a53e0cSJaegeuk Kim } 150439a53e0cSJaegeuk Kim 1505513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 150639a53e0cSJaegeuk Kim { 1507513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 150839a53e0cSJaegeuk Kim } 150939a53e0cSJaegeuk Kim 1510a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1511a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1512a56c7c6fSJaegeuk Kim { 1513c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1514c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1515cac5a3d8SDongOh Shin 1516c41f3cc3SJaegeuk Kim if (page) 1517c41f3cc3SJaegeuk Kim return page; 1518c41f3cc3SJaegeuk Kim 151955523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 152055523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1521c41f3cc3SJaegeuk Kim return NULL; 152255523519SChao Yu } 1523c41f3cc3SJaegeuk Kim #endif 1524a56c7c6fSJaegeuk Kim if (!for_write) 1525a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1526a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1527a56c7c6fSJaegeuk Kim } 1528a56c7c6fSJaegeuk Kim 15296e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 15306e2c64adSJaegeuk Kim { 15316e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 15326e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 15336e2c64adSJaegeuk Kim 15346e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 15356e2c64adSJaegeuk Kim kunmap(dst); 15366e2c64adSJaegeuk Kim kunmap(src); 15376e2c64adSJaegeuk Kim } 15386e2c64adSJaegeuk Kim 153939a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 154039a53e0cSJaegeuk Kim { 1541031fa8ccSJaegeuk Kim if (!page) 154239a53e0cSJaegeuk Kim return; 154339a53e0cSJaegeuk Kim 154439a53e0cSJaegeuk Kim if (unlock) { 15459850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 154639a53e0cSJaegeuk Kim unlock_page(page); 154739a53e0cSJaegeuk Kim } 154809cbfeafSKirill A. Shutemov put_page(page); 154939a53e0cSJaegeuk Kim } 155039a53e0cSJaegeuk Kim 155139a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 155239a53e0cSJaegeuk Kim { 155339a53e0cSJaegeuk Kim if (dn->node_page) 155439a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 155539a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 155639a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 155739a53e0cSJaegeuk Kim dn->node_page = NULL; 155839a53e0cSJaegeuk Kim dn->inode_page = NULL; 155939a53e0cSJaegeuk Kim } 156039a53e0cSJaegeuk Kim 156139a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1562e8512d2eSGu Zheng size_t size) 156339a53e0cSJaegeuk Kim { 1564e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 156539a53e0cSJaegeuk Kim } 156639a53e0cSJaegeuk Kim 15677bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 15687bd59381SGu Zheng gfp_t flags) 15697bd59381SGu Zheng { 15707bd59381SGu Zheng void *entry; 15717bd59381SGu Zheng 157280c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 157380c54505SJaegeuk Kim if (!entry) 157480c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 15757bd59381SGu Zheng return entry; 15767bd59381SGu Zheng } 15777bd59381SGu Zheng 1578740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1579740432f8SJaegeuk Kim { 1580740432f8SJaegeuk Kim struct bio *bio; 1581740432f8SJaegeuk Kim 1582740432f8SJaegeuk Kim /* No failure on bio allocation */ 1583740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 158480c54505SJaegeuk Kim if (!bio) 158580c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1586740432f8SJaegeuk Kim return bio; 1587740432f8SJaegeuk Kim } 1588740432f8SJaegeuk Kim 15899be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 15909be32d72SJaegeuk Kim unsigned long index, void *item) 15919be32d72SJaegeuk Kim { 15929be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 15939be32d72SJaegeuk Kim cond_resched(); 15949be32d72SJaegeuk Kim } 15959be32d72SJaegeuk Kim 159639a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 159739a53e0cSJaegeuk Kim 159839a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 159939a53e0cSJaegeuk Kim { 160045590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1601cac5a3d8SDongOh Shin 160239a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 160339a53e0cSJaegeuk Kim } 160439a53e0cSJaegeuk Kim 160539a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 160639a53e0cSJaegeuk Kim { 160739a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 160839a53e0cSJaegeuk Kim } 160939a53e0cSJaegeuk Kim 161039a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 161139a53e0cSJaegeuk Kim unsigned int offset) 161239a53e0cSJaegeuk Kim { 161339a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 161439a53e0cSJaegeuk Kim __le32 *addr_array; 1615cac5a3d8SDongOh Shin 161645590710SGu Zheng raw_node = F2FS_NODE(node_page); 161739a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 161839a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 161939a53e0cSJaegeuk Kim } 162039a53e0cSJaegeuk Kim 162139a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 162239a53e0cSJaegeuk Kim { 162339a53e0cSJaegeuk Kim int mask; 162439a53e0cSJaegeuk Kim 162539a53e0cSJaegeuk Kim addr += (nr >> 3); 162639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 162739a53e0cSJaegeuk Kim return mask & *addr; 162839a53e0cSJaegeuk Kim } 162939a53e0cSJaegeuk Kim 1630a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1631a66cdd98SJaegeuk Kim { 1632a66cdd98SJaegeuk Kim int mask; 1633a66cdd98SJaegeuk Kim 1634a66cdd98SJaegeuk Kim addr += (nr >> 3); 1635a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1636a66cdd98SJaegeuk Kim *addr |= mask; 1637a66cdd98SJaegeuk Kim } 1638a66cdd98SJaegeuk Kim 1639a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1640a66cdd98SJaegeuk Kim { 1641a66cdd98SJaegeuk Kim int mask; 1642a66cdd98SJaegeuk Kim 1643a66cdd98SJaegeuk Kim addr += (nr >> 3); 1644a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1645a66cdd98SJaegeuk Kim *addr &= ~mask; 1646a66cdd98SJaegeuk Kim } 1647a66cdd98SJaegeuk Kim 164852aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 164939a53e0cSJaegeuk Kim { 165039a53e0cSJaegeuk Kim int mask; 165139a53e0cSJaegeuk Kim int ret; 165239a53e0cSJaegeuk Kim 165339a53e0cSJaegeuk Kim addr += (nr >> 3); 165439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 165539a53e0cSJaegeuk Kim ret = mask & *addr; 165639a53e0cSJaegeuk Kim *addr |= mask; 165739a53e0cSJaegeuk Kim return ret; 165839a53e0cSJaegeuk Kim } 165939a53e0cSJaegeuk Kim 166052aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 166139a53e0cSJaegeuk Kim { 166239a53e0cSJaegeuk Kim int mask; 166339a53e0cSJaegeuk Kim int ret; 166439a53e0cSJaegeuk Kim 166539a53e0cSJaegeuk Kim addr += (nr >> 3); 166639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 166739a53e0cSJaegeuk Kim ret = mask & *addr; 166839a53e0cSJaegeuk Kim *addr &= ~mask; 166939a53e0cSJaegeuk Kim return ret; 167039a53e0cSJaegeuk Kim } 167139a53e0cSJaegeuk Kim 1672c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1673c6ac4c0eSGu Zheng { 1674c6ac4c0eSGu Zheng int mask; 1675c6ac4c0eSGu Zheng 1676c6ac4c0eSGu Zheng addr += (nr >> 3); 1677c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1678c6ac4c0eSGu Zheng *addr ^= mask; 1679c6ac4c0eSGu Zheng } 1680c6ac4c0eSGu Zheng 168139a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 168239a53e0cSJaegeuk Kim enum { 168339a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1684b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 168526de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1686ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 168739a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 168839a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 168939a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1690c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1691c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1692444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 16931001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 169434d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1695fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1696fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 169788b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 169888b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 16995fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 170002a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 17013c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 17021e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1703b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1704510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1705d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1706c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 1707dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 170839a53e0cSJaegeuk Kim }; 170939a53e0cSJaegeuk Kim 1710205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 1711205b9822SJaegeuk Kim int flag, bool set) 171239a53e0cSJaegeuk Kim { 1713205b9822SJaegeuk Kim switch (flag) { 1714205b9822SJaegeuk Kim case FI_INLINE_XATTR: 1715205b9822SJaegeuk Kim case FI_INLINE_DATA: 1716205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 1717205b9822SJaegeuk Kim if (set) 1718205b9822SJaegeuk Kim return; 1719205b9822SJaegeuk Kim case FI_DATA_EXIST: 1720205b9822SJaegeuk Kim case FI_INLINE_DOTS: 17217c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1722205b9822SJaegeuk Kim } 172339a53e0cSJaegeuk Kim } 172439a53e0cSJaegeuk Kim 172591942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 172639a53e0cSJaegeuk Kim { 172791942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 172891942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 1729205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 173039a53e0cSJaegeuk Kim } 173139a53e0cSJaegeuk Kim 173291942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 173339a53e0cSJaegeuk Kim { 173491942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 173539a53e0cSJaegeuk Kim } 173639a53e0cSJaegeuk Kim 173791942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 173839a53e0cSJaegeuk Kim { 173991942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 174091942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 1741205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 174239a53e0cSJaegeuk Kim } 174339a53e0cSJaegeuk Kim 174491942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 1745444c580fSJaegeuk Kim { 174691942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 174791942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 17487c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 174939a53e0cSJaegeuk Kim } 175039a53e0cSJaegeuk Kim 1751a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 1752a1961246SJaegeuk Kim { 1753a1961246SJaegeuk Kim if (inc) 1754a1961246SJaegeuk Kim inc_nlink(inode); 1755a1961246SJaegeuk Kim else 1756a1961246SJaegeuk Kim drop_nlink(inode); 17577c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1758a1961246SJaegeuk Kim } 1759a1961246SJaegeuk Kim 17608edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 17618edd03c8SJaegeuk Kim blkcnt_t diff, bool add) 17628edd03c8SJaegeuk Kim { 176326de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 176426de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 176526de9b11SJaegeuk Kim 17668edd03c8SJaegeuk Kim inode->i_blocks = add ? inode->i_blocks + diff : 17678edd03c8SJaegeuk Kim inode->i_blocks - diff; 17687c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 176926de9b11SJaegeuk Kim if (clean || recover) 177026de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 17718edd03c8SJaegeuk Kim } 17728edd03c8SJaegeuk Kim 1773fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 1774fc9581c8SJaegeuk Kim { 177526de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 177626de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 177726de9b11SJaegeuk Kim 1778fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 1779fc9581c8SJaegeuk Kim return; 1780fc9581c8SJaegeuk Kim 1781fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 17827c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 178326de9b11SJaegeuk Kim if (clean || recover) 178426de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 178526de9b11SJaegeuk Kim } 178626de9b11SJaegeuk Kim 1787205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 1788205b9822SJaegeuk Kim { 1789205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 17907c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1791205b9822SJaegeuk Kim } 1792205b9822SJaegeuk Kim 1793205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 1794205b9822SJaegeuk Kim { 1795205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 17967c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1797205b9822SJaegeuk Kim } 1798205b9822SJaegeuk Kim 1799205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 1800205b9822SJaegeuk Kim { 1801205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 18027c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1803205b9822SJaegeuk Kim } 1804205b9822SJaegeuk Kim 180591942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 1806444c580fSJaegeuk Kim { 1807205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 1808205b9822SJaegeuk Kim 1809444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1810205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 18111001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 1812205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 181334d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1814205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 1815b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1816205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 1817510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1818205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 1819444c580fSJaegeuk Kim } 1820444c580fSJaegeuk Kim 182191942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 1822444c580fSJaegeuk Kim { 1823444c580fSJaegeuk Kim ri->i_inline = 0; 1824444c580fSJaegeuk Kim 182591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 1826444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 182791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 18281001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 182991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 183034d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 183191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 1832b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 183391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 1834510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1835444c580fSJaegeuk Kim } 1836444c580fSJaegeuk Kim 1837987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1838987c7c31SChao Yu { 183991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 1840987c7c31SChao Yu } 1841987c7c31SChao Yu 184281ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1843de93653fSJaegeuk Kim { 184481ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1845de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1846de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1847de93653fSJaegeuk Kim } 1848de93653fSJaegeuk Kim 184965985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 185065985d93SJaegeuk Kim { 1851695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1852cac5a3d8SDongOh Shin 185365985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 185465985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 185565985d93SJaegeuk Kim } 185665985d93SJaegeuk Kim 185765985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 185865985d93SJaegeuk Kim { 1859987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 186065985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 186165985d93SJaegeuk Kim else 186265985d93SJaegeuk Kim return 0; 186365985d93SJaegeuk Kim } 186465985d93SJaegeuk Kim 18650dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 18660dbdc2aeSJaegeuk Kim { 186791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 18680dbdc2aeSJaegeuk Kim } 18690dbdc2aeSJaegeuk Kim 1870b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1871b3d208f9SJaegeuk Kim { 187291942321SJaegeuk Kim clear_inode_flag(inode, FI_INLINE_DATA); 187391942321SJaegeuk Kim clear_inode_flag(inode, FI_DATA_EXIST); 1874b3d208f9SJaegeuk Kim } 1875b3d208f9SJaegeuk Kim 1876b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1877b3d208f9SJaegeuk Kim { 187891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 1879b3d208f9SJaegeuk Kim } 1880b3d208f9SJaegeuk Kim 1881510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1882510022a8SJaegeuk Kim { 188391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 1884510022a8SJaegeuk Kim } 1885510022a8SJaegeuk Kim 188688b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 188788b88a66SJaegeuk Kim { 188891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 188988b88a66SJaegeuk Kim } 189088b88a66SJaegeuk Kim 18915fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 18925fe45743SChao Yu { 18935fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 18945fe45743SChao Yu } 18955fe45743SChao Yu 189602a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 189702a1335fSJaegeuk Kim { 189891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 189902a1335fSJaegeuk Kim } 190002a1335fSJaegeuk Kim 19013c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 19023c6c2bebSJaegeuk Kim { 190391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 19043c6c2bebSJaegeuk Kim } 19053c6c2bebSJaegeuk Kim 19061e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 19071e84371fSJaegeuk Kim { 190891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 19091e84371fSJaegeuk Kim } 19101e84371fSJaegeuk Kim 19111001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 19121001b347SHuajun Li { 1913695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1914cac5a3d8SDongOh Shin 19151001b347SHuajun Li return (void *)&(ri->i_addr[1]); 19161001b347SHuajun Li } 19171001b347SHuajun Li 191834d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 191934d67debSChao Yu { 192091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 192134d67debSChao Yu } 192234d67debSChao Yu 19239486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 19249486ba44SJaegeuk Kim { 19259486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 19269486ba44SJaegeuk Kim kunmap(page); 19279486ba44SJaegeuk Kim } 19289486ba44SJaegeuk Kim 1929b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1930b5492af7SJaegeuk Kim { 1931b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1932b5492af7SJaegeuk Kim } 1933b5492af7SJaegeuk Kim 1934b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1935b5492af7SJaegeuk Kim { 1936b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 19377c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1938b5492af7SJaegeuk Kim } 1939b5492af7SJaegeuk Kim 1940b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1941b5492af7SJaegeuk Kim { 1942b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 19437c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1944b5492af7SJaegeuk Kim } 1945b5492af7SJaegeuk Kim 194626787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 194726787236SJaegeuk Kim { 194826787236SJaegeuk Kim if (dsync) { 194926787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 195026787236SJaegeuk Kim bool ret; 195126787236SJaegeuk Kim 195226787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 195326787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 195426787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 195526787236SJaegeuk Kim return ret; 195626787236SJaegeuk Kim } 195726787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 195826787236SJaegeuk Kim file_keep_isize(inode) || 195926787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 196026787236SJaegeuk Kim return false; 196126787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 1962267378d4SChao Yu } 1963267378d4SChao Yu 1964267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 1965267378d4SChao Yu { 1966267378d4SChao Yu return sb->s_flags & MS_RDONLY; 1967267378d4SChao Yu } 196839a53e0cSJaegeuk Kim 196939a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 197039a53e0cSJaegeuk Kim { 1971aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 197239a53e0cSJaegeuk Kim } 197339a53e0cSJaegeuk Kim 1974eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1975eaa693f4SJaegeuk Kim { 1976eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1977eaa693f4SJaegeuk Kim return true; 1978eaa693f4SJaegeuk Kim 1979eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1980eaa693f4SJaegeuk Kim return true; 1981eaa693f4SJaegeuk Kim 1982eaa693f4SJaegeuk Kim return false; 1983eaa693f4SJaegeuk Kim } 1984eaa693f4SJaegeuk Kim 19853e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 19863e72f721SJaegeuk Kim { 19873e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 198891942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 19893e72f721SJaegeuk Kim return false; 19903e72f721SJaegeuk Kim 1991886f56f9SAl Viro return S_ISREG(inode->i_mode); 19923e72f721SJaegeuk Kim } 19933e72f721SJaegeuk Kim 19941ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 19951ecc0c5cSChao Yu size_t size, gfp_t flags) 19960414b004SJaegeuk Kim { 19972c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 199855523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 199955523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 20002c63feadSJaegeuk Kim return NULL; 200155523519SChao Yu } 20022c63feadSJaegeuk Kim #endif 20030414b004SJaegeuk Kim return kmalloc(size, flags); 20040414b004SJaegeuk Kim } 20050414b004SJaegeuk Kim 200639307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 200739307a8eSJaegeuk Kim { 200839307a8eSJaegeuk Kim void *ret; 200939307a8eSJaegeuk Kim 201039307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 201139307a8eSJaegeuk Kim if (!ret) 201239307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 201339307a8eSJaegeuk Kim return ret; 201439307a8eSJaegeuk Kim } 201539307a8eSJaegeuk Kim 201639307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 201739307a8eSJaegeuk Kim { 201839307a8eSJaegeuk Kim void *ret; 201939307a8eSJaegeuk Kim 202039307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 202139307a8eSJaegeuk Kim if (!ret) 202239307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 202339307a8eSJaegeuk Kim return ret; 202439307a8eSJaegeuk Kim } 202539307a8eSJaegeuk Kim 202639a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 202791942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 202839a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 202939a53e0cSJaegeuk Kim 203039a53e0cSJaegeuk Kim /* get offset of first page in next direct node */ 203181ca7350SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, inode) \ 203281ca7350SChao Yu ((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) : \ 203381ca7350SChao Yu (pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) / \ 203481ca7350SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode)) 20351e1bb4baSJaegeuk Kim 203639a53e0cSJaegeuk Kim /* 20372d4d9fb5SJaegeuk Kim * file.c 203839a53e0cSJaegeuk Kim */ 2039cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2040cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2041cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2042cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2043*a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2044*a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2045cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2046cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2047cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2048cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2049cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 205039a53e0cSJaegeuk Kim 205139a53e0cSJaegeuk Kim /* 205239a53e0cSJaegeuk Kim * inode.c 205339a53e0cSJaegeuk Kim */ 2054cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2055cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2056cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2057cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2058cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2059cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2060cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2061cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2062cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 206339a53e0cSJaegeuk Kim 206439a53e0cSJaegeuk Kim /* 206539a53e0cSJaegeuk Kim * namei.c 206639a53e0cSJaegeuk Kim */ 206739a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 206839a53e0cSJaegeuk Kim 206939a53e0cSJaegeuk Kim /* 207039a53e0cSJaegeuk Kim * dir.c 207139a53e0cSJaegeuk Kim */ 2072cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2073cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2074cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2075cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2076cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2077cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2078cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2079cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2080cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2081cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2082cac5a3d8SDongOh Shin const struct qstr *new_name, 2083cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2084cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2085cac5a3d8SDongOh Shin unsigned int current_depth); 2086cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2087cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2088cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2089cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2090cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2091cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2092cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2093cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2094cac5a3d8SDongOh Shin struct page **page); 2095cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2096cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2097cac5a3d8SDongOh Shin int update_dent_inode(struct inode *inode, struct inode *to, 2098cac5a3d8SDongOh Shin const struct qstr *name); 2099cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2100cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2101cac5a3d8SDongOh Shin unsigned int bit_pos); 2102cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2103cac5a3d8SDongOh Shin const struct qstr *orig_name, 2104cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2105cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2106cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2107cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2108cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2109cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2110cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2111cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2112cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 211339a53e0cSJaegeuk Kim 2114b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2115b7f7a5e0SAl Viro { 21162b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2117510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2118b7f7a5e0SAl Viro } 2119b7f7a5e0SAl Viro 212039a53e0cSJaegeuk Kim /* 212139a53e0cSJaegeuk Kim * super.c 212239a53e0cSJaegeuk Kim */ 2123cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2124cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2125cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2126cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2127a07ef784SNamjae Jeon extern __printf(3, 4) 2128cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2129984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 213039a53e0cSJaegeuk Kim 213139a53e0cSJaegeuk Kim /* 213239a53e0cSJaegeuk Kim * hash.c 213339a53e0cSJaegeuk Kim */ 2134cac5a3d8SDongOh Shin f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info); 213539a53e0cSJaegeuk Kim 213639a53e0cSJaegeuk Kim /* 213739a53e0cSJaegeuk Kim * node.c 213839a53e0cSJaegeuk Kim */ 213939a53e0cSJaegeuk Kim struct dnode_of_data; 214039a53e0cSJaegeuk Kim struct node_info; 214139a53e0cSJaegeuk Kim 2142cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2143cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2144cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2145cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2146cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2147cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2148cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2149cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2150cac5a3d8SDongOh Shin int truncate_xattr_node(struct inode *inode, struct page *page); 2151cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2152cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2153cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 2154cac5a3d8SDongOh Shin struct page *new_node_page(struct dnode_of_data *dn, 2155cac5a3d8SDongOh Shin unsigned int ofs, struct page *ipage); 2156cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2157cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2158cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2159cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2160cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2161cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2162cac5a3d8SDongOh Shin int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc); 216322ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2164cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2165cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2166cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2167cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2168cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2169d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2170cac5a3d8SDongOh Shin block_t blkaddr); 2171cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2172cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2173cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 217422ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2175cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2176cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 21776e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 217839a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 217939a53e0cSJaegeuk Kim 218039a53e0cSJaegeuk Kim /* 218139a53e0cSJaegeuk Kim * segment.c 218239a53e0cSJaegeuk Kim */ 2183cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 2184cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 2185cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2186cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2187cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2188cac5a3d8SDongOh Shin int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2189cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2190cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2191cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2192cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2193cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2194cac5a3d8SDongOh Shin void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr); 2195cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2196cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2197cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2198cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2199cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2200cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2201cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2202cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2203cac5a3d8SDongOh Shin void write_meta_page(struct f2fs_sb_info *sbi, struct page *page); 2204cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2205cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2206cac5a3d8SDongOh Shin void rewrite_data_page(struct f2fs_io_info *fio); 2207cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2208cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2209cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2210cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2211cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2212cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2213cac5a3d8SDongOh Shin bool recover_newaddr); 2214cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2215cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2216cac5a3d8SDongOh Shin struct f2fs_summary *sum, int type); 2217cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2218cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2219cac5a3d8SDongOh Shin void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2220cac5a3d8SDongOh Shin block_t blkaddr); 2221cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2222cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2223cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2224cac5a3d8SDongOh Shin unsigned int val, int alloc); 2225cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2226cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2227cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 22287fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 22297fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 223039a53e0cSJaegeuk Kim 223139a53e0cSJaegeuk Kim /* 223239a53e0cSJaegeuk Kim * checkpoint.c 223339a53e0cSJaegeuk Kim */ 2234cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2235cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2236cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2237cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2238cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2239cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2240cac5a3d8SDongOh Shin int type, bool sync); 2241cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2242cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2243cac5a3d8SDongOh Shin long nr_to_write); 2244cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2245cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2246cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2247cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2248cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2249cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2250cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2251cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2252cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2253cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2254cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2255cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2256cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2257cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2258cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2259cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 22606e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 226139a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 226239a53e0cSJaegeuk Kim 226339a53e0cSJaegeuk Kim /* 226439a53e0cSJaegeuk Kim * data.c 226539a53e0cSJaegeuk Kim */ 2266cac5a3d8SDongOh Shin void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 2267cac5a3d8SDongOh Shin int rw); 2268cac5a3d8SDongOh Shin void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, 2269942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2270942fd319SJaegeuk Kim enum page_type type, int rw); 2271cac5a3d8SDongOh Shin void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi); 2272cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2273cac5a3d8SDongOh Shin int f2fs_submit_page_mbio(struct f2fs_io_info *fio); 2274cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2275cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2276cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2277cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2278cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2279cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2280cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2281cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2282cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2283cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2284cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2285cac5a3d8SDongOh Shin int op_flags, bool for_write); 2286cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2287cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2288cac5a3d8SDongOh Shin bool for_write); 2289cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2290cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2291cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2292cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2293cac5a3d8SDongOh Shin int create, int flag); 2294cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2295cac5a3d8SDongOh Shin u64 start, u64 len); 2296cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2297cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2298cac5a3d8SDongOh Shin unsigned int length); 2299cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 23005b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2301cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2302cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 23035b7a487cSWeichao Guo #endif 230439a53e0cSJaegeuk Kim 230539a53e0cSJaegeuk Kim /* 230639a53e0cSJaegeuk Kim * gc.c 230739a53e0cSJaegeuk Kim */ 2308cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2309cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2310cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2311cac5a3d8SDongOh Shin int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background); 2312cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 231339a53e0cSJaegeuk Kim 231439a53e0cSJaegeuk Kim /* 231539a53e0cSJaegeuk Kim * recovery.c 231639a53e0cSJaegeuk Kim */ 2317cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2318cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 231939a53e0cSJaegeuk Kim 232039a53e0cSJaegeuk Kim /* 232139a53e0cSJaegeuk Kim * debug.c 232239a53e0cSJaegeuk Kim */ 232339a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 232439a53e0cSJaegeuk Kim struct f2fs_stat_info { 232539a53e0cSJaegeuk Kim struct list_head stat_list; 232639a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 232739a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 232839a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 23295b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 23305b7ee374SChao Yu unsigned long long hit_total, total_ext; 2331c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 233235782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 233335782b23SJaegeuk Kim int inmem_pages; 23340f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 2335b8559dc2SChao Yu int nats, dirty_nats, sits, dirty_sits, free_nids, alloc_nids; 233639a53e0cSJaegeuk Kim int total_count, utilization; 2337dcc9165dSJaegeuk Kim int bg_gc, nr_wb_cp_data, nr_wb_data, nr_flush, nr_discard; 2338a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 233926a28a0cSJaegeuk Kim int aw_cnt, max_aw_cnt; 2340f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 234139a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 234239a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 234339a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 234439a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 234542190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 234639a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2347e1235983SChangman Lee int bg_node_segs, bg_data_segs; 234839a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2349e1235983SChangman Lee int bg_data_blks, bg_node_blks; 235039a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 235139a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 235239a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 235339a53e0cSJaegeuk Kim 235439a53e0cSJaegeuk Kim unsigned int segment_count[2]; 235539a53e0cSJaegeuk Kim unsigned int block_count[2]; 2356b9a2c252SChangman Lee unsigned int inplace_count; 23579edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 235839a53e0cSJaegeuk Kim }; 235939a53e0cSJaegeuk Kim 2360963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2361963d4f7dSGu Zheng { 2362963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2363963d4f7dSGu Zheng } 2364963d4f7dSGu Zheng 2365942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 236642190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 236739a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2368dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 236933fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 237033fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 23715b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 23725b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 23735b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 23745b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2375d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2376d5e8f6c9SChao Yu do { \ 2377d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2378d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2379d5e8f6c9SChao Yu } while (0) 2380d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2381d5e8f6c9SChao Yu do { \ 2382d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2383d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2384d5e8f6c9SChao Yu } while (0) 23850dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 23860dbdc2aeSJaegeuk Kim do { \ 23870dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 238803e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 23890dbdc2aeSJaegeuk Kim } while (0) 23900dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 23910dbdc2aeSJaegeuk Kim do { \ 23920dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 239303e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 23940dbdc2aeSJaegeuk Kim } while (0) 23953289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 23963289c061SJaegeuk Kim do { \ 23973289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 239803e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 23993289c061SJaegeuk Kim } while (0) 24003289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 24013289c061SJaegeuk Kim do { \ 24023289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 240303e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 24043289c061SJaegeuk Kim } while (0) 2405dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2406dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2407dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2408dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2409b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2410b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 241126a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2412cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 241326a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2414cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 241526a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 241626a28a0cSJaegeuk Kim do { \ 241726a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 241826a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 241926a28a0cSJaegeuk Kim if (cur > max) \ 242026a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 242126a28a0cSJaegeuk Kim } while (0) 2422e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 242339a53e0cSJaegeuk Kim do { \ 2424963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 242539a53e0cSJaegeuk Kim (si)->tot_segs++; \ 2426e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 242739a53e0cSJaegeuk Kim si->data_segs++; \ 2428e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2429e1235983SChangman Lee } else { \ 243039a53e0cSJaegeuk Kim si->node_segs++; \ 2431e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2432e1235983SChangman Lee } \ 243339a53e0cSJaegeuk Kim } while (0) 243439a53e0cSJaegeuk Kim 243539a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 243639a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 243739a53e0cSJaegeuk Kim 2438e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 243939a53e0cSJaegeuk Kim do { \ 2440963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 244139a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 244239a53e0cSJaegeuk Kim si->data_blks += (blks); \ 2443e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 244439a53e0cSJaegeuk Kim } while (0) 244539a53e0cSJaegeuk Kim 2446e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 244739a53e0cSJaegeuk Kim do { \ 2448963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 244939a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 245039a53e0cSJaegeuk Kim si->node_blks += (blks); \ 2451e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 245239a53e0cSJaegeuk Kim } while (0) 245339a53e0cSJaegeuk Kim 2454cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2455cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2456787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 24574589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 245839a53e0cSJaegeuk Kim #else 2459942e0be6SChangman Lee #define stat_inc_cp_count(si) 246042190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) 246139a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 2462dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 246333fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) 246433fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) 2465dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 2466029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 246791c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 246891c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 2469d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 2470d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 24710dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 24720dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 24733289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 24743289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 247526a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) 247626a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) 247726a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) 2478dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 2479dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 2480b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 2481e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 248239a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 2483e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 2484e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 248539a53e0cSJaegeuk Kim 248639a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 248739a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2488787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 24894589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 249039a53e0cSJaegeuk Kim #endif 249139a53e0cSJaegeuk Kim 249239a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 249339a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 249439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 249539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 249639a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 249739a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 249839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 249939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2500cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 250139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 250229e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 25031001b347SHuajun Li 2504e18c65b2SHuajun Li /* 2505e18c65b2SHuajun Li * inline.c 2506e18c65b2SHuajun Li */ 2507cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2508cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2509cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2510cac5a3d8SDongOh Shin bool truncate_inline_inode(struct page *ipage, u64 from); 2511cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2512cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2513cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2514cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2515cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2516cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2517cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2518cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2519cac5a3d8SDongOh Shin struct page *ipage); 2520cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2521cac5a3d8SDongOh Shin const struct qstr *orig_name, 2522cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2523cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2524cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2525cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2526cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2527cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2528cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2529cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2530cac5a3d8SDongOh Shin __u64 start, __u64 len); 2531cde4de12SJaegeuk Kim 2532cde4de12SJaegeuk Kim /* 25332658e50dSJaegeuk Kim * shrinker.c 25342658e50dSJaegeuk Kim */ 2535cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2536cac5a3d8SDongOh Shin struct shrink_control *sc); 2537cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2538cac5a3d8SDongOh Shin struct shrink_control *sc); 2539cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2540cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 25412658e50dSJaegeuk Kim 25422658e50dSJaegeuk Kim /* 2543a28ef1f5SChao Yu * extent_cache.c 2544a28ef1f5SChao Yu */ 2545cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2546cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2547cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2548cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2549cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2550cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2551cac5a3d8SDongOh Shin struct extent_info *ei); 2552cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 255319b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2554cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2555cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2556a28ef1f5SChao Yu int __init create_extent_cache(void); 2557a28ef1f5SChao Yu void destroy_extent_cache(void); 2558a28ef1f5SChao Yu 2559a28ef1f5SChao Yu /* 2560cde4de12SJaegeuk Kim * crypto support 2561cde4de12SJaegeuk Kim */ 25620b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2563cde4de12SJaegeuk Kim { 2564cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2565cde4de12SJaegeuk Kim } 2566cde4de12SJaegeuk Kim 2567cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2568cde4de12SJaegeuk Kim { 2569cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2570cde4de12SJaegeuk Kim file_set_encrypt(inode); 2571cde4de12SJaegeuk Kim #endif 2572cde4de12SJaegeuk Kim } 2573cde4de12SJaegeuk Kim 2574cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2575cde4de12SJaegeuk Kim { 25760b81d077SJaegeuk Kim return bio->bi_private != NULL; 2577cde4de12SJaegeuk Kim } 2578cde4de12SJaegeuk Kim 2579cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2580cde4de12SJaegeuk Kim { 2581cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2582cde4de12SJaegeuk Kim } 2583f424f664SJaegeuk Kim 25840bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 258552763a4bSJaegeuk Kim { 25860bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 258752763a4bSJaegeuk Kim } 258852763a4bSJaegeuk Kim 2589178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2590178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 25913c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2592178053e2SDamien Le Moal { 2593178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 25943c62be17SJaegeuk Kim int i; 2595178053e2SDamien Le Moal 25963c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 25973c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 25983c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 25993c62be17SJaegeuk Kim return -EINVAL; 2600178053e2SDamien Le Moal } 2601178053e2SDamien Le Moal #endif 2602178053e2SDamien Le Moal 260396ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 260496ba2decSDamien Le Moal { 260596ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 260696ba2decSDamien Le Moal 260796ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 260852763a4bSJaegeuk Kim } 260952763a4bSJaegeuk Kim 261052763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 261152763a4bSJaegeuk Kim { 261252763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 261352763a4bSJaegeuk Kim clear_opt(sbi, LFS); 261452763a4bSJaegeuk Kim 261552763a4bSJaegeuk Kim switch (mt) { 261652763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 261752763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 261852763a4bSJaegeuk Kim break; 261952763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 262052763a4bSJaegeuk Kim set_opt(sbi, LFS); 262152763a4bSJaegeuk Kim break; 262252763a4bSJaegeuk Kim } 262352763a4bSJaegeuk Kim } 262452763a4bSJaegeuk Kim 2625fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2626fcc85a4dSJaegeuk Kim { 2627fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2628886f56f9SAl Viro umode_t mode = inode->i_mode; 2629fcc85a4dSJaegeuk Kim 2630fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2631fcc85a4dSJaegeuk Kim #else 2632fcc85a4dSJaegeuk Kim return 0; 2633fcc85a4dSJaegeuk Kim #endif 2634fcc85a4dSJaegeuk Kim } 2635fcc85a4dSJaegeuk Kim 263639a53e0cSJaegeuk Kim #endif 2637