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> 227c2e5963SJaegeuk Kim #include <linux/cred.h> 2339307a8eSJaegeuk Kim #include <linux/vmalloc.h> 24740432f8SJaegeuk Kim #include <linux/bio.h> 25d0239e1bSJaegeuk Kim #include <linux/blkdev.h> 260abd675eSChao Yu #include <linux/quotaops.h> 2743b6573bSKeith Mok #include <crypto/hash.h> 2839a53e0cSJaegeuk Kim 29734f0d24SDave Chinner #define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_F2FS_FS_ENCRYPTION) 30734f0d24SDave Chinner #include <linux/fscrypt.h> 31734f0d24SDave Chinner 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, 47628b3d14SChao Yu FAULT_KVMALLOC, 48c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 4901eccef7SChao Yu FAULT_PAGE_GET, 50d62fe971SChao Yu FAULT_ALLOC_BIO, 51cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 52cb78942bSJaegeuk Kim FAULT_ORPHAN, 53cb78942bSJaegeuk Kim FAULT_BLOCK, 54cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5553aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 5614b44d23SJaegeuk Kim FAULT_TRUNCATE, 578b038c70SChao Yu FAULT_IO, 580f348028SChao Yu FAULT_CHECKPOINT, 592c63feadSJaegeuk Kim FAULT_MAX, 602c63feadSJaegeuk Kim }; 612c63feadSJaegeuk Kim 6208796897SSheng Yong struct f2fs_fault_info { 6308796897SSheng Yong atomic_t inject_ops; 6408796897SSheng Yong unsigned int inject_rate; 6508796897SSheng Yong unsigned int inject_type; 6608796897SSheng Yong }; 6708796897SSheng Yong 682c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX]; 6968afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 702c63feadSJaegeuk Kim #endif 712c63feadSJaegeuk Kim 7239a53e0cSJaegeuk Kim /* 7339a53e0cSJaegeuk Kim * For mount options 7439a53e0cSJaegeuk Kim */ 7539a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 8039a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 8139a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 82444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 831001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8434d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8534d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8634d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 87d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8889672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 896aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 90343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 9173faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 9236abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 9336abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 940abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA 0x00080000 950abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA 0x00100000 965c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA 0x00200000 974b2414d0SChao Yu #define F2FS_MOUNT_QUOTA 0x00400000 986afc662eSChao Yu #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 997e65be49SJaegeuk Kim #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 10039a53e0cSJaegeuk Kim 10163189b78SChao Yu #define F2FS_OPTION(sbi) ((sbi)->mount_opt) 10263189b78SChao Yu #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) 10363189b78SChao Yu #define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option) 10463189b78SChao Yu #define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option) 10539a53e0cSJaegeuk Kim 10639a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 10739a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 10839a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 10939a53e0cSJaegeuk Kim 110a9841c4dSJaegeuk Kim typedef u32 block_t; /* 111a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 112a9841c4dSJaegeuk Kim * address format, __le32. 113a9841c4dSJaegeuk Kim */ 11439a53e0cSJaegeuk Kim typedef u32 nid_t; 11539a53e0cSJaegeuk Kim 11639a53e0cSJaegeuk Kim struct f2fs_mount_info { 11739a53e0cSJaegeuk Kim unsigned int opt; 11863189b78SChao Yu int write_io_size_bits; /* Write IO size bits */ 11963189b78SChao Yu block_t root_reserved_blocks; /* root reserved blocks */ 12063189b78SChao Yu kuid_t s_resuid; /* reserved blocks for uid */ 12163189b78SChao Yu kgid_t s_resgid; /* reserved blocks for gid */ 12263189b78SChao Yu int active_logs; /* # of active logs */ 12363189b78SChao Yu int inline_xattr_size; /* inline xattr size */ 12463189b78SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 12563189b78SChao Yu struct f2fs_fault_info fault_info; /* For fault injection */ 12663189b78SChao Yu #endif 12763189b78SChao Yu #ifdef CONFIG_QUOTA 12863189b78SChao Yu /* Names of quota files with journalled quota */ 12963189b78SChao Yu char *s_qf_names[MAXQUOTAS]; 13063189b78SChao Yu int s_jquota_fmt; /* Format of quota to use */ 13163189b78SChao Yu #endif 13263189b78SChao Yu /* For which write hints are passed down to block layer */ 13363189b78SChao Yu int whint_mode; 13463189b78SChao Yu int alloc_mode; /* segment allocation policy */ 13563189b78SChao Yu int fsync_mode; /* fsync policy */ 13639a53e0cSJaegeuk Kim }; 13739a53e0cSJaegeuk Kim 138cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1390bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 140e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1417a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1425c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 143704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 1446afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 145234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO 0x0080 1461c1d35dfSChao Yu #define F2FS_FEATURE_INODE_CRTIME 0x0100 147*b7c409deSSheng Yong #define F2FS_FEATURE_LOST_FOUND 0x0200 148cde4de12SJaegeuk Kim 14976f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 15076f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 15176f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 152c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 15376f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 154c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 15576f105a2SJaegeuk Kim 15639a53e0cSJaegeuk Kim /* 1577c2e5963SJaegeuk Kim * Default values for user and/or group using reserved blocks 1587c2e5963SJaegeuk Kim */ 1597c2e5963SJaegeuk Kim #define F2FS_DEF_RESUID 0 1607c2e5963SJaegeuk Kim #define F2FS_DEF_RESGID 0 1617c2e5963SJaegeuk Kim 1627c2e5963SJaegeuk Kim /* 16339a53e0cSJaegeuk Kim * For checkpoint manager 16439a53e0cSJaegeuk Kim */ 16539a53e0cSJaegeuk Kim enum { 16639a53e0cSJaegeuk Kim NAT_BITMAP, 16739a53e0cSJaegeuk Kim SIT_BITMAP 16839a53e0cSJaegeuk Kim }; 16939a53e0cSJaegeuk Kim 170c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 171c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 172c473f1a9SChao Yu #define CP_SYNC 0x00000004 173c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 174c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1751f43e2adSChao Yu #define CP_TRIMMED 0x00000020 17675ab4cb8SJaegeuk Kim 17747b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 178bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 1794ddb1a4dSJaegeuk Kim (GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections)) 180a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 181a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 1824ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 183ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 184969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 185969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 18660b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 187dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 188bba681cbSJaegeuk Kim 18975ab4cb8SJaegeuk Kim struct cp_control { 19075ab4cb8SJaegeuk Kim int reason; 1914b2fecc8SJaegeuk Kim __u64 trim_start; 1924b2fecc8SJaegeuk Kim __u64 trim_end; 1934b2fecc8SJaegeuk Kim __u64 trim_minlen; 19475ab4cb8SJaegeuk Kim }; 19575ab4cb8SJaegeuk Kim 196662befdaSChao Yu /* 19781c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 198662befdaSChao Yu */ 199662befdaSChao Yu enum { 200662befdaSChao Yu META_CP, 201662befdaSChao Yu META_NAT, 20281c1a0f1SChao Yu META_SIT, 2034c521f49SJaegeuk Kim META_SSA, 2044c521f49SJaegeuk Kim META_POR, 205662befdaSChao Yu }; 206662befdaSChao Yu 2076451e041SJaegeuk Kim /* for the list of ino */ 2086451e041SJaegeuk Kim enum { 2096451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 210fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 211fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 2120a007b97SJaegeuk Kim TRANS_DIR_INO, /* for trasactions dir ino list */ 21339d787beSChao Yu FLUSH_INO, /* for multiple device flushing */ 2146451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 2156451e041SJaegeuk Kim }; 2166451e041SJaegeuk Kim 2176451e041SJaegeuk Kim struct ino_entry { 21839a53e0cSJaegeuk Kim struct list_head list; /* list head */ 21939a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 22039d787beSChao Yu unsigned int dirty_device; /* dirty device bitmap */ 22139a53e0cSJaegeuk Kim }; 22239a53e0cSJaegeuk Kim 2232710fd7eSChao Yu /* for the list of inodes to be GCed */ 22406292073SChao Yu struct inode_entry { 22539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 22639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 22739a53e0cSJaegeuk Kim }; 22839a53e0cSJaegeuk Kim 229a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 2307fd9e544SJaegeuk Kim struct discard_entry { 2317fd9e544SJaegeuk Kim struct list_head list; /* list head */ 232a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 233a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 2347fd9e544SJaegeuk Kim }; 2357fd9e544SJaegeuk Kim 236969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 237969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 238969d1b18SChao Yu 239ba48a33eSChao Yu /* max discard pend list number */ 240ba48a33eSChao Yu #define MAX_PLIST_NUM 512 241ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 242ba48a33eSChao Yu (MAX_PLIST_NUM - 1) : (blk_num - 1)) 243ba48a33eSChao Yu 24415469963SJaegeuk Kim enum { 24515469963SJaegeuk Kim D_PREP, 24615469963SJaegeuk Kim D_SUBMIT, 24715469963SJaegeuk Kim D_DONE, 24815469963SJaegeuk Kim }; 24915469963SJaegeuk Kim 250004b6862SChao Yu struct discard_info { 251b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 252b01a9201SJaegeuk Kim block_t len; /* length */ 253004b6862SChao Yu block_t start; /* actual start address in dev */ 254004b6862SChao Yu }; 255004b6862SChao Yu 256b01a9201SJaegeuk Kim struct discard_cmd { 257004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 258004b6862SChao Yu union { 259004b6862SChao Yu struct { 260004b6862SChao Yu block_t lstart; /* logical start address */ 261004b6862SChao Yu block_t len; /* length */ 262004b6862SChao Yu block_t start; /* actual start address in dev */ 263004b6862SChao Yu }; 264004b6862SChao Yu struct discard_info di; /* discard info */ 265004b6862SChao Yu 266004b6862SChao Yu }; 267b01a9201SJaegeuk Kim struct list_head list; /* command list */ 268b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 269c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 270ec9895adSChao Yu unsigned short ref; /* reference count */ 2719a744b92SChao Yu unsigned char state; /* state */ 272c81abe34SJaegeuk Kim int error; /* bio error */ 273275b66b0SChao Yu }; 274275b66b0SChao Yu 27578997b56SChao Yu enum { 27678997b56SChao Yu DPOLICY_BG, 27778997b56SChao Yu DPOLICY_FORCE, 27878997b56SChao Yu DPOLICY_FSTRIM, 27978997b56SChao Yu DPOLICY_UMOUNT, 28078997b56SChao Yu MAX_DPOLICY, 28178997b56SChao Yu }; 28278997b56SChao Yu 283ecc9aa00SChao Yu struct discard_policy { 28478997b56SChao Yu int type; /* type of discard */ 285ecc9aa00SChao Yu unsigned int min_interval; /* used for candidates exist */ 286ecc9aa00SChao Yu unsigned int max_interval; /* used for candidates not exist */ 287ecc9aa00SChao Yu unsigned int max_requests; /* # of discards issued per round */ 288ecc9aa00SChao Yu unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ 289ecc9aa00SChao Yu bool io_aware; /* issue discard in idle time */ 290ecc9aa00SChao Yu bool sync; /* submit discard with REQ_SYNC flag */ 29178997b56SChao Yu unsigned int granularity; /* discard granularity */ 292ecc9aa00SChao Yu }; 293ecc9aa00SChao Yu 2940b54fb84SJaegeuk Kim struct discard_cmd_control { 29515469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 29646f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 297ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 29846f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 2998412663dSChao Yu struct list_head fstrim_list; /* in-flight discard from fstrim */ 30015469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 301969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 30215469963SJaegeuk Kim struct mutex cmd_lock; 303d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 304d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 305969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 306d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 3078b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 3088b8dd65fSChao Yu atomic_t issing_discard; /* # of issing discard */ 3095f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 310004b6862SChao Yu struct rb_root root; /* root of discard rb-tree */ 31139a53e0cSJaegeuk Kim }; 31239a53e0cSJaegeuk Kim 31339a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 31439a53e0cSJaegeuk Kim struct fsync_inode_entry { 31539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 31639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 317c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 318c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 31939a53e0cSJaegeuk Kim }; 32039a53e0cSJaegeuk Kim 32168afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 32268afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 32339a53e0cSJaegeuk Kim 32468afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 32568afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 32668afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 32768afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 32839a53e0cSJaegeuk Kim 329dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 330dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 331309cc2b6SJaegeuk Kim 332dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 33339a53e0cSJaegeuk Kim { 334dfc08a12SChao Yu int before = nats_in_cursum(journal); 335cac5a3d8SDongOh Shin 336dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 33739a53e0cSJaegeuk Kim return before; 33839a53e0cSJaegeuk Kim } 33939a53e0cSJaegeuk Kim 340dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 34139a53e0cSJaegeuk Kim { 342dfc08a12SChao Yu int before = sits_in_cursum(journal); 343cac5a3d8SDongOh Shin 344dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 34539a53e0cSJaegeuk Kim return before; 34639a53e0cSJaegeuk Kim } 34739a53e0cSJaegeuk Kim 348dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 349dfc08a12SChao Yu int size, int type) 350184a5cd2SChao Yu { 351184a5cd2SChao Yu if (type == NAT_JOURNAL) 352dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 353dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 354184a5cd2SChao Yu } 355184a5cd2SChao Yu 35639a53e0cSJaegeuk Kim /* 357e9750824SNamjae Jeon * ioctl commands 358e9750824SNamjae Jeon */ 359e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 360e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 361d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 362e9750824SNamjae Jeon 36388b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 36488b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 36588b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 36602a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 3671e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 3681e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 369d07efb50SJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32) 370456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 371d07efb50SJaegeuk Kim #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \ 372d07efb50SJaegeuk Kim struct f2fs_defragment) 3734dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 3744dd6f977SJaegeuk Kim struct f2fs_move_range) 375e066b83cSJaegeuk Kim #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ 376e066b83cSJaegeuk Kim struct f2fs_flush_device) 37734dc77adSJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ 37834dc77adSJaegeuk Kim struct f2fs_gc_range) 379e65ef207SJaegeuk Kim #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) 3801ad71a27SJaegeuk Kim #define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32) 3811ad71a27SJaegeuk Kim #define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32) 382c4020b2dSChao Yu #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) 38388b88a66SJaegeuk Kim 3840b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 3850b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 3860b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 387f424f664SJaegeuk Kim 3881abff93dSJaegeuk Kim /* 3891abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 3901abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 3911abff93dSJaegeuk Kim */ 3921abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 3931abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 3941abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 3951abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 396c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 3971abff93dSJaegeuk Kim 398e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 399e9750824SNamjae Jeon /* 400e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 401e9750824SNamjae Jeon */ 402e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 403e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 40404ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 405e9750824SNamjae Jeon #endif 406e9750824SNamjae Jeon 4072c1d0305SChao Yu #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR 4082c1d0305SChao Yu #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR 4092c1d0305SChao Yu 41034dc77adSJaegeuk Kim struct f2fs_gc_range { 41134dc77adSJaegeuk Kim u32 sync; 41234dc77adSJaegeuk Kim u64 start; 41334dc77adSJaegeuk Kim u64 len; 41434dc77adSJaegeuk Kim }; 41534dc77adSJaegeuk Kim 416d323d005SChao Yu struct f2fs_defragment { 417d323d005SChao Yu u64 start; 418d323d005SChao Yu u64 len; 419d323d005SChao Yu }; 420d323d005SChao Yu 4214dd6f977SJaegeuk Kim struct f2fs_move_range { 4224dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 4234dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 4244dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 4254dd6f977SJaegeuk Kim u64 len; /* size to move */ 4264dd6f977SJaegeuk Kim }; 4274dd6f977SJaegeuk Kim 428e066b83cSJaegeuk Kim struct f2fs_flush_device { 429e066b83cSJaegeuk Kim u32 dev_num; /* device number to flush */ 430e066b83cSJaegeuk Kim u32 segments; /* # of segments to flush */ 431e066b83cSJaegeuk Kim }; 432e066b83cSJaegeuk Kim 433f2470371SChao Yu /* for inline stuff */ 434f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 4356afc662eSChao Yu #define DEF_MIN_INLINE_SIZE 1 4367a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 4376afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode); 4387a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 4397a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 440b323fd28SChao Yu get_inline_xattr_addrs(inode) - \ 4416afc662eSChao Yu DEF_INLINE_RESERVED_SIZE)) 442f2470371SChao Yu 443f2470371SChao Yu /* for inline dir */ 444f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 445f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 446f2470371SChao Yu BITS_PER_BYTE + 1)) 447f2470371SChao Yu #define INLINE_DENTRY_BITMAP_SIZE(inode) ((NR_INLINE_DENTRY(inode) + \ 448f2470371SChao Yu BITS_PER_BYTE - 1) / BITS_PER_BYTE) 449f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 450f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 451f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 452f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 453f2470371SChao Yu 454e9750824SNamjae Jeon /* 45539a53e0cSJaegeuk Kim * For INODE and NODE manager 45639a53e0cSJaegeuk Kim */ 4577b3cd7d6SJaegeuk Kim /* for directory operations */ 4587b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 459d8c6822aSJaegeuk Kim struct inode *inode; 46076a9dd85SChao Yu void *bitmap; 4617b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 4627b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 4637b3cd7d6SJaegeuk Kim int max; 46476a9dd85SChao Yu int nr_bitmap; 4657b3cd7d6SJaegeuk Kim }; 4667b3cd7d6SJaegeuk Kim 46764c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 46864c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 4697b3cd7d6SJaegeuk Kim { 470d8c6822aSJaegeuk Kim d->inode = inode; 4717b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 47276a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 4737b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 4747b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 4757b3cd7d6SJaegeuk Kim d->filename = t->filename; 47664c24ecbSTomohiro Kusumi } 477cac5a3d8SDongOh Shin 47864c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 479f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 48064c24ecbSTomohiro Kusumi { 481f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 482f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 483f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 484f2470371SChao Yu 48564c24ecbSTomohiro Kusumi d->inode = inode; 486f2470371SChao Yu d->max = entry_cnt; 487f2470371SChao Yu d->nr_bitmap = bitmap_size; 488f2470371SChao Yu d->bitmap = t; 489f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 490f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 491f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 4927b3cd7d6SJaegeuk Kim } 4937b3cd7d6SJaegeuk Kim 494dbe6a5ffSJaegeuk Kim /* 495dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 496dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 497dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 49839a53e0cSJaegeuk Kim */ 499dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 500dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 501266e97a8SJaegeuk Kim enum { 502266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 503266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 504266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 505266e97a8SJaegeuk Kim * look up a node with readahead called 5064f4124d0SChao Yu * by get_data_block. 50739a53e0cSJaegeuk Kim */ 508266e97a8SJaegeuk Kim }; 509266e97a8SJaegeuk Kim 510a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 51139a53e0cSJaegeuk Kim 512817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 513817202d9SChao Yu 51413054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 51513054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 51613054c54SChao Yu 51739a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 51813054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 51913054c54SChao Yu 52013054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 52113054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 522c11abd1aSJaegeuk Kim 52354c2258cSChao Yu struct rb_entry { 52454c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 52554c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 52654c2258cSChao Yu unsigned int len; /* length of the entry */ 52754c2258cSChao Yu }; 52854c2258cSChao Yu 52939a53e0cSJaegeuk Kim struct extent_info { 53039a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 531111d2495SMasanari Iida unsigned int len; /* length of the extent */ 53254c2258cSChao Yu u32 blk; /* start block address of the extent */ 53339a53e0cSJaegeuk Kim }; 53439a53e0cSJaegeuk Kim 53513054c54SChao Yu struct extent_node { 53654c2258cSChao Yu struct rb_node rb_node; 53754c2258cSChao Yu union { 53854c2258cSChao Yu struct { 53954c2258cSChao Yu unsigned int fofs; 54054c2258cSChao Yu unsigned int len; 54154c2258cSChao Yu u32 blk; 54254c2258cSChao Yu }; 54313054c54SChao Yu struct extent_info ei; /* extent info */ 54454c2258cSChao Yu 54554c2258cSChao Yu }; 54654c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 547201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 54813054c54SChao Yu }; 54913054c54SChao Yu 55013054c54SChao Yu struct extent_tree { 55113054c54SChao Yu nid_t ino; /* inode number */ 55213054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 55362c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 5543e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 555137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 55613054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 55768e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 55813054c54SChao Yu }; 55913054c54SChao Yu 56039a53e0cSJaegeuk Kim /* 561003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 562003a3e1dSJaegeuk Kim * 563003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 564003a3e1dSJaegeuk Kim */ 565003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 566003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 5677f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 5687f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 5697f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 570003a3e1dSJaegeuk Kim 571003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 572003a3e1dSJaegeuk Kim block_t m_pblk; 573003a3e1dSJaegeuk Kim block_t m_lblk; 574003a3e1dSJaegeuk Kim unsigned int m_len; 575003a3e1dSJaegeuk Kim unsigned int m_flags; 576da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 577c4020b2dSChao Yu pgoff_t *m_next_extent; /* point to next possible extent */ 578d5097be5SHyunchul Lee int m_seg_type; 579003a3e1dSJaegeuk Kim }; 580003a3e1dSJaegeuk Kim 581e2b4e2bcSChao Yu /* for flag in get_data_block */ 582f2220c7fSQiuyang Sun enum { 583f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 584f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 585f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 586f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 587f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 588c4020b2dSChao Yu F2FS_GET_BLOCK_PRECACHE, 589f2220c7fSQiuyang Sun }; 590e2b4e2bcSChao Yu 591003a3e1dSJaegeuk Kim /* 59239a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 59339a53e0cSJaegeuk Kim */ 59439a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 595354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 596cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 597e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 59826787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 599b6a06cbbSChao Yu #define FADVISE_HOT_BIT 0x20 60039a53e0cSJaegeuk Kim 601b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 602b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 603b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 604b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 605b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 606b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 607cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 608cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 609cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 610e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 611e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 61226787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 61326787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 614b6a06cbbSChao Yu #define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT) 615b6a06cbbSChao Yu #define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT) 616b6a06cbbSChao Yu #define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT) 617cde4de12SJaegeuk Kim 618ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 619ab9fa662SJaegeuk Kim 62039a53e0cSJaegeuk Kim struct f2fs_inode_info { 62139a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 62239a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 62339a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 62438431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 6251ad71a27SJaegeuk Kim union { 6261ad71a27SJaegeuk Kim unsigned int i_current_depth; /* only for directory depth */ 6271ad71a27SJaegeuk Kim unsigned short i_gc_failures; /* only for regular file */ 6281ad71a27SJaegeuk Kim }; 6296666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 63039a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 63139a53e0cSJaegeuk Kim 63239a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 63339a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 634d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 635204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 63639a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 63739a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 63888c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 639b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 64039a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 64126de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 64288b88a66SJaegeuk Kim 6430abd675eSChao Yu #ifdef CONFIG_QUOTA 6440abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 6450abd675eSChao Yu 6460abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 6470abd675eSChao Yu qsize_t i_reserved_quota; 6480abd675eSChao Yu #endif 6490f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 6500f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 65157864ae5SJaegeuk Kim struct list_head inmem_ilist; /* list for inmem inodes */ 65288b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 6537a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 65488b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 6553e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 65682e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 6575a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 65827161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 659f2470371SChao Yu 6607a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 6615c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 6626afc662eSChao Yu int i_inline_xattr_size; /* inline xattr size */ 6631c1d35dfSChao Yu struct timespec i_crtime; /* inode creation time */ 66439a53e0cSJaegeuk Kim }; 66539a53e0cSJaegeuk Kim 66639a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 667bd933d4fSChao Yu struct f2fs_extent *i_ext) 66839a53e0cSJaegeuk Kim { 669bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 670bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 671bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 67239a53e0cSJaegeuk Kim } 67339a53e0cSJaegeuk Kim 67439a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 67539a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 67639a53e0cSJaegeuk Kim { 67739a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 6784d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 67939a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 68039a53e0cSJaegeuk Kim } 68139a53e0cSJaegeuk Kim 682429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 683429511cdSChao Yu u32 blk, unsigned int len) 684429511cdSChao Yu { 685429511cdSChao Yu ei->fofs = fofs; 686429511cdSChao Yu ei->blk = blk; 687429511cdSChao Yu ei->len = len; 688429511cdSChao Yu } 689429511cdSChao Yu 690004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 691004b6862SChao Yu struct discard_info *front) 692004b6862SChao Yu { 693004b6862SChao Yu return back->lstart + back->len == front->lstart; 694004b6862SChao Yu } 695004b6862SChao Yu 696004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 697004b6862SChao Yu struct discard_info *back) 698004b6862SChao Yu { 699004b6862SChao Yu return __is_discard_mergeable(back, cur); 700004b6862SChao Yu } 701004b6862SChao Yu 702004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 703004b6862SChao Yu struct discard_info *front) 704004b6862SChao Yu { 705004b6862SChao Yu return __is_discard_mergeable(cur, front); 706004b6862SChao Yu } 707004b6862SChao Yu 708429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 709429511cdSChao Yu struct extent_info *front) 710429511cdSChao Yu { 711429511cdSChao Yu return (back->fofs + back->len == front->fofs && 712429511cdSChao Yu back->blk + back->len == front->blk); 713429511cdSChao Yu } 714429511cdSChao Yu 715429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 716429511cdSChao Yu struct extent_info *back) 717429511cdSChao Yu { 718429511cdSChao Yu return __is_extent_mergeable(back, cur); 719429511cdSChao Yu } 720429511cdSChao Yu 721429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 722429511cdSChao Yu struct extent_info *front) 723429511cdSChao Yu { 724429511cdSChao Yu return __is_extent_mergeable(cur, front); 725429511cdSChao Yu } 726429511cdSChao Yu 727cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 728205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 729205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 7304abd3f5aSChao Yu { 731205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 7324abd3f5aSChao Yu et->largest = en->ei; 7337c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 734205b9822SJaegeuk Kim } 7354abd3f5aSChao Yu } 7364abd3f5aSChao Yu 7379a4ffdf5SChao Yu /* 7389a4ffdf5SChao Yu * For free nid management 7399a4ffdf5SChao Yu */ 7409a4ffdf5SChao Yu enum nid_state { 7419a4ffdf5SChao Yu FREE_NID, /* newly added to free nid list */ 7429a4ffdf5SChao Yu PREALLOC_NID, /* it is preallocated */ 7439a4ffdf5SChao Yu MAX_NID_STATE, 744b8559dc2SChao Yu }; 745b8559dc2SChao Yu 74639a53e0cSJaegeuk Kim struct f2fs_nm_info { 74739a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 74839a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 74904d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 75039a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 751cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 752ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 7532304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 75439a53e0cSJaegeuk Kim 75539a53e0cSJaegeuk Kim /* NAT cache management */ 75639a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 757309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 758b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 75939a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 760309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 761aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 76222ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 76339a53e0cSJaegeuk Kim 76439a53e0cSJaegeuk Kim /* free node ids management */ 7658a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 7669a4ffdf5SChao Yu struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ 7679a4ffdf5SChao Yu unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 768b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 76939a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 770bb1105e4SJaegeuk Kim unsigned char **free_nid_bitmap; 7714ac91242SChao Yu unsigned char *nat_block_bitmap; 772586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 77339a53e0cSJaegeuk Kim 77439a53e0cSJaegeuk Kim /* for checkpoint */ 77539a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 77622ad0b6aSJaegeuk Kim 77722ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 77822ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 77922ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 78022ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 781599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 782599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 783599a09b2SChao Yu #endif 78439a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 78539a53e0cSJaegeuk Kim }; 78639a53e0cSJaegeuk Kim 78739a53e0cSJaegeuk Kim /* 78839a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 78939a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 79039a53e0cSJaegeuk Kim * by the data offset in a file. 79139a53e0cSJaegeuk Kim */ 79239a53e0cSJaegeuk Kim struct dnode_of_data { 79339a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 79439a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 79539a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 79639a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 79739a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 79839a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 79993bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 8003cf45747SChao Yu char cur_level; /* level of hole node page */ 8013cf45747SChao Yu char max_level; /* level of current page located */ 80239a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 80339a53e0cSJaegeuk Kim }; 80439a53e0cSJaegeuk Kim 80539a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 80639a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 80739a53e0cSJaegeuk Kim { 808d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 80939a53e0cSJaegeuk Kim dn->inode = inode; 81039a53e0cSJaegeuk Kim dn->inode_page = ipage; 81139a53e0cSJaegeuk Kim dn->node_page = npage; 81239a53e0cSJaegeuk Kim dn->nid = nid; 81339a53e0cSJaegeuk Kim } 81439a53e0cSJaegeuk Kim 81539a53e0cSJaegeuk Kim /* 81639a53e0cSJaegeuk Kim * For SIT manager 81739a53e0cSJaegeuk Kim * 81839a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 81939a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 82039a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 82139a53e0cSJaegeuk Kim * respectively. 82239a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 82339a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 82439a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 82539a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 82639a53e0cSJaegeuk Kim * data and 8 for node logs. 82739a53e0cSJaegeuk Kim */ 82839a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 82939a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 83039a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 83139a53e0cSJaegeuk Kim 83239a53e0cSJaegeuk Kim enum { 83339a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 83439a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 83539a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 83639a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 83739a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 83839a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 83938aa0889SJaegeuk Kim NO_CHECK_TYPE, 84039a53e0cSJaegeuk Kim }; 84139a53e0cSJaegeuk Kim 8426b4afdd7SJaegeuk Kim struct flush_cmd { 8436b4afdd7SJaegeuk Kim struct completion wait; 844721bd4d5SGu Zheng struct llist_node llnode; 84539d787beSChao Yu nid_t ino; 8466b4afdd7SJaegeuk Kim int ret; 8476b4afdd7SJaegeuk Kim }; 8486b4afdd7SJaegeuk Kim 849a688b9d9SGu Zheng struct flush_cmd_control { 850a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 851a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 8528b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 8538b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 854721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 855721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 856a688b9d9SGu Zheng }; 857a688b9d9SGu Zheng 85839a53e0cSJaegeuk Kim struct f2fs_sm_info { 85939a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 86039a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 86139a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 86239a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 86339a53e0cSJaegeuk Kim 8642b60311dSChao Yu struct rw_semaphore curseg_lock; /* for preventing curseg change */ 8652b60311dSChao Yu 86639a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 86739a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 86839a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 86939a53e0cSJaegeuk Kim 87039a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 87139a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 87239a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 87339a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 87481eb8d6eSJaegeuk Kim 87581eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 87681eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 8777fd9e544SJaegeuk Kim 878bba681cbSJaegeuk Kim /* for batched trimming */ 879bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 880bba681cbSJaegeuk Kim 881184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 882184a5cd2SChao Yu 883216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 884216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 885c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 886ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 887a2a12b67SChao Yu unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ 8886b4afdd7SJaegeuk Kim 8896b4afdd7SJaegeuk Kim /* for flush command control */ 890b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 891a688b9d9SGu Zheng 8920b54fb84SJaegeuk Kim /* for discard command control */ 8930b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 89439a53e0cSJaegeuk Kim }; 89539a53e0cSJaegeuk Kim 89639a53e0cSJaegeuk Kim /* 89739a53e0cSJaegeuk Kim * For superblock 89839a53e0cSJaegeuk Kim */ 89939a53e0cSJaegeuk Kim /* 90039a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 90139a53e0cSJaegeuk Kim * 90239a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 90339a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 90439a53e0cSJaegeuk Kim */ 90536951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 90639a53e0cSJaegeuk Kim enum count_type { 90739a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 908c227f912SChao Yu F2FS_DIRTY_DATA, 9092c8a4a28SJaegeuk Kim F2FS_DIRTY_QDATA, 91039a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 91139a53e0cSJaegeuk Kim F2FS_DIRTY_META, 9128dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 9130f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 91436951b38SChao Yu F2FS_WB_CP_DATA, 91536951b38SChao Yu F2FS_WB_DATA, 91639a53e0cSJaegeuk Kim NR_COUNT_TYPE, 91739a53e0cSJaegeuk Kim }; 91839a53e0cSJaegeuk Kim 91939a53e0cSJaegeuk Kim /* 920e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 92139a53e0cSJaegeuk Kim * The available types are: 92239a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 92339a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 92439a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 92539a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 92639a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 92739a53e0cSJaegeuk Kim * with waiting the bio's completion 92839a53e0cSJaegeuk Kim * ... Only can be used with META. 92939a53e0cSJaegeuk Kim */ 9307d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 93139a53e0cSJaegeuk Kim enum page_type { 93239a53e0cSJaegeuk Kim DATA, 93339a53e0cSJaegeuk Kim NODE, 93439a53e0cSJaegeuk Kim META, 93539a53e0cSJaegeuk Kim NR_PAGE_TYPE, 93639a53e0cSJaegeuk Kim META_FLUSH, 9378ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 9388ce67cb0SJaegeuk Kim INMEM_DROP, 9398c242db9SJaegeuk Kim INMEM_INVALIDATE, 94028bc106bSChao Yu INMEM_REVOKE, 9418ce67cb0SJaegeuk Kim IPU, 9428ce67cb0SJaegeuk Kim OPU, 94339a53e0cSJaegeuk Kim }; 94439a53e0cSJaegeuk Kim 945a912b54dSJaegeuk Kim enum temp_type { 946a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 947a912b54dSJaegeuk Kim WARM, 948a912b54dSJaegeuk Kim COLD, 949a912b54dSJaegeuk Kim NR_TEMP_TYPE, 950a912b54dSJaegeuk Kim }; 951a912b54dSJaegeuk Kim 952cc15620bSJaegeuk Kim enum need_lock_type { 953cc15620bSJaegeuk Kim LOCK_REQ = 0, 954cc15620bSJaegeuk Kim LOCK_DONE, 955cc15620bSJaegeuk Kim LOCK_RETRY, 956cc15620bSJaegeuk Kim }; 957cc15620bSJaegeuk Kim 958a5fd5050SChao Yu enum cp_reason_type { 959a5fd5050SChao Yu CP_NO_NEEDED, 960a5fd5050SChao Yu CP_NON_REGULAR, 961a5fd5050SChao Yu CP_HARDLINK, 962a5fd5050SChao Yu CP_SB_NEED_CP, 963a5fd5050SChao Yu CP_WRONG_PINO, 964a5fd5050SChao Yu CP_NO_SPC_ROLL, 965a5fd5050SChao Yu CP_NODE_NEED_CP, 966a5fd5050SChao Yu CP_FASTBOOT_MODE, 967a5fd5050SChao Yu CP_SPEC_LOG_NUM, 9680a007b97SJaegeuk Kim CP_RECOVER_DIR, 969a5fd5050SChao Yu }; 970a5fd5050SChao Yu 971b0af6d49SChao Yu enum iostat_type { 972b0af6d49SChao Yu APP_DIRECT_IO, /* app direct IOs */ 973b0af6d49SChao Yu APP_BUFFERED_IO, /* app buffered IOs */ 974b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 975b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 976b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 977b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 978b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 979b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 980b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 981b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 982b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 983b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 984b0af6d49SChao Yu FS_DISCARD, /* discard */ 985b0af6d49SChao Yu NR_IO_TYPE, 986b0af6d49SChao Yu }; 987b0af6d49SChao Yu 988458e6197SJaegeuk Kim struct f2fs_io_info { 98905ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 99039d787beSChao Yu nid_t ino; /* inode number */ 991458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 992a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 99304d328deSMike Christie int op; /* contains REQ_OP_ */ 994ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 9957a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 99628bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 99705ca3632SJaegeuk Kim struct page *page; /* page to be written */ 9984375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 999fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 1000d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 1001cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 1002fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 1003b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 1004578c6478SYufen Yu struct writeback_control *io_wbc; /* writeback control */ 1005458e6197SJaegeuk Kim }; 1006458e6197SJaegeuk Kim 100768afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 10081ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 1009458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 10101ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 10111ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 1012458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 1013df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 1014fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 1015fb830fc5SChao Yu struct list_head io_list; /* track fios */ 10161ff7bd3bSJaegeuk Kim }; 10171ff7bd3bSJaegeuk Kim 10183c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 10193c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 10203c62be17SJaegeuk Kim struct f2fs_dev_info { 10213c62be17SJaegeuk Kim struct block_device *bdev; 10223c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 10233c62be17SJaegeuk Kim unsigned int total_segments; 10243c62be17SJaegeuk Kim block_t start_blk; 10253c62be17SJaegeuk Kim block_t end_blk; 10263c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 10273c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 10283c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 10293c62be17SJaegeuk Kim #endif 10303c62be17SJaegeuk Kim }; 10313c62be17SJaegeuk Kim 1032c227f912SChao Yu enum inode_type { 1033c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 1034c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 10350f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 103657864ae5SJaegeuk Kim ATOMIC_FILE, /* for all atomic files */ 1037c227f912SChao Yu NR_INODE_TYPE, 1038c227f912SChao Yu }; 1039c227f912SChao Yu 104067298804SChao Yu /* for inner inode cache management */ 104167298804SChao Yu struct inode_management { 104267298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 104367298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 104467298804SChao Yu struct list_head ino_list; /* inode list head */ 104567298804SChao Yu unsigned long ino_num; /* number of entries */ 104667298804SChao Yu }; 104767298804SChao Yu 1048caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 1049caf0047eSChao Yu enum { 1050caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 1051caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 1052caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 1053caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 1054df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 1055bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 1056caf0047eSChao Yu }; 1057caf0047eSChao Yu 10586beceb54SJaegeuk Kim enum { 10596beceb54SJaegeuk Kim CP_TIME, 1060d0239e1bSJaegeuk Kim REQ_TIME, 10616beceb54SJaegeuk Kim MAX_TIME, 10626beceb54SJaegeuk Kim }; 10636beceb54SJaegeuk Kim 10640cdd3195SHyunchul Lee enum { 10650cdd3195SHyunchul Lee WHINT_MODE_OFF, /* not pass down write hints */ 10660cdd3195SHyunchul Lee WHINT_MODE_USER, /* try to pass down hints given by users */ 1067f2e703f9SHyunchul Lee WHINT_MODE_FS, /* pass down hints with F2FS policy */ 10680cdd3195SHyunchul Lee }; 10690cdd3195SHyunchul Lee 107007939627SJaegeuk Kim enum { 107107939627SJaegeuk Kim ALLOC_MODE_DEFAULT, /* stay default */ 107207939627SJaegeuk Kim ALLOC_MODE_REUSE, /* reuse segments as much as possible */ 107307939627SJaegeuk Kim }; 107407939627SJaegeuk Kim 107593cf93f1SJunling Zheng enum fsync_mode { 107693cf93f1SJunling Zheng FSYNC_MODE_POSIX, /* fsync follows posix semantics */ 107793cf93f1SJunling Zheng FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */ 107893cf93f1SJunling Zheng }; 107993cf93f1SJunling Zheng 108039a53e0cSJaegeuk Kim struct f2fs_sb_info { 108139a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 10825e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 108339a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 1084846ae671SChao Yu struct rw_semaphore sb_lock; /* lock for raw super block */ 1085e8240f65SChao Yu int valid_super_block; /* valid super block no */ 1086fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 108739a53e0cSJaegeuk Kim 1088178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 1089178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1090178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 1091178053e2SDamien Le Moal #endif 1092178053e2SDamien Le Moal 109339a53e0cSJaegeuk Kim /* for node-related operations */ 109439a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 109539a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 109639a53e0cSJaegeuk Kim 109739a53e0cSJaegeuk Kim /* for segment-related operations */ 109839a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 10991ff7bd3bSJaegeuk Kim 11001ff7bd3bSJaegeuk Kim /* for bio operations */ 1101a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1102e41e6d75SChao Yu struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 1103e41e6d75SChao Yu /* bio ordering for NODE/DATA */ 11040a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 110539a53e0cSJaegeuk Kim 110639a53e0cSJaegeuk Kim /* for checkpoint */ 110739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 11088508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1109aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 111039a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 111139936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 1112b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1113b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 111459c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1115fb51b5efSChangman Lee wait_queue_head_t cp_wait; 11166beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 11176beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 111839a53e0cSJaegeuk Kim 111967298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 11206451e041SJaegeuk Kim 11216451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 11220d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 112339a53e0cSJaegeuk Kim 1124c227f912SChao Yu /* for inode management */ 1125c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1126c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 112739a53e0cSJaegeuk Kim 112813054c54SChao Yu /* for extent tree cache */ 112913054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 11305e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 113113054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 113213054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 11337441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1134137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 113574fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 113613054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 113713054c54SChao Yu 113839a53e0cSJaegeuk Kim /* basic filesystem units */ 113939a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 114039a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 114139a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 114239a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 114339a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 114439a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 114539a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 114639a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 114739a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 114839a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 114939a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 115039a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 115139a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1152e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 1153ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 1154a2a12b67SChao Yu unsigned int trigger_ssr_threshold; /* threshold to trigger ssr */ 1155f6df8f23SSheng Yong int readdir_ra; /* readahead inode in readdir */ 115639a53e0cSJaegeuk Kim 115739a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 115839a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1159a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 116039a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1161daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 116280d42145SYunlong Song block_t current_reserved_blocks; /* current reserved blocks */ 1163daeb433eSChao Yu 1164292c196aSChao Yu unsigned int nquota_files; /* # of quota sysfile */ 1165292c196aSChao Yu 116639a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 1167523be8a6SJaegeuk Kim 1168523be8a6SJaegeuk Kim /* # of pages, see count_type */ 116935782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 117041382ec4SJaegeuk Kim /* # of allocated blocks */ 117141382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 117239a53e0cSJaegeuk Kim 1173687de7f1SJaegeuk Kim /* writeback control */ 1174687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 1175687de7f1SJaegeuk Kim 1176513c5f37SJaegeuk Kim /* valid inode count */ 1177513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1178513c5f37SJaegeuk Kim 117939a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 118039a53e0cSJaegeuk Kim 118139a53e0cSJaegeuk Kim /* for cleaning operations */ 118239a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 118339a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 11845ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 118539a53e0cSJaegeuk Kim 1186e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 1187e93b9865SHou Pengyang u64 fggc_threshold; 1188e93b9865SHou Pengyang 11891ad71a27SJaegeuk Kim /* threshold for gc trials on pinned files */ 11901ad71a27SJaegeuk Kim u64 gc_pin_file_threshold; 11911ad71a27SJaegeuk Kim 1192b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1193b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1194b1c57c1cSJaegeuk Kim 119539a53e0cSJaegeuk Kim /* 119639a53e0cSJaegeuk Kim * for stat information. 119739a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 119839a53e0cSJaegeuk Kim */ 119935b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 120039a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 120139a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 120239a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1203b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 12045b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 12055b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 12065b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 12075b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1208d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 120903e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 121003e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 121126a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 1212648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 121326a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1214648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 121539a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 121633fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 121735b09d82SNamjae Jeon #endif 121839a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1219b59d0baeSNamjae Jeon 1220b0af6d49SChao Yu /* For app/fs IO statistics */ 1221b0af6d49SChao Yu spinlock_t iostat_lock; 1222b0af6d49SChao Yu unsigned long long write_iostat[NR_IO_TYPE]; 1223b0af6d49SChao Yu bool iostat_enable; 1224b0af6d49SChao Yu 1225b59d0baeSNamjae Jeon /* For sysfs suppport */ 1226b59d0baeSNamjae Jeon struct kobject s_kobj; 1227b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 12282658e50dSJaegeuk Kim 12292658e50dSJaegeuk Kim /* For shrinker support */ 12302658e50dSJaegeuk Kim struct list_head s_list; 12313c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 12323c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 12331228b482SChao Yu unsigned int dirty_device; /* for checkpoint data flush */ 12341228b482SChao Yu spinlock_t dev_lock; /* protect dirty_device */ 12352658e50dSJaegeuk Kim struct mutex umount_mutex; 12362658e50dSJaegeuk Kim unsigned int shrinker_run_no; 12378f1dbbbbSShuoran Liu 12388f1dbbbbSShuoran Liu /* For write statistics */ 12398f1dbbbbSShuoran Liu u64 sectors_written_start; 12408f1dbbbbSShuoran Liu u64 kbytes_written; 124143b6573bSKeith Mok 124243b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 124343b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 12441ecc0c5cSChao Yu 1245704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1246704956ecSChao Yu __u32 s_chksum_seed; 124739a53e0cSJaegeuk Kim }; 124839a53e0cSJaegeuk Kim 12491ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 125055523519SChao Yu #define f2fs_show_injection_info(type) \ 125155523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 125255523519SChao Yu KERN_INFO, fault_name[type], \ 125355523519SChao Yu __func__, __builtin_return_address(0)) 12541ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 12551ecc0c5cSChao Yu { 125663189b78SChao Yu struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; 12571ecc0c5cSChao Yu 12581ecc0c5cSChao Yu if (!ffi->inject_rate) 12591ecc0c5cSChao Yu return false; 12601ecc0c5cSChao Yu 12611ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 12621ecc0c5cSChao Yu return false; 12631ecc0c5cSChao Yu 12641ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 12651ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 12661ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 12671ecc0c5cSChao Yu return true; 12681ecc0c5cSChao Yu } 12691ecc0c5cSChao Yu return false; 12701ecc0c5cSChao Yu } 12711ecc0c5cSChao Yu #endif 12721ecc0c5cSChao Yu 12738f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 12748f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 12758f1dbbbbSShuoran Liu */ 12768f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 127768afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 127868afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 12798f1dbbbbSShuoran Liu 12806beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 12816beceb54SJaegeuk Kim { 12826beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 12836beceb54SJaegeuk Kim } 12846beceb54SJaegeuk Kim 12856beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 12866beceb54SJaegeuk Kim { 12876bccfa19SArnd Bergmann unsigned long interval = sbi->interval_time[type] * HZ; 12886beceb54SJaegeuk Kim 12896beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 12906beceb54SJaegeuk Kim } 12916beceb54SJaegeuk Kim 1292d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1293d0239e1bSJaegeuk Kim { 1294d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1295d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1296d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1297d0239e1bSJaegeuk Kim 1298d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1299d0239e1bSJaegeuk Kim return 0; 1300d0239e1bSJaegeuk Kim 1301d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1302d0239e1bSJaegeuk Kim } 1303d0239e1bSJaegeuk Kim 130439a53e0cSJaegeuk Kim /* 130539a53e0cSJaegeuk Kim * Inline functions 130639a53e0cSJaegeuk Kim */ 1307416d2dbbSChao Yu static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc, 1308704956ecSChao Yu const void *address, unsigned int length) 1309704956ecSChao Yu { 1310704956ecSChao Yu struct { 1311704956ecSChao Yu struct shash_desc shash; 1312704956ecSChao Yu char ctx[4]; 1313704956ecSChao Yu } desc; 1314704956ecSChao Yu int err; 1315704956ecSChao Yu 1316704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1317704956ecSChao Yu 1318704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1319704956ecSChao Yu desc.shash.flags = 0; 1320704956ecSChao Yu *(u32 *)desc.ctx = crc; 1321704956ecSChao Yu 1322704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1323704956ecSChao Yu BUG_ON(err); 1324704956ecSChao Yu 1325704956ecSChao Yu return *(u32 *)desc.ctx; 1326704956ecSChao Yu } 1327704956ecSChao Yu 1328416d2dbbSChao Yu static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 1329416d2dbbSChao Yu unsigned int length) 1330416d2dbbSChao Yu { 1331416d2dbbSChao Yu return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length); 1332416d2dbbSChao Yu } 1333416d2dbbSChao Yu 1334416d2dbbSChao Yu static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 1335416d2dbbSChao Yu void *buf, size_t buf_size) 1336416d2dbbSChao Yu { 1337416d2dbbSChao Yu return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 1338416d2dbbSChao Yu } 1339416d2dbbSChao Yu 1340416d2dbbSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1341416d2dbbSChao Yu const void *address, unsigned int length) 1342416d2dbbSChao Yu { 1343416d2dbbSChao Yu return __f2fs_crc32(sbi, crc, address, length); 1344416d2dbbSChao Yu } 1345416d2dbbSChao Yu 134639a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 134739a53e0cSJaegeuk Kim { 134839a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 134939a53e0cSJaegeuk Kim } 135039a53e0cSJaegeuk Kim 135139a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 135239a53e0cSJaegeuk Kim { 135339a53e0cSJaegeuk Kim return sb->s_fs_info; 135439a53e0cSJaegeuk Kim } 135539a53e0cSJaegeuk Kim 13564081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 13574081363fSJaegeuk Kim { 13584081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 13594081363fSJaegeuk Kim } 13604081363fSJaegeuk Kim 13614081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 13624081363fSJaegeuk Kim { 13634081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 13644081363fSJaegeuk Kim } 13654081363fSJaegeuk Kim 13664081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 13674081363fSJaegeuk Kim { 13684081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 13694081363fSJaegeuk Kim } 13704081363fSJaegeuk Kim 137139a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 137239a53e0cSJaegeuk Kim { 137339a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 137439a53e0cSJaegeuk Kim } 137539a53e0cSJaegeuk Kim 137639a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 137739a53e0cSJaegeuk Kim { 137839a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 137939a53e0cSJaegeuk Kim } 138039a53e0cSJaegeuk Kim 138145590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 138245590710SGu Zheng { 138345590710SGu Zheng return (struct f2fs_node *)page_address(page); 138445590710SGu Zheng } 138545590710SGu Zheng 138658bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 138758bfaf44SJaegeuk Kim { 138858bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 138958bfaf44SJaegeuk Kim } 139058bfaf44SJaegeuk Kim 139139a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 139239a53e0cSJaegeuk Kim { 139339a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 139439a53e0cSJaegeuk Kim } 139539a53e0cSJaegeuk Kim 139639a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 139739a53e0cSJaegeuk Kim { 139839a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 139939a53e0cSJaegeuk Kim } 140039a53e0cSJaegeuk Kim 140139a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 140239a53e0cSJaegeuk Kim { 140339a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 140439a53e0cSJaegeuk Kim } 140539a53e0cSJaegeuk Kim 140639a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 140739a53e0cSJaegeuk Kim { 140839a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 140939a53e0cSJaegeuk Kim } 141039a53e0cSJaegeuk Kim 141139a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 141239a53e0cSJaegeuk Kim { 141339a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 141439a53e0cSJaegeuk Kim } 141539a53e0cSJaegeuk Kim 14169df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 14179df27d98SGu Zheng { 14189df27d98SGu Zheng return sbi->meta_inode->i_mapping; 14199df27d98SGu Zheng } 14209df27d98SGu Zheng 14214ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 14224ef51a8fSJaegeuk Kim { 14234ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 14244ef51a8fSJaegeuk Kim } 14254ef51a8fSJaegeuk Kim 1426caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 142739a53e0cSJaegeuk Kim { 1428fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 142939a53e0cSJaegeuk Kim } 143039a53e0cSJaegeuk Kim 1431caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 143239a53e0cSJaegeuk Kim { 1433fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1434caf0047eSChao Yu } 1435caf0047eSChao Yu 1436caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1437caf0047eSChao Yu { 1438fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 143939a53e0cSJaegeuk Kim } 144039a53e0cSJaegeuk Kim 1441d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1442d71b5564SJaegeuk Kim { 1443d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1444d71b5564SJaegeuk Kim } 1445d71b5564SJaegeuk Kim 1446ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) 1447ea676733SJaegeuk Kim { 1448ea676733SJaegeuk Kim if (type < F2FS_MAX_QUOTAS) 1449ea676733SJaegeuk Kim return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); 1450ea676733SJaegeuk Kim return 0; 1451ea676733SJaegeuk Kim } 1452ea676733SJaegeuk Kim 1453ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1454ced2c7eaSKinglong Mee { 1455ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1456ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1457ced2c7eaSKinglong Mee } 1458ced2c7eaSKinglong Mee 1459aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 146025ca923bSJaegeuk Kim { 146125ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1462aaec2b1dSChao Yu 146325ca923bSJaegeuk Kim return ckpt_flags & f; 146425ca923bSJaegeuk Kim } 146525ca923bSJaegeuk Kim 1466aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 146725ca923bSJaegeuk Kim { 1468aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1469aaec2b1dSChao Yu } 1470aaec2b1dSChao Yu 1471aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1472aaec2b1dSChao Yu { 1473aaec2b1dSChao Yu unsigned int ckpt_flags; 1474aaec2b1dSChao Yu 1475aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 147625ca923bSJaegeuk Kim ckpt_flags |= f; 147725ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 147825ca923bSJaegeuk Kim } 147925ca923bSJaegeuk Kim 1480aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 148125ca923bSJaegeuk Kim { 1482d1aa2453SChao Yu unsigned long flags; 1483d1aa2453SChao Yu 1484d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1485aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1486d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1487aaec2b1dSChao Yu } 1488aaec2b1dSChao Yu 1489aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1490aaec2b1dSChao Yu { 1491aaec2b1dSChao Yu unsigned int ckpt_flags; 1492aaec2b1dSChao Yu 1493aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 149425ca923bSJaegeuk Kim ckpt_flags &= (~f); 149525ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 149625ca923bSJaegeuk Kim } 149725ca923bSJaegeuk Kim 1498aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1499aaec2b1dSChao Yu { 1500d1aa2453SChao Yu unsigned long flags; 1501d1aa2453SChao Yu 1502d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1503aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1504d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1505aaec2b1dSChao Yu } 1506aaec2b1dSChao Yu 150722ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 150822ad0b6aSJaegeuk Kim { 1509d1aa2453SChao Yu unsigned long flags; 1510d1aa2453SChao Yu 151122ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 151222ad0b6aSJaegeuk Kim 151322ad0b6aSJaegeuk Kim if (lock) 1514d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 151522ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 151622ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 151722ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 151822ad0b6aSJaegeuk Kim if (lock) 1519d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 152022ad0b6aSJaegeuk Kim } 152122ad0b6aSJaegeuk Kim 152222ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 152322ad0b6aSJaegeuk Kim struct cp_control *cpc) 152422ad0b6aSJaegeuk Kim { 152522ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 152622ad0b6aSJaegeuk Kim 1527c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 152822ad0b6aSJaegeuk Kim } 152922ad0b6aSJaegeuk Kim 1530e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 153139a53e0cSJaegeuk Kim { 1532b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 153339a53e0cSJaegeuk Kim } 153439a53e0cSJaegeuk Kim 1535cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1536cc15620bSJaegeuk Kim { 1537cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1538cc15620bSJaegeuk Kim } 1539cc15620bSJaegeuk Kim 1540e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 154139a53e0cSJaegeuk Kim { 1542b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 154339936837SJaegeuk Kim } 154439936837SJaegeuk Kim 1545e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 154639936837SJaegeuk Kim { 1547b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 154839936837SJaegeuk Kim } 154939936837SJaegeuk Kim 1550e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 155139936837SJaegeuk Kim { 1552b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 155339a53e0cSJaegeuk Kim } 155439a53e0cSJaegeuk Kim 1555119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1556119ee914SJaegeuk Kim { 1557119ee914SJaegeuk Kim int reason = CP_SYNC; 1558119ee914SJaegeuk Kim 1559119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1560119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1561119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1562119ee914SJaegeuk Kim reason = CP_UMOUNT; 1563119ee914SJaegeuk Kim return reason; 1564119ee914SJaegeuk Kim } 1565119ee914SJaegeuk Kim 1566119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1567119ee914SJaegeuk Kim { 1568c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1569119ee914SJaegeuk Kim } 1570119ee914SJaegeuk Kim 1571119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1572119ee914SJaegeuk Kim { 1573aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1574aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1575119ee914SJaegeuk Kim } 1576119ee914SJaegeuk Kim 157739a53e0cSJaegeuk Kim /* 157839a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 157939a53e0cSJaegeuk Kim */ 1580064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 158139a53e0cSJaegeuk Kim { 1582d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1583d6b7d4b3SChao Yu return -EINVAL; 1584cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1585064e0823SNamjae Jeon return -EINVAL; 1586064e0823SNamjae Jeon return 0; 158739a53e0cSJaegeuk Kim } 158839a53e0cSJaegeuk Kim 158939a53e0cSJaegeuk Kim /* 159039a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 159139a53e0cSJaegeuk Kim */ 159239a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 159339a53e0cSJaegeuk Kim { 15940eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 15950eb0adadSChao Yu 1596000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 159739a53e0cSJaegeuk Kim } 159839a53e0cSJaegeuk Kim 15994bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 16004bc8e9bcSChao Yu { 16014bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 16024bc8e9bcSChao Yu } 16034bc8e9bcSChao Yu 1604d8a9a229SJaegeuk Kim static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, 1605d8a9a229SJaegeuk Kim struct inode *inode) 16067c2e5963SJaegeuk Kim { 1607d8a9a229SJaegeuk Kim if (!inode) 1608d8a9a229SJaegeuk Kim return true; 16097c2e5963SJaegeuk Kim if (!test_opt(sbi, RESERVE_ROOT)) 16107c2e5963SJaegeuk Kim return false; 1611d8a9a229SJaegeuk Kim if (IS_NOQUOTA(inode)) 1612d8a9a229SJaegeuk Kim return true; 161363189b78SChao Yu if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid())) 16147c2e5963SJaegeuk Kim return true; 161563189b78SChao Yu if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) && 161663189b78SChao Yu in_group_p(F2FS_OPTION(sbi).s_resgid)) 16177c2e5963SJaegeuk Kim return true; 1618162b27aeSJaegeuk Kim if (capable(CAP_SYS_RESOURCE)) 1619162b27aeSJaegeuk Kim return true; 16207c2e5963SJaegeuk Kim return false; 16217c2e5963SJaegeuk Kim } 16227c2e5963SJaegeuk Kim 16230abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 16240abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 162546008c6dSChao Yu struct inode *inode, blkcnt_t *count) 162639a53e0cSJaegeuk Kim { 16270abd675eSChao Yu blkcnt_t diff = 0, release = 0; 1628daeb433eSChao Yu block_t avail_user_block_count; 16290abd675eSChao Yu int ret; 16300abd675eSChao Yu 16310abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 16320abd675eSChao Yu if (ret) 16330abd675eSChao Yu return ret; 1634dd11a5dfSJaegeuk Kim 1635cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 163655523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 163755523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 16380abd675eSChao Yu release = *count; 16390abd675eSChao Yu goto enospc; 164055523519SChao Yu } 1641cb78942bSJaegeuk Kim #endif 1642dd11a5dfSJaegeuk Kim /* 1643dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1644dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1645dd11a5dfSJaegeuk Kim */ 1646dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1647cfb271d4SChao Yu 164839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 16492555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 165080d42145SYunlong Song avail_user_block_count = sbi->user_block_count - 165180d42145SYunlong Song sbi->current_reserved_blocks; 16527e65be49SJaegeuk Kim 1653d8a9a229SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode)) 165463189b78SChao Yu avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; 16557e65be49SJaegeuk Kim 1656daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1657daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 16587e65be49SJaegeuk Kim if (diff > *count) 16597e65be49SJaegeuk Kim diff = *count; 1660dd11a5dfSJaegeuk Kim *count -= diff; 16610abd675eSChao Yu release = diff; 16627e65be49SJaegeuk Kim sbi->total_valid_block_count -= diff; 166346008c6dSChao Yu if (!*count) { 166439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1665dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 16660abd675eSChao Yu goto enospc; 166739a53e0cSJaegeuk Kim } 166846008c6dSChao Yu } 166939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 167041382ec4SJaegeuk Kim 1671fab2adeeSLiFan if (unlikely(release)) 16720abd675eSChao Yu dquot_release_reservation_block(inode, release); 16730abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 16740abd675eSChao Yu return 0; 16750abd675eSChao Yu 16760abd675eSChao Yu enospc: 16770abd675eSChao Yu dquot_release_reservation_block(inode, release); 16780abd675eSChao Yu return -ENOSPC; 167939a53e0cSJaegeuk Kim } 168039a53e0cSJaegeuk Kim 1681da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 168239a53e0cSJaegeuk Kim struct inode *inode, 16830eb0adadSChao Yu block_t count) 168439a53e0cSJaegeuk Kim { 16850eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 16860eb0adadSChao Yu 168739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 16889850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 16890eb0adadSChao Yu f2fs_bug_on(sbi, inode->i_blocks < sectors); 169039a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 169180d42145SYunlong Song if (sbi->reserved_blocks && 169280d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 169380d42145SYunlong Song sbi->current_reserved_blocks = min(sbi->reserved_blocks, 169480d42145SYunlong Song sbi->current_reserved_blocks + count); 169539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 16960abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 169739a53e0cSJaegeuk Kim } 169839a53e0cSJaegeuk Kim 169939a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 170039a53e0cSJaegeuk Kim { 170135782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 17027c4abcbeSChao Yu 170336951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 170436951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 17057c4abcbeSChao Yu return; 17067c4abcbeSChao Yu 1707caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 170839a53e0cSJaegeuk Kim } 170939a53e0cSJaegeuk Kim 1710a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 171139a53e0cSJaegeuk Kim { 1712204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1713c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1714c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 17152c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 17162c8a4a28SJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 171739a53e0cSJaegeuk Kim } 171839a53e0cSJaegeuk Kim 171939a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 172039a53e0cSJaegeuk Kim { 172135782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 172239a53e0cSJaegeuk Kim } 172339a53e0cSJaegeuk Kim 1724a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 172539a53e0cSJaegeuk Kim { 17265ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 17275ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 17281fe54f9dSJaegeuk Kim return; 17291fe54f9dSJaegeuk Kim 1730204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1731c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1732c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 17332c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 17342c8a4a28SJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 173539a53e0cSJaegeuk Kim } 173639a53e0cSJaegeuk Kim 1737523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 173839a53e0cSJaegeuk Kim { 173935782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 174039a53e0cSJaegeuk Kim } 174139a53e0cSJaegeuk Kim 1742204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1743f8b2c1f9SJaegeuk Kim { 1744204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1745f8b2c1f9SJaegeuk Kim } 1746f8b2c1f9SJaegeuk Kim 17475ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 17485ac206cfSNamjae Jeon { 17493519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1750523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1751523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1752523be8a6SJaegeuk Kim 1753523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 17545ac206cfSNamjae Jeon } 17555ac206cfSNamjae Jeon 175639a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 175739a53e0cSJaegeuk Kim { 17588b8343faSJaegeuk Kim return sbi->total_valid_block_count; 175939a53e0cSJaegeuk Kim } 176039a53e0cSJaegeuk Kim 1761f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1762f83a2584SYunlei He { 1763f83a2584SYunlei He return sbi->discard_blks; 1764f83a2584SYunlei He } 1765f83a2584SYunlei He 176639a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 176739a53e0cSJaegeuk Kim { 176839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 176939a53e0cSJaegeuk Kim 177039a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 177139a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 177239a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 177339a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 177439a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 177539a53e0cSJaegeuk Kim 177639a53e0cSJaegeuk Kim return 0; 177739a53e0cSJaegeuk Kim } 177839a53e0cSJaegeuk Kim 177955141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 178055141486SWanpeng Li { 178155141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 178255141486SWanpeng Li } 178355141486SWanpeng Li 178439a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 178539a53e0cSJaegeuk Kim { 178639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 17871dbe4152SChangman Lee int offset; 17881dbe4152SChangman Lee 1789199bc3feSChao Yu if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { 1790199bc3feSChao Yu offset = (flag == SIT_BITMAP) ? 1791199bc3feSChao Yu le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; 1792199bc3feSChao Yu return &ckpt->sit_nat_version_bitmap + offset; 1793199bc3feSChao Yu } 1794199bc3feSChao Yu 179555141486SWanpeng Li if (__cp_payload(sbi) > 0) { 17961dbe4152SChangman Lee if (flag == NAT_BITMAP) 17971dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 17981dbe4152SChangman Lee else 179965b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 18001dbe4152SChangman Lee } else { 18011dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 180225ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 180339a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 180439a53e0cSJaegeuk Kim } 18051dbe4152SChangman Lee } 180639a53e0cSJaegeuk Kim 180739a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 180839a53e0cSJaegeuk Kim { 18098508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 181039a53e0cSJaegeuk Kim 18118508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 181239a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 181339a53e0cSJaegeuk Kim return start_addr; 181439a53e0cSJaegeuk Kim } 181539a53e0cSJaegeuk Kim 18168508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 18178508e44aSJaegeuk Kim { 18188508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 18198508e44aSJaegeuk Kim 18208508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 18218508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 18228508e44aSJaegeuk Kim return start_addr; 18238508e44aSJaegeuk Kim } 18248508e44aSJaegeuk Kim 18258508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 18268508e44aSJaegeuk Kim { 18278508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 18288508e44aSJaegeuk Kim } 18298508e44aSJaegeuk Kim 183039a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 183139a53e0cSJaegeuk Kim { 183239a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 183339a53e0cSJaegeuk Kim } 183439a53e0cSJaegeuk Kim 18350abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 1836000519f2SChao Yu struct inode *inode, bool is_inode) 183739a53e0cSJaegeuk Kim { 183839a53e0cSJaegeuk Kim block_t valid_block_count; 183939a53e0cSJaegeuk Kim unsigned int valid_node_count; 18400abd675eSChao Yu bool quota = inode && !is_inode; 18410abd675eSChao Yu 18420abd675eSChao Yu if (quota) { 18430abd675eSChao Yu int ret = dquot_reserve_block(inode, 1); 18440abd675eSChao Yu if (ret) 18450abd675eSChao Yu return ret; 18460abd675eSChao Yu } 184739a53e0cSJaegeuk Kim 1848812c6056SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 1849812c6056SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 1850812c6056SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 1851812c6056SChao Yu goto enospc; 1852812c6056SChao Yu } 1853812c6056SChao Yu #endif 1854812c6056SChao Yu 185539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 185639a53e0cSJaegeuk Kim 18577e65be49SJaegeuk Kim valid_block_count = sbi->total_valid_block_count + 18587e65be49SJaegeuk Kim sbi->current_reserved_blocks + 1; 18597e65be49SJaegeuk Kim 1860d8a9a229SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode)) 186163189b78SChao Yu valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; 18627e65be49SJaegeuk Kim 18637e65be49SJaegeuk Kim if (unlikely(valid_block_count > sbi->user_block_count)) { 186439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 18650abd675eSChao Yu goto enospc; 186639a53e0cSJaegeuk Kim } 186739a53e0cSJaegeuk Kim 1868ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1869cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 187039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 18710abd675eSChao Yu goto enospc; 187239a53e0cSJaegeuk Kim } 187339a53e0cSJaegeuk Kim 1874ef86d709SGu Zheng sbi->total_valid_node_count++; 1875ef86d709SGu Zheng sbi->total_valid_block_count++; 187639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 187739a53e0cSJaegeuk Kim 18780abd675eSChao Yu if (inode) { 18790abd675eSChao Yu if (is_inode) 18800abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 18810abd675eSChao Yu else 18820abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 18830abd675eSChao Yu } 18840abd675eSChao Yu 188541382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 18860abd675eSChao Yu return 0; 18870abd675eSChao Yu 18880abd675eSChao Yu enospc: 18890abd675eSChao Yu if (quota) 18900abd675eSChao Yu dquot_release_reservation_block(inode, 1); 18910abd675eSChao Yu return -ENOSPC; 189239a53e0cSJaegeuk Kim } 189339a53e0cSJaegeuk Kim 189439a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1895000519f2SChao Yu struct inode *inode, bool is_inode) 189639a53e0cSJaegeuk Kim { 189739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 189839a53e0cSJaegeuk Kim 18999850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 19009850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 1901000519f2SChao Yu f2fs_bug_on(sbi, !is_inode && !inode->i_blocks); 190239a53e0cSJaegeuk Kim 1903ef86d709SGu Zheng sbi->total_valid_node_count--; 1904ef86d709SGu Zheng sbi->total_valid_block_count--; 190580d42145SYunlong Song if (sbi->reserved_blocks && 190680d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 190780d42145SYunlong Song sbi->current_reserved_blocks++; 190839a53e0cSJaegeuk Kim 190939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 19100abd675eSChao Yu 19110abd675eSChao Yu if (!is_inode) 19120abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 191339a53e0cSJaegeuk Kim } 191439a53e0cSJaegeuk Kim 191539a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 191639a53e0cSJaegeuk Kim { 19178b8343faSJaegeuk Kim return sbi->total_valid_node_count; 191839a53e0cSJaegeuk Kim } 191939a53e0cSJaegeuk Kim 192039a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 192139a53e0cSJaegeuk Kim { 1922513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 192339a53e0cSJaegeuk Kim } 192439a53e0cSJaegeuk Kim 19250e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 192639a53e0cSJaegeuk Kim { 1927513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 192839a53e0cSJaegeuk Kim } 192939a53e0cSJaegeuk Kim 1930513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 193139a53e0cSJaegeuk Kim { 1932513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 193339a53e0cSJaegeuk Kim } 193439a53e0cSJaegeuk Kim 1935a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1936a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1937a56c7c6fSJaegeuk Kim { 1938c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1939c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1940cac5a3d8SDongOh Shin 1941c41f3cc3SJaegeuk Kim if (page) 1942c41f3cc3SJaegeuk Kim return page; 1943c41f3cc3SJaegeuk Kim 194455523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 194555523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1946c41f3cc3SJaegeuk Kim return NULL; 194755523519SChao Yu } 1948c41f3cc3SJaegeuk Kim #endif 1949a56c7c6fSJaegeuk Kim if (!for_write) 1950a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1951a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1952a56c7c6fSJaegeuk Kim } 1953a56c7c6fSJaegeuk Kim 195401eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page( 195501eccef7SChao Yu struct address_space *mapping, pgoff_t index, 195601eccef7SChao Yu int fgp_flags, gfp_t gfp_mask) 195701eccef7SChao Yu { 195801eccef7SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 195901eccef7SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { 196001eccef7SChao Yu f2fs_show_injection_info(FAULT_PAGE_GET); 196101eccef7SChao Yu return NULL; 196201eccef7SChao Yu } 196301eccef7SChao Yu #endif 196401eccef7SChao Yu return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); 196501eccef7SChao Yu } 196601eccef7SChao Yu 19676e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 19686e2c64adSJaegeuk Kim { 19696e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 19706e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 19716e2c64adSJaegeuk Kim 19726e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 19736e2c64adSJaegeuk Kim kunmap(dst); 19746e2c64adSJaegeuk Kim kunmap(src); 19756e2c64adSJaegeuk Kim } 19766e2c64adSJaegeuk Kim 197739a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 197839a53e0cSJaegeuk Kim { 1979031fa8ccSJaegeuk Kim if (!page) 198039a53e0cSJaegeuk Kim return; 198139a53e0cSJaegeuk Kim 198239a53e0cSJaegeuk Kim if (unlock) { 19839850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 198439a53e0cSJaegeuk Kim unlock_page(page); 198539a53e0cSJaegeuk Kim } 198609cbfeafSKirill A. Shutemov put_page(page); 198739a53e0cSJaegeuk Kim } 198839a53e0cSJaegeuk Kim 198939a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 199039a53e0cSJaegeuk Kim { 199139a53e0cSJaegeuk Kim if (dn->node_page) 199239a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 199339a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 199439a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 199539a53e0cSJaegeuk Kim dn->node_page = NULL; 199639a53e0cSJaegeuk Kim dn->inode_page = NULL; 199739a53e0cSJaegeuk Kim } 199839a53e0cSJaegeuk Kim 199939a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 2000e8512d2eSGu Zheng size_t size) 200139a53e0cSJaegeuk Kim { 2002e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 200339a53e0cSJaegeuk Kim } 200439a53e0cSJaegeuk Kim 20057bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 20067bd59381SGu Zheng gfp_t flags) 20077bd59381SGu Zheng { 20087bd59381SGu Zheng void *entry; 20097bd59381SGu Zheng 201080c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 201180c54505SJaegeuk Kim if (!entry) 201280c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 20137bd59381SGu Zheng return entry; 20147bd59381SGu Zheng } 20157bd59381SGu Zheng 2016d62fe971SChao Yu static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, 2017d62fe971SChao Yu int npages, bool no_fail) 2018740432f8SJaegeuk Kim { 2019740432f8SJaegeuk Kim struct bio *bio; 2020740432f8SJaegeuk Kim 2021d62fe971SChao Yu if (no_fail) { 2022740432f8SJaegeuk Kim /* No failure on bio allocation */ 2023740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 202480c54505SJaegeuk Kim if (!bio) 202580c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 2026740432f8SJaegeuk Kim return bio; 2027740432f8SJaegeuk Kim } 2028d62fe971SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 2029d62fe971SChao Yu if (time_to_inject(sbi, FAULT_ALLOC_BIO)) { 2030d62fe971SChao Yu f2fs_show_injection_info(FAULT_ALLOC_BIO); 2031d62fe971SChao Yu return NULL; 2032d62fe971SChao Yu } 2033d62fe971SChao Yu #endif 2034d62fe971SChao Yu return bio_alloc(GFP_KERNEL, npages); 2035d62fe971SChao Yu } 2036740432f8SJaegeuk Kim 20379be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 20389be32d72SJaegeuk Kim unsigned long index, void *item) 20399be32d72SJaegeuk Kim { 20409be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 20419be32d72SJaegeuk Kim cond_resched(); 20429be32d72SJaegeuk Kim } 20439be32d72SJaegeuk Kim 204439a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 204539a53e0cSJaegeuk Kim 204639a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 204739a53e0cSJaegeuk Kim { 204845590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 2049cac5a3d8SDongOh Shin 205039a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 205139a53e0cSJaegeuk Kim } 205239a53e0cSJaegeuk Kim 20537a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 20547a2af766SChao Yu { 20557a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 20567a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 20577a2af766SChao Yu } 20587a2af766SChao Yu 205939a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 206039a53e0cSJaegeuk Kim { 206139a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 206239a53e0cSJaegeuk Kim } 206339a53e0cSJaegeuk Kim 20647a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 20657a2af766SChao Yu static inline block_t datablock_addr(struct inode *inode, 20667a2af766SChao Yu struct page *node_page, unsigned int offset) 206739a53e0cSJaegeuk Kim { 206839a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 206939a53e0cSJaegeuk Kim __le32 *addr_array; 20707a2af766SChao Yu int base = 0; 20717a2af766SChao Yu bool is_inode = IS_INODE(node_page); 2072cac5a3d8SDongOh Shin 207345590710SGu Zheng raw_node = F2FS_NODE(node_page); 20747a2af766SChao Yu 20757a2af766SChao Yu /* from GC path only */ 2076979f492fSLiFan if (is_inode) { 2077979f492fSLiFan if (!inode) 20787a2af766SChao Yu base = offset_in_addr(&raw_node->i); 2079979f492fSLiFan else if (f2fs_has_extra_attr(inode)) 20807a2af766SChao Yu base = get_extra_isize(inode); 20817a2af766SChao Yu } 20827a2af766SChao Yu 208339a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 20847a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 208539a53e0cSJaegeuk Kim } 208639a53e0cSJaegeuk Kim 208739a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 208839a53e0cSJaegeuk Kim { 208939a53e0cSJaegeuk Kim int mask; 209039a53e0cSJaegeuk Kim 209139a53e0cSJaegeuk Kim addr += (nr >> 3); 209239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 209339a53e0cSJaegeuk Kim return mask & *addr; 209439a53e0cSJaegeuk Kim } 209539a53e0cSJaegeuk Kim 2096a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 2097a66cdd98SJaegeuk Kim { 2098a66cdd98SJaegeuk Kim int mask; 2099a66cdd98SJaegeuk Kim 2100a66cdd98SJaegeuk Kim addr += (nr >> 3); 2101a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2102a66cdd98SJaegeuk Kim *addr |= mask; 2103a66cdd98SJaegeuk Kim } 2104a66cdd98SJaegeuk Kim 2105a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 2106a66cdd98SJaegeuk Kim { 2107a66cdd98SJaegeuk Kim int mask; 2108a66cdd98SJaegeuk Kim 2109a66cdd98SJaegeuk Kim addr += (nr >> 3); 2110a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2111a66cdd98SJaegeuk Kim *addr &= ~mask; 2112a66cdd98SJaegeuk Kim } 2113a66cdd98SJaegeuk Kim 211452aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 211539a53e0cSJaegeuk Kim { 211639a53e0cSJaegeuk Kim int mask; 211739a53e0cSJaegeuk Kim int ret; 211839a53e0cSJaegeuk Kim 211939a53e0cSJaegeuk Kim addr += (nr >> 3); 212039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 212139a53e0cSJaegeuk Kim ret = mask & *addr; 212239a53e0cSJaegeuk Kim *addr |= mask; 212339a53e0cSJaegeuk Kim return ret; 212439a53e0cSJaegeuk Kim } 212539a53e0cSJaegeuk Kim 212652aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 212739a53e0cSJaegeuk Kim { 212839a53e0cSJaegeuk Kim int mask; 212939a53e0cSJaegeuk Kim int ret; 213039a53e0cSJaegeuk Kim 213139a53e0cSJaegeuk Kim addr += (nr >> 3); 213239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 213339a53e0cSJaegeuk Kim ret = mask & *addr; 213439a53e0cSJaegeuk Kim *addr &= ~mask; 213539a53e0cSJaegeuk Kim return ret; 213639a53e0cSJaegeuk Kim } 213739a53e0cSJaegeuk Kim 2138c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 2139c6ac4c0eSGu Zheng { 2140c6ac4c0eSGu Zheng int mask; 2141c6ac4c0eSGu Zheng 2142c6ac4c0eSGu Zheng addr += (nr >> 3); 2143c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 2144c6ac4c0eSGu Zheng *addr ^= mask; 2145c6ac4c0eSGu Zheng } 2146c6ac4c0eSGu Zheng 21475c57132eSChao Yu #define F2FS_REG_FLMASK (~(FS_DIRSYNC_FL | FS_TOPDIR_FL)) 21485c57132eSChao Yu #define F2FS_OTHER_FLMASK (FS_NODUMP_FL | FS_NOATIME_FL) 21495c57132eSChao Yu #define F2FS_FL_INHERITED (FS_PROJINHERIT_FL) 21505c57132eSChao Yu 21515c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 21525c57132eSChao Yu { 21535c57132eSChao Yu if (S_ISDIR(mode)) 21545c57132eSChao Yu return flags; 21555c57132eSChao Yu else if (S_ISREG(mode)) 21565c57132eSChao Yu return flags & F2FS_REG_FLMASK; 21575c57132eSChao Yu else 21585c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 21595c57132eSChao Yu } 21605c57132eSChao Yu 216139a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 216239a53e0cSJaegeuk Kim enum { 216339a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 2164b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 216526de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 2166ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 216739a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 216839a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 216939a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 2170c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 2171c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 2172444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 21731001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 217434d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 2175fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 2176fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 217788b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 217888b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 21795fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 218002a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 21813c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 21821e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 2183b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 2184510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 2185d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 2186c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 2187dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 2188ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 21897a2af766SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 21905c57132eSChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 21911ad71a27SJaegeuk Kim FI_PIN_FILE, /* indicate file should not be gced */ 219239a53e0cSJaegeuk Kim }; 219339a53e0cSJaegeuk Kim 2194205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2195205b9822SJaegeuk Kim int flag, bool set) 219639a53e0cSJaegeuk Kim { 2197205b9822SJaegeuk Kim switch (flag) { 2198205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2199205b9822SJaegeuk Kim case FI_INLINE_DATA: 2200205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 22019ac1e2d8SDaeho Jeong case FI_NEW_INODE: 2202205b9822SJaegeuk Kim if (set) 2203205b9822SJaegeuk Kim return; 2204205b9822SJaegeuk Kim case FI_DATA_EXIST: 2205205b9822SJaegeuk Kim case FI_INLINE_DOTS: 22061ad71a27SJaegeuk Kim case FI_PIN_FILE: 22077c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2208205b9822SJaegeuk Kim } 220939a53e0cSJaegeuk Kim } 221039a53e0cSJaegeuk Kim 221191942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 221239a53e0cSJaegeuk Kim { 221391942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 221491942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 2215205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 221639a53e0cSJaegeuk Kim } 221739a53e0cSJaegeuk Kim 221891942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 221939a53e0cSJaegeuk Kim { 222091942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 222139a53e0cSJaegeuk Kim } 222239a53e0cSJaegeuk Kim 222391942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 222439a53e0cSJaegeuk Kim { 222591942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 222691942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 2227205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 222839a53e0cSJaegeuk Kim } 222939a53e0cSJaegeuk Kim 223091942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2231444c580fSJaegeuk Kim { 223291942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 223391942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 22347c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 223539a53e0cSJaegeuk Kim } 223639a53e0cSJaegeuk Kim 2237a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2238a1961246SJaegeuk Kim { 2239a1961246SJaegeuk Kim if (inc) 2240a1961246SJaegeuk Kim inc_nlink(inode); 2241a1961246SJaegeuk Kim else 2242a1961246SJaegeuk Kim drop_nlink(inode); 22437c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2244a1961246SJaegeuk Kim } 2245a1961246SJaegeuk Kim 22468edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 22470abd675eSChao Yu block_t diff, bool add, bool claim) 22488edd03c8SJaegeuk Kim { 224926de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 225026de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 225126de9b11SJaegeuk Kim 22520abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 22530abd675eSChao Yu if (add) { 22540abd675eSChao Yu if (claim) 22550abd675eSChao Yu dquot_claim_block(inode, diff); 22560abd675eSChao Yu else 22570abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 22580abd675eSChao Yu } else { 22590abd675eSChao Yu dquot_free_block(inode, diff); 22600abd675eSChao Yu } 22610abd675eSChao Yu 22627c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 226326de9b11SJaegeuk Kim if (clean || recover) 226426de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 22658edd03c8SJaegeuk Kim } 22668edd03c8SJaegeuk Kim 2267fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2268fc9581c8SJaegeuk Kim { 226926de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 227026de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 227126de9b11SJaegeuk Kim 2272fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2273fc9581c8SJaegeuk Kim return; 2274fc9581c8SJaegeuk Kim 2275fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 22767c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 227726de9b11SJaegeuk Kim if (clean || recover) 227826de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 227926de9b11SJaegeuk Kim } 228026de9b11SJaegeuk Kim 2281205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2282205b9822SJaegeuk Kim { 2283205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 22847c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2285205b9822SJaegeuk Kim } 2286205b9822SJaegeuk Kim 22871ad71a27SJaegeuk Kim static inline void f2fs_i_gc_failures_write(struct inode *inode, 22881ad71a27SJaegeuk Kim unsigned int count) 22891ad71a27SJaegeuk Kim { 22901ad71a27SJaegeuk Kim F2FS_I(inode)->i_gc_failures = count; 22911ad71a27SJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 22921ad71a27SJaegeuk Kim } 22931ad71a27SJaegeuk Kim 2294205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2295205b9822SJaegeuk Kim { 2296205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 22977c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2298205b9822SJaegeuk Kim } 2299205b9822SJaegeuk Kim 2300205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2301205b9822SJaegeuk Kim { 2302205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 23037c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2304205b9822SJaegeuk Kim } 2305205b9822SJaegeuk Kim 230691942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2307444c580fSJaegeuk Kim { 2308205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2309205b9822SJaegeuk Kim 2310444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 2311205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 23121001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 2313205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 231434d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 2315205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 2316b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 2317205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 2318510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 2319205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 23207a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 23217a2af766SChao Yu set_bit(FI_EXTRA_ATTR, &fi->flags); 23221ad71a27SJaegeuk Kim if (ri->i_inline & F2FS_PIN_FILE) 23231ad71a27SJaegeuk Kim set_bit(FI_PIN_FILE, &fi->flags); 2324444c580fSJaegeuk Kim } 2325444c580fSJaegeuk Kim 232691942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2327444c580fSJaegeuk Kim { 2328444c580fSJaegeuk Kim ri->i_inline = 0; 2329444c580fSJaegeuk Kim 233091942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2331444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 233291942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 23331001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 233491942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 233534d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 233691942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2337b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 233891942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2339510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 23407a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 23417a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 23421ad71a27SJaegeuk Kim if (is_inode_flag_set(inode, FI_PIN_FILE)) 23431ad71a27SJaegeuk Kim ri->i_inline |= F2FS_PIN_FILE; 23447a2af766SChao Yu } 23457a2af766SChao Yu 23467a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 23477a2af766SChao Yu { 23487a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2349444c580fSJaegeuk Kim } 2350444c580fSJaegeuk Kim 2351987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2352987c7c31SChao Yu { 235391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2354987c7c31SChao Yu } 2355987c7c31SChao Yu 235681ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2357de93653fSJaegeuk Kim { 2358b323fd28SChao Yu return CUR_ADDRS_PER_INODE(inode) - get_inline_xattr_addrs(inode); 2359de93653fSJaegeuk Kim } 2360de93653fSJaegeuk Kim 23616afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page) 236265985d93SJaegeuk Kim { 2363695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2364cac5a3d8SDongOh Shin 236565985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 2366b323fd28SChao Yu get_inline_xattr_addrs(inode)]); 236765985d93SJaegeuk Kim } 236865985d93SJaegeuk Kim 236965985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 237065985d93SJaegeuk Kim { 23716afc662eSChao Yu return get_inline_xattr_addrs(inode) * sizeof(__le32); 237265985d93SJaegeuk Kim } 237365985d93SJaegeuk Kim 23740dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 23750dbdc2aeSJaegeuk Kim { 237691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 23770dbdc2aeSJaegeuk Kim } 23780dbdc2aeSJaegeuk Kim 2379b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2380b3d208f9SJaegeuk Kim { 238191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2382b3d208f9SJaegeuk Kim } 2383b3d208f9SJaegeuk Kim 2384510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2385510022a8SJaegeuk Kim { 238691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2387510022a8SJaegeuk Kim } 2388510022a8SJaegeuk Kim 23891ad71a27SJaegeuk Kim static inline bool f2fs_is_pinned_file(struct inode *inode) 23901ad71a27SJaegeuk Kim { 23911ad71a27SJaegeuk Kim return is_inode_flag_set(inode, FI_PIN_FILE); 23921ad71a27SJaegeuk Kim } 23931ad71a27SJaegeuk Kim 239488b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 239588b88a66SJaegeuk Kim { 239691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 239788b88a66SJaegeuk Kim } 239888b88a66SJaegeuk Kim 23995fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 24005fe45743SChao Yu { 24015fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 24025fe45743SChao Yu } 24035fe45743SChao Yu 240402a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 240502a1335fSJaegeuk Kim { 240691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 240702a1335fSJaegeuk Kim } 240802a1335fSJaegeuk Kim 24093c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 24103c6c2bebSJaegeuk Kim { 241191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 24123c6c2bebSJaegeuk Kim } 24133c6c2bebSJaegeuk Kim 24141e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 24151e84371fSJaegeuk Kim { 241691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 24171e84371fSJaegeuk Kim } 24181e84371fSJaegeuk Kim 2419f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 24201001b347SHuajun Li { 2421695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 24227a2af766SChao Yu int extra_size = get_extra_isize(inode); 2423cac5a3d8SDongOh Shin 24247a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 24251001b347SHuajun Li } 24261001b347SHuajun Li 242734d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 242834d67debSChao Yu { 242991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 243034d67debSChao Yu } 243134d67debSChao Yu 2432b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2433b5492af7SJaegeuk Kim { 2434b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2435b5492af7SJaegeuk Kim } 2436b5492af7SJaegeuk Kim 2437b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2438b5492af7SJaegeuk Kim { 2439b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 24407c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2441b5492af7SJaegeuk Kim } 2442b5492af7SJaegeuk Kim 2443b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2444b5492af7SJaegeuk Kim { 2445b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 24467c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2447b5492af7SJaegeuk Kim } 2448b5492af7SJaegeuk Kim 244926787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 245026787236SJaegeuk Kim { 2451a0d00fadSChao Yu bool ret; 2452a0d00fadSChao Yu 245326787236SJaegeuk Kim if (dsync) { 245426787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 245526787236SJaegeuk Kim 245626787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 245726787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 245826787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 245926787236SJaegeuk Kim return ret; 246026787236SJaegeuk Kim } 246126787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 246226787236SJaegeuk Kim file_keep_isize(inode) || 246326787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 246426787236SJaegeuk Kim return false; 2465a0d00fadSChao Yu 2466a0d00fadSChao Yu down_read(&F2FS_I(inode)->i_sem); 2467a0d00fadSChao Yu ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 2468a0d00fadSChao Yu up_read(&F2FS_I(inode)->i_sem); 2469a0d00fadSChao Yu 2470a0d00fadSChao Yu return ret; 2471267378d4SChao Yu } 2472267378d4SChao Yu 2473deeedd71SChao Yu static inline bool f2fs_readonly(struct super_block *sb) 247477888c1eSJaegeuk Kim { 2475deeedd71SChao Yu return sb_rdonly(sb); 247677888c1eSJaegeuk Kim } 247777888c1eSJaegeuk Kim 2478744602cfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 2479744602cfSJaegeuk Kim { 2480aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 2481744602cfSJaegeuk Kim } 2482744602cfSJaegeuk Kim 2483eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2484eaa693f4SJaegeuk Kim { 2485eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2486eaa693f4SJaegeuk Kim return true; 2487eaa693f4SJaegeuk Kim 2488eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2489eaa693f4SJaegeuk Kim return true; 2490eaa693f4SJaegeuk Kim 2491eaa693f4SJaegeuk Kim return false; 2492eaa693f4SJaegeuk Kim } 2493eaa693f4SJaegeuk Kim 24943e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 24953e72f721SJaegeuk Kim { 24963e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 249791942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 24983e72f721SJaegeuk Kim return false; 24993e72f721SJaegeuk Kim 2500886f56f9SAl Viro return S_ISREG(inode->i_mode); 25013e72f721SJaegeuk Kim } 25023e72f721SJaegeuk Kim 25031ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 25041ecc0c5cSChao Yu size_t size, gfp_t flags) 25050414b004SJaegeuk Kim { 25062c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 250755523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 250855523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 25092c63feadSJaegeuk Kim return NULL; 251055523519SChao Yu } 25112c63feadSJaegeuk Kim #endif 25120414b004SJaegeuk Kim return kmalloc(size, flags); 25130414b004SJaegeuk Kim } 25140414b004SJaegeuk Kim 2515acbf054dSChao Yu static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, 2516acbf054dSChao Yu size_t size, gfp_t flags) 2517acbf054dSChao Yu { 2518acbf054dSChao Yu return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); 2519acbf054dSChao Yu } 2520acbf054dSChao Yu 2521628b3d14SChao Yu static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, 2522628b3d14SChao Yu size_t size, gfp_t flags) 2523628b3d14SChao Yu { 2524628b3d14SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 2525628b3d14SChao Yu if (time_to_inject(sbi, FAULT_KVMALLOC)) { 2526628b3d14SChao Yu f2fs_show_injection_info(FAULT_KVMALLOC); 2527628b3d14SChao Yu return NULL; 2528628b3d14SChao Yu } 2529628b3d14SChao Yu #endif 2530628b3d14SChao Yu return kvmalloc(size, flags); 2531628b3d14SChao Yu } 2532628b3d14SChao Yu 2533628b3d14SChao Yu static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi, 2534628b3d14SChao Yu size_t size, gfp_t flags) 2535628b3d14SChao Yu { 2536628b3d14SChao Yu return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO); 2537628b3d14SChao Yu } 2538628b3d14SChao Yu 25397a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 2540f2470371SChao Yu { 25417a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 2542f2470371SChao Yu } 2543f2470371SChao Yu 25446afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode) 25456afc662eSChao Yu { 25466afc662eSChao Yu return F2FS_I(inode)->i_inline_xattr_size; 25476afc662eSChao Yu } 25486afc662eSChao Yu 2549a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \ 255091942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 2551a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 2552a6dda0e6SChristoph Hellwig 25537a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 25547a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 25557a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 25567a2af766SChao Yu 25575c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 25585c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 25595c57132eSChao Yu ((offsetof(typeof(*f2fs_inode), field) + \ 25605c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 25615c57132eSChao Yu <= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize)) \ 25625c57132eSChao Yu 2563b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 2564b0af6d49SChao Yu { 2565b0af6d49SChao Yu int i; 2566b0af6d49SChao Yu 2567b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2568b0af6d49SChao Yu for (i = 0; i < NR_IO_TYPE; i++) 2569b0af6d49SChao Yu sbi->write_iostat[i] = 0; 2570b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2571b0af6d49SChao Yu } 2572b0af6d49SChao Yu 2573b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 2574b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 2575b0af6d49SChao Yu { 2576b0af6d49SChao Yu if (!sbi->iostat_enable) 2577b0af6d49SChao Yu return; 2578b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2579b0af6d49SChao Yu sbi->write_iostat[type] += io_bytes; 2580b0af6d49SChao Yu 2581b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 2582b0af6d49SChao Yu sbi->write_iostat[APP_BUFFERED_IO] = 2583b0af6d49SChao Yu sbi->write_iostat[APP_WRITE_IO] - 2584b0af6d49SChao Yu sbi->write_iostat[APP_DIRECT_IO]; 2585b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2586b0af6d49SChao Yu } 2587b0af6d49SChao Yu 258839a53e0cSJaegeuk Kim /* 258939a53e0cSJaegeuk Kim * file.c 259039a53e0cSJaegeuk Kim */ 2591cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2592cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2593cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2594cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2595a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2596a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2597cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2598cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2599f652e9d9SChao Yu void truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2600c4020b2dSChao Yu int f2fs_precache_extents(struct inode *inode); 2601cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2602cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 26031ad71a27SJaegeuk Kim int f2fs_pin_file_control(struct inode *inode, bool inc); 260439a53e0cSJaegeuk Kim 260539a53e0cSJaegeuk Kim /* 260639a53e0cSJaegeuk Kim * inode.c 260739a53e0cSJaegeuk Kim */ 2608cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2609704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 2610704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 2611cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2612cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2613cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2614211a6fa0SYunlei He void update_inode(struct inode *inode, struct page *node_page); 2615211a6fa0SYunlei He void update_inode_page(struct inode *inode); 2616cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2617cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2618cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 261939a53e0cSJaegeuk Kim 262039a53e0cSJaegeuk Kim /* 262139a53e0cSJaegeuk Kim * namei.c 262239a53e0cSJaegeuk Kim */ 2623846ae671SChao Yu int update_extension_list(struct f2fs_sb_info *sbi, const char *name, 2624b6a06cbbSChao Yu bool hot, bool set); 262539a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 262639a53e0cSJaegeuk Kim 262739a53e0cSJaegeuk Kim /* 262839a53e0cSJaegeuk Kim * dir.c 262939a53e0cSJaegeuk Kim */ 2630cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2631cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2632cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2633cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2634cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2635cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2636cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2637cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2638cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2639cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2640cac5a3d8SDongOh Shin const struct qstr *new_name, 2641cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2642cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2643cac5a3d8SDongOh Shin unsigned int current_depth); 2644cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2645cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2646cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2647cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2648cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2649cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2650cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2651cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2652cac5a3d8SDongOh Shin struct page **page); 2653cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2654cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2655cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2656cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2657cac5a3d8SDongOh Shin unsigned int bit_pos); 2658cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2659cac5a3d8SDongOh Shin const struct qstr *orig_name, 2660cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2661cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2662cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2663cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2664cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2665cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2666cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2667cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2668cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 266939a53e0cSJaegeuk Kim 2670b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2671b7f7a5e0SAl Viro { 26722b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2673510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2674b7f7a5e0SAl Viro } 2675b7f7a5e0SAl Viro 267639a53e0cSJaegeuk Kim /* 267739a53e0cSJaegeuk Kim * super.c 267839a53e0cSJaegeuk Kim */ 2679cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2680cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2681ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); 26824b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 2683cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2684cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2685a07ef784SNamjae Jeon extern __printf(3, 4) 2686cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2687984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 268839a53e0cSJaegeuk Kim 268939a53e0cSJaegeuk Kim /* 269039a53e0cSJaegeuk Kim * hash.c 269139a53e0cSJaegeuk Kim */ 26926332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, 26936332cd32SJaegeuk Kim struct fscrypt_name *fname); 269439a53e0cSJaegeuk Kim 269539a53e0cSJaegeuk Kim /* 269639a53e0cSJaegeuk Kim * node.c 269739a53e0cSJaegeuk Kim */ 269839a53e0cSJaegeuk Kim struct dnode_of_data; 269939a53e0cSJaegeuk Kim struct node_info; 270039a53e0cSJaegeuk Kim 2701cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2702cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2703cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2704cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2705cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2706cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2707cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2708cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 27099c77f754SJaegeuk Kim int truncate_xattr_node(struct inode *inode); 2710cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2711cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2712cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 27135f4ce6abSYunlei He struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs); 2714cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2715cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2716cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2717cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2718cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2719cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2720401db79fSYunlong Song int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc, 2721b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 272222ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2723cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2724cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2725cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2726cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2727cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2728e17d488bSSheng Yong int recover_xattr_data(struct inode *inode, struct page *page); 2729cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2730c376fc0fSYunlei He void restore_node_summary(struct f2fs_sb_info *sbi, 2731cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 273222ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2733cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2734cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 27356e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 273639a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 273739a53e0cSJaegeuk Kim 273839a53e0cSJaegeuk Kim /* 273939a53e0cSJaegeuk Kim * segment.c 274039a53e0cSJaegeuk Kim */ 2741b3a97a2aSJaegeuk Kim bool need_SSR(struct f2fs_sb_info *sbi); 2742cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 274357864ae5SJaegeuk Kim void drop_inmem_pages_all(struct f2fs_sb_info *sbi); 2744cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 27458c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2746cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2747cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2748cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 274939d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 2750cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 27511228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); 2752cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2753cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2754cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 275578997b56SChao Yu void init_discard_policy(struct discard_policy *dpolicy, int discard_type, 275678997b56SChao Yu unsigned int granularity); 27577950e9acSChao Yu void drop_discard_cmd(struct f2fs_sb_info *sbi); 2758cce13252SChao Yu void stop_discard_thread(struct f2fs_sb_info *sbi); 2759cf5c759fSChao Yu bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2760cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2761cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2762cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2763cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2764cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2765cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2766cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2767cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2768b0af6d49SChao Yu void write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 2769b0af6d49SChao Yu enum iostat_type io_type); 2770cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2771cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2772d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2773cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2774cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2775cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2776cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2777cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2778cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2779cac5a3d8SDongOh Shin bool recover_newaddr); 2780cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2781cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2782fb830fc5SChao Yu struct f2fs_summary *sum, int type, 2783fb830fc5SChao Yu struct f2fs_io_info *fio, bool add_list); 2784cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2785cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2786d4c759eeSJaegeuk Kim void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr); 2787cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2788cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2789cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2790cac5a3d8SDongOh Shin unsigned int val, int alloc); 2791cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2792cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2793cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 27947fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 27957fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 2796d5097be5SHyunchul Lee int rw_hint_to_seg_type(enum rw_hint hint); 27970cdd3195SHyunchul Lee enum rw_hint io_type_to_rw_hint(struct f2fs_sb_info *sbi, enum page_type type, 27980cdd3195SHyunchul Lee enum temp_type temp); 279939a53e0cSJaegeuk Kim 280039a53e0cSJaegeuk Kim /* 280139a53e0cSJaegeuk Kim * checkpoint.c 280239a53e0cSJaegeuk Kim */ 2803cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2804cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2805cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2806cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2807cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2808cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2809cac5a3d8SDongOh Shin int type, bool sync); 2810cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2811cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2812b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 2813cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2814cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2815cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2816cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 281739d787beSChao Yu void set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 281839d787beSChao Yu unsigned int devidx, int type); 281939d787beSChao Yu bool is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 282039d787beSChao Yu unsigned int devidx, int type); 2821cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2822cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2823cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2824cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2825cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2826cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2827cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2828cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2829cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2830cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2831cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2832cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 28336e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 283439a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 283539a53e0cSJaegeuk Kim 283639a53e0cSJaegeuk Kim /* 283739a53e0cSJaegeuk Kim * data.c 283839a53e0cSJaegeuk Kim */ 2839b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 2840b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 2841942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2842b9109b0eSJaegeuk Kim enum page_type type); 2843b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 2844cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2845b9109b0eSJaegeuk Kim int f2fs_submit_page_write(struct f2fs_io_info *fio); 2846cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2847cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2848cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2849cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2850cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2851cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2852cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2853cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2854cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2855cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2856cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2857cac5a3d8SDongOh Shin int op_flags, bool for_write); 2858cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2859cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2860cac5a3d8SDongOh Shin bool for_write); 2861cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2862cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2863cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2864cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2865cac5a3d8SDongOh Shin int create, int flag); 2866cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2867cac5a3d8SDongOh Shin u64 start, u64 len); 2868bb9e3bb8SChao Yu bool should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); 2869bb9e3bb8SChao Yu bool should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); 2870cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2871b0af6d49SChao Yu int __f2fs_write_data_pages(struct address_space *mapping, 2872b0af6d49SChao Yu struct writeback_control *wbc, 2873b0af6d49SChao Yu enum iostat_type io_type); 2874cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2875cac5a3d8SDongOh Shin unsigned int length); 2876cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 28775b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2878cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2879cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 28805b7a487cSWeichao Guo #endif 2881b91050a8SHyunchul Lee bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len); 288239a53e0cSJaegeuk Kim 288339a53e0cSJaegeuk Kim /* 288439a53e0cSJaegeuk Kim * gc.c 288539a53e0cSJaegeuk Kim */ 2886cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2887cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2888cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2889e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 2890e066b83cSJaegeuk Kim unsigned int segno); 2891cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 289239a53e0cSJaegeuk Kim 289339a53e0cSJaegeuk Kim /* 289439a53e0cSJaegeuk Kim * recovery.c 289539a53e0cSJaegeuk Kim */ 2896cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2897cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 289839a53e0cSJaegeuk Kim 289939a53e0cSJaegeuk Kim /* 290039a53e0cSJaegeuk Kim * debug.c 290139a53e0cSJaegeuk Kim */ 290239a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 290339a53e0cSJaegeuk Kim struct f2fs_stat_info { 290439a53e0cSJaegeuk Kim struct list_head stat_list; 290539a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 290639a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 290739a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 29085b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 29095b7ee374SChao Yu unsigned long long hit_total, total_ext; 2910c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 29112c8a4a28SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; 29122c8a4a28SJaegeuk Kim int ndirty_data, ndirty_qdata; 291335782b23SJaegeuk Kim int inmem_pages; 29142c8a4a28SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; 29155b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 29165b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 291739a53e0cSJaegeuk Kim int total_count, utilization; 29188b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 291914d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 292014d8d5f7SChao Yu int nr_discarding, nr_discarded; 29215f32366aSChao Yu int nr_discard_cmd; 2922d84d1cbdSChao Yu unsigned int undiscard_blks; 2923a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2924648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2925f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 292639a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 292739a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 292839a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 292939a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 293042190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 293139a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2932e1235983SChangman Lee int bg_node_segs, bg_data_segs; 293339a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2934e1235983SChangman Lee int bg_data_blks, bg_node_blks; 293539a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 293639a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 293739a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 293839a53e0cSJaegeuk Kim 293939a53e0cSJaegeuk Kim unsigned int segment_count[2]; 294039a53e0cSJaegeuk Kim unsigned int block_count[2]; 2941b9a2c252SChangman Lee unsigned int inplace_count; 29429edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 294339a53e0cSJaegeuk Kim }; 294439a53e0cSJaegeuk Kim 2945963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2946963d4f7dSGu Zheng { 2947963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2948963d4f7dSGu Zheng } 2949963d4f7dSGu Zheng 2950942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 295142190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 295239a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2953dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 295433fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 295533fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 29565b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 29575b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 29585b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 29595b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2960d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2961d5e8f6c9SChao Yu do { \ 2962d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2963d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2964d5e8f6c9SChao Yu } while (0) 2965d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2966d5e8f6c9SChao Yu do { \ 2967d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2968d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2969d5e8f6c9SChao Yu } while (0) 29700dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 29710dbdc2aeSJaegeuk Kim do { \ 29720dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 297303e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 29740dbdc2aeSJaegeuk Kim } while (0) 29750dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 29760dbdc2aeSJaegeuk Kim do { \ 29770dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 297803e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 29790dbdc2aeSJaegeuk Kim } while (0) 29803289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 29813289c061SJaegeuk Kim do { \ 29823289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 298303e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 29843289c061SJaegeuk Kim } while (0) 29853289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 29863289c061SJaegeuk Kim do { \ 29873289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 298803e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 29893289c061SJaegeuk Kim } while (0) 2990dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2991dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2992dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2993dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2994b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2995b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 299626a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2997cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 299826a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2999cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 300026a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 300126a28a0cSJaegeuk Kim do { \ 300226a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 300326a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 300426a28a0cSJaegeuk Kim if (cur > max) \ 300526a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 300626a28a0cSJaegeuk Kim } while (0) 3007648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 3008648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 3009648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 3010648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 3011648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 3012648d50baSChao Yu do { \ 3013648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 3014648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 3015648d50baSChao Yu if (cur > max) \ 3016648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 3017648d50baSChao Yu } while (0) 3018e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 301939a53e0cSJaegeuk Kim do { \ 3020963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 302168afcf2dSTomohiro Kusumi si->tot_segs++; \ 302268afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 302339a53e0cSJaegeuk Kim si->data_segs++; \ 3024e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 3025e1235983SChangman Lee } else { \ 302639a53e0cSJaegeuk Kim si->node_segs++; \ 3027e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 3028e1235983SChangman Lee } \ 302939a53e0cSJaegeuk Kim } while (0) 303039a53e0cSJaegeuk Kim 303139a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 303268afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 303339a53e0cSJaegeuk Kim 3034e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 303539a53e0cSJaegeuk Kim do { \ 3036963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 303739a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 303839a53e0cSJaegeuk Kim si->data_blks += (blks); \ 303968afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 304039a53e0cSJaegeuk Kim } while (0) 304139a53e0cSJaegeuk Kim 3042e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 304339a53e0cSJaegeuk Kim do { \ 3044963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 304539a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 304639a53e0cSJaegeuk Kim si->node_blks += (blks); \ 304768afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 304839a53e0cSJaegeuk Kim } while (0) 304939a53e0cSJaegeuk Kim 3050cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 3051cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 3052787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 30534589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 305439a53e0cSJaegeuk Kim #else 3055d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 3056d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 3057d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 3058d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 3059d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 3060d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 3061d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 3062d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 3063d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 3064d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 3065d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 3066d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 3067d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 3068d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 3069d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 3070d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 3071d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 3072d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 3073d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 3074d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 3075d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 3076d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 3077d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 3078d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 3079d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 3080d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 3081d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 3082d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 3083d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 308439a53e0cSJaegeuk Kim 308539a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 308639a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 3087787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 30884589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 308939a53e0cSJaegeuk Kim #endif 309039a53e0cSJaegeuk Kim 309139a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 309239a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 309339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 309439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 309539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 309639a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 309739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 309839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 3099cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 310039a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 310129e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 31021001b347SHuajun Li 3103e18c65b2SHuajun Li /* 3104e18c65b2SHuajun Li * inline.c 3105e18c65b2SHuajun Li */ 3106cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 3107cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 3108cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 3109bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 3110cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 3111cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 3112cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 3113cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 3114cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 3115cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 3116cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 3117cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 3118cac5a3d8SDongOh Shin struct page *ipage); 3119cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 3120cac5a3d8SDongOh Shin const struct qstr *orig_name, 3121cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 3122cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 3123cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 3124cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 3125cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 3126cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 3127cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 3128cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 3129cac5a3d8SDongOh Shin __u64 start, __u64 len); 3130cde4de12SJaegeuk Kim 3131cde4de12SJaegeuk Kim /* 31322658e50dSJaegeuk Kim * shrinker.c 31332658e50dSJaegeuk Kim */ 3134cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 3135cac5a3d8SDongOh Shin struct shrink_control *sc); 3136cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 3137cac5a3d8SDongOh Shin struct shrink_control *sc); 3138cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 3139cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 31402658e50dSJaegeuk Kim 31412658e50dSJaegeuk Kim /* 3142a28ef1f5SChao Yu * extent_cache.c 3143a28ef1f5SChao Yu */ 3144004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 3145004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 3146004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 3147004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 3148004b6862SChao Yu unsigned int ofs); 3149004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 3150004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 3151004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 3152004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 3153004b6862SChao Yu bool force); 3154df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi, 3155df0f6b44SChao Yu struct rb_root *root); 3156cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 3157cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 3158cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 3159cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 3160cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 3161cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 3162cac5a3d8SDongOh Shin struct extent_info *ei); 3163cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 316419b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 3165cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 3166cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 3167a28ef1f5SChao Yu int __init create_extent_cache(void); 3168a28ef1f5SChao Yu void destroy_extent_cache(void); 3169a28ef1f5SChao Yu 3170a28ef1f5SChao Yu /* 31718ceffcb2SChao Yu * sysfs.c 31728ceffcb2SChao Yu */ 3173dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 3174dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 3175dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 3176dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 31778ceffcb2SChao Yu 31788ceffcb2SChao Yu /* 3179cde4de12SJaegeuk Kim * crypto support 3180cde4de12SJaegeuk Kim */ 31810b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 3182cde4de12SJaegeuk Kim { 3183cde4de12SJaegeuk Kim return file_is_encrypt(inode); 3184cde4de12SJaegeuk Kim } 3185cde4de12SJaegeuk Kim 31861958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 31871958593eSJaegeuk Kim { 31881958593eSJaegeuk Kim return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode); 31891958593eSJaegeuk Kim } 31901958593eSJaegeuk Kim 3191cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 3192cde4de12SJaegeuk Kim { 3193cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 3194cde4de12SJaegeuk Kim file_set_encrypt(inode); 31952ee6a576SEric Biggers inode->i_flags |= S_ENCRYPTED; 3196cde4de12SJaegeuk Kim #endif 3197cde4de12SJaegeuk Kim } 3198cde4de12SJaegeuk Kim 3199cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 3200cde4de12SJaegeuk Kim { 32010b81d077SJaegeuk Kim return bio->bi_private != NULL; 3202cde4de12SJaegeuk Kim } 3203cde4de12SJaegeuk Kim 3204ccd31cb2SSheng Yong #define F2FS_FEATURE_FUNCS(name, flagname) \ 3205ccd31cb2SSheng Yong static inline int f2fs_sb_has_##name(struct super_block *sb) \ 3206ccd31cb2SSheng Yong { \ 3207ccd31cb2SSheng Yong return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_##flagname); \ 3208cde4de12SJaegeuk Kim } 3209f424f664SJaegeuk Kim 3210ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(encrypt, ENCRYPT); 3211ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(blkzoned, BLKZONED); 3212ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR); 3213ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA); 3214ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM); 3215ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); 3216ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); 3217ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); 3218*b7c409deSSheng Yong F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); 32191c1d35dfSChao Yu 3220178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 3221178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 32223c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 3223178053e2SDamien Le Moal { 3224178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 32253c62be17SJaegeuk Kim int i; 3226178053e2SDamien Le Moal 32273c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 32283c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 32293c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 32303c62be17SJaegeuk Kim return -EINVAL; 3231178053e2SDamien Le Moal } 3232178053e2SDamien Le Moal #endif 3233178053e2SDamien Le Moal 323496ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 323596ba2decSDamien Le Moal { 323696ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 323796ba2decSDamien Le Moal 3238ccd31cb2SSheng Yong return blk_queue_discard(q) || f2fs_sb_has_blkzoned(sbi->sb); 323952763a4bSJaegeuk Kim } 324052763a4bSJaegeuk Kim 324152763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 324252763a4bSJaegeuk Kim { 324352763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 324452763a4bSJaegeuk Kim clear_opt(sbi, LFS); 324552763a4bSJaegeuk Kim 324652763a4bSJaegeuk Kim switch (mt) { 324752763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 324852763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 324952763a4bSJaegeuk Kim break; 325052763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 325152763a4bSJaegeuk Kim set_opt(sbi, LFS); 325252763a4bSJaegeuk Kim break; 325352763a4bSJaegeuk Kim } 325452763a4bSJaegeuk Kim } 325552763a4bSJaegeuk Kim 3256fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 3257fcc85a4dSJaegeuk Kim { 3258fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 3259886f56f9SAl Viro umode_t mode = inode->i_mode; 3260fcc85a4dSJaegeuk Kim 3261fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 3262fcc85a4dSJaegeuk Kim #else 3263fcc85a4dSJaegeuk Kim return 0; 3264fcc85a4dSJaegeuk Kim #endif 3265fcc85a4dSJaegeuk Kim } 3266fcc85a4dSJaegeuk Kim 3267b91050a8SHyunchul Lee static inline bool f2fs_force_buffered_io(struct inode *inode, int rw) 3268b91050a8SHyunchul Lee { 3269b91050a8SHyunchul Lee return (f2fs_encrypted_file(inode) || 3270b91050a8SHyunchul Lee (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) || 3271b91050a8SHyunchul Lee F2FS_I_SB(inode)->s_ndevs); 3272b91050a8SHyunchul Lee } 3273b91050a8SHyunchul Lee 327439a53e0cSJaegeuk Kim #endif 3275