Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 1 | /* |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2 | * fs/f2fs/f2fs.h |
| 3 | * |
| 4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. |
| 5 | * http://www.samsung.com/ |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | #ifndef _LINUX_F2FS_H |
| 12 | #define _LINUX_F2FS_H |
| 13 | |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/page-flags.h> |
| 16 | #include <linux/buffer_head.h> |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
| 18 | #include <linux/crc32.h> |
| 19 | #include <linux/magic.h> |
Jaegeuk Kim | c2d715d | 2013-08-08 15:56:49 +0900 | [diff] [blame] | 20 | #include <linux/kobject.h> |
Gu Zheng | 7bd5938 | 2013-10-22 14:52:26 +0800 | [diff] [blame] | 21 | #include <linux/sched.h> |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 22 | #include <linux/writeback.h> |
Jaegeuk Kim | 462d762 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 23 | #include <linux/cred.h> |
Jaegeuk Kim | 39307a8 | 2015-09-22 13:50:47 -0700 | [diff] [blame] | 24 | #include <linux/vmalloc.h> |
Jaegeuk Kim | 740432f | 2015-08-14 11:43:56 -0700 | [diff] [blame] | 25 | #include <linux/bio.h> |
Jaegeuk Kim | d0239e1 | 2016-01-08 16:57:48 -0800 | [diff] [blame] | 26 | #include <linux/blkdev.h> |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 27 | #include <linux/quotaops.h> |
Keith Mok | 43b6573 | 2016-03-02 12:04:24 -0800 | [diff] [blame] | 28 | #include <crypto/hash.h> |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 29 | |
Dave Chinner | 1617929 | 2017-10-09 12:15:34 -0700 | [diff] [blame] | 30 | #define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_F2FS_FS_ENCRYPTION) |
| 31 | #include <linux/fscrypt.h> |
| 32 | |
Jaegeuk Kim | 5d56b67 | 2013-10-29 15:14:54 +0900 | [diff] [blame] | 33 | #ifdef CONFIG_F2FS_CHECK_FS |
Jaegeuk Kim | 9850cf4 | 2014-09-02 15:52:58 -0700 | [diff] [blame] | 34 | #define f2fs_bug_on(sbi, condition) BUG_ON(condition) |
Jaegeuk Kim | 5d56b67 | 2013-10-29 15:14:54 +0900 | [diff] [blame] | 35 | #else |
Jaegeuk Kim | 9850cf4 | 2014-09-02 15:52:58 -0700 | [diff] [blame] | 36 | #define f2fs_bug_on(sbi, condition) \ |
| 37 | do { \ |
| 38 | if (unlikely(condition)) { \ |
| 39 | WARN_ON(1); \ |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 40 | set_sbi_flag(sbi, SBI_NEED_FSCK); \ |
Jaegeuk Kim | 9850cf4 | 2014-09-02 15:52:58 -0700 | [diff] [blame] | 41 | } \ |
| 42 | } while (0) |
Jaegeuk Kim | 5d56b67 | 2013-10-29 15:14:54 +0900 | [diff] [blame] | 43 | #endif |
| 44 | |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 45 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 46 | enum { |
| 47 | FAULT_KMALLOC, |
Chao Yu | ead5259 | 2017-11-30 19:28:18 +0800 | [diff] [blame] | 48 | FAULT_KVMALLOC, |
Jaegeuk Kim | c41f3cc3 | 2016-04-29 16:17:09 -0700 | [diff] [blame] | 49 | FAULT_PAGE_ALLOC, |
Chao Yu | 58ddec8 | 2017-10-28 16:52:30 +0800 | [diff] [blame] | 50 | FAULT_PAGE_GET, |
Chao Yu | b5db2de | 2017-10-28 16:52:31 +0800 | [diff] [blame] | 51 | FAULT_ALLOC_BIO, |
Jaegeuk Kim | cb78942 | 2016-04-29 16:29:22 -0700 | [diff] [blame] | 52 | FAULT_ALLOC_NID, |
| 53 | FAULT_ORPHAN, |
| 54 | FAULT_BLOCK, |
| 55 | FAULT_DIR_DEPTH, |
Jaegeuk Kim | 53aa6bb | 2016-05-25 15:24:18 -0700 | [diff] [blame] | 56 | FAULT_EVICT_INODE, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 57 | FAULT_TRUNCATE, |
Chao Yu | 8b038c7 | 2016-09-18 23:30:07 +0800 | [diff] [blame] | 58 | FAULT_IO, |
Chao Yu | 0f34802 | 2016-09-26 19:45:55 +0800 | [diff] [blame] | 59 | FAULT_CHECKPOINT, |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 60 | FAULT_MAX, |
| 61 | }; |
| 62 | |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 63 | struct f2fs_fault_info { |
| 64 | atomic_t inject_ops; |
| 65 | unsigned int inject_rate; |
| 66 | unsigned int inject_type; |
| 67 | }; |
| 68 | |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 69 | extern char *fault_name[FAULT_MAX]; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 70 | #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 71 | #endif |
| 72 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 73 | /* |
| 74 | * For mount options |
| 75 | */ |
| 76 | #define F2FS_MOUNT_BG_GC 0x00000001 |
| 77 | #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 |
| 78 | #define F2FS_MOUNT_DISCARD 0x00000004 |
| 79 | #define F2FS_MOUNT_NOHEAP 0x00000008 |
| 80 | #define F2FS_MOUNT_XATTR_USER 0x00000010 |
| 81 | #define F2FS_MOUNT_POSIX_ACL 0x00000020 |
| 82 | #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 83 | #define F2FS_MOUNT_INLINE_XATTR 0x00000080 |
Huajun Li | 1001b34 | 2013-11-10 23:13:16 +0800 | [diff] [blame] | 84 | #define F2FS_MOUNT_INLINE_DATA 0x00000100 |
Chao Yu | 34d67de | 2014-09-24 18:15:19 +0800 | [diff] [blame] | 85 | #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 |
| 86 | #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 |
| 87 | #define F2FS_MOUNT_NOBARRIER 0x00000800 |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 88 | #define F2FS_MOUNT_FASTBOOT 0x00001000 |
Chao Yu | 8967215 | 2015-02-05 17:55:51 +0800 | [diff] [blame] | 89 | #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 |
Jaegeuk Kim | 6aefd93 | 2015-10-05 11:02:54 -0700 | [diff] [blame] | 90 | #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 |
Chao Yu | 343f40f | 2015-12-16 13:12:16 +0800 | [diff] [blame] | 91 | #define F2FS_MOUNT_DATA_FLUSH 0x00008000 |
Jaegeuk Kim | 73faec4 | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 92 | #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 93 | #define F2FS_MOUNT_ADAPTIVE 0x00020000 |
| 94 | #define F2FS_MOUNT_LFS 0x00040000 |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 95 | #define F2FS_MOUNT_USRQUOTA 0x00080000 |
| 96 | #define F2FS_MOUNT_GRPQUOTA 0x00100000 |
Chao Yu | 5647b30 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 97 | #define F2FS_MOUNT_PRJQUOTA 0x00200000 |
Chao Yu | 41ad73f | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 98 | #define F2FS_MOUNT_QUOTA 0x00400000 |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 99 | #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 |
Jaegeuk Kim | 5fee540 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 100 | #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 101 | |
Chao Yu | e9a50e6 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 102 | #define F2FS_OPTION(sbi) ((sbi)->mount_opt) |
| 103 | #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) |
| 104 | #define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option) |
| 105 | #define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 106 | |
| 107 | #define ver_after(a, b) (typecheck(unsigned long long, a) && \ |
| 108 | typecheck(unsigned long long, b) && \ |
| 109 | ((long long)((a) - (b)) > 0)) |
| 110 | |
Jaegeuk Kim | a9841c4 | 2013-05-24 12:41:04 +0900 | [diff] [blame] | 111 | typedef u32 block_t; /* |
| 112 | * should not change u32, since it is the on-disk block |
| 113 | * address format, __le32. |
| 114 | */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 115 | typedef u32 nid_t; |
| 116 | |
| 117 | struct f2fs_mount_info { |
Chao Yu | e9a50e6 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 118 | unsigned int opt; |
| 119 | int write_io_size_bits; /* Write IO size bits */ |
| 120 | block_t root_reserved_blocks; /* root reserved blocks */ |
| 121 | kuid_t s_resuid; /* reserved blocks for uid */ |
| 122 | kgid_t s_resgid; /* reserved blocks for gid */ |
| 123 | int active_logs; /* # of active logs */ |
| 124 | int inline_xattr_size; /* inline xattr size */ |
| 125 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 126 | struct f2fs_fault_info fault_info; /* For fault injection */ |
| 127 | #endif |
| 128 | #ifdef CONFIG_QUOTA |
| 129 | /* Names of quota files with journalled quota */ |
| 130 | char *s_qf_names[MAXQUOTAS]; |
| 131 | int s_jquota_fmt; /* Format of quota to use */ |
| 132 | #endif |
| 133 | /* For which write hints are passed down to block layer */ |
| 134 | int whint_mode; |
| 135 | int alloc_mode; /* segment allocation policy */ |
| 136 | int fsync_mode; /* fsync policy */ |
Sheng Yong | aa5bcfd | 2018-03-15 18:51:42 +0800 | [diff] [blame] | 137 | bool test_dummy_encryption; /* test dummy encryption */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 138 | }; |
| 139 | |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 140 | #define F2FS_FEATURE_ENCRYPT 0x0001 |
| 141 | #define F2FS_FEATURE_BLKZONED 0x0002 |
| 142 | #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 |
| 143 | #define F2FS_FEATURE_EXTRA_ATTR 0x0008 |
Chao Yu | 5647b30 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 144 | #define F2FS_FEATURE_PRJQUOTA 0x0010 |
Chao Yu | 4310125 | 2017-07-31 20:19:09 +0800 | [diff] [blame] | 145 | #define F2FS_FEATURE_INODE_CHKSUM 0x0020 |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 146 | #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 |
Jaegeuk Kim | d4c292d | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 147 | #define F2FS_FEATURE_QUOTA_INO 0x0080 |
Chao Yu | 71f8f04 | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 148 | #define F2FS_FEATURE_INODE_CRTIME 0x0100 |
Sheng Yong | 9b880fe | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 149 | #define F2FS_FEATURE_LOST_FOUND 0x0200 |
Eric Biggers | 29cead5 | 2018-03-28 11:15:09 -0700 | [diff] [blame] | 150 | #define F2FS_FEATURE_VERITY 0x0400 /* reserved */ |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 151 | |
Jaegeuk Kim | 76f105a | 2015-04-13 15:10:36 -0700 | [diff] [blame] | 152 | #define F2FS_HAS_FEATURE(sb, mask) \ |
| 153 | ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) |
| 154 | #define F2FS_SET_FEATURE(sb, mask) \ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 155 | (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) |
Jaegeuk Kim | 76f105a | 2015-04-13 15:10:36 -0700 | [diff] [blame] | 156 | #define F2FS_CLEAR_FEATURE(sb, mask) \ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 157 | (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) |
Jaegeuk Kim | 76f105a | 2015-04-13 15:10:36 -0700 | [diff] [blame] | 158 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 159 | /* |
Jaegeuk Kim | 462d762 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 160 | * Default values for user and/or group using reserved blocks |
| 161 | */ |
| 162 | #define F2FS_DEF_RESUID 0 |
| 163 | #define F2FS_DEF_RESGID 0 |
| 164 | |
| 165 | /* |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 166 | * For checkpoint manager |
| 167 | */ |
| 168 | enum { |
| 169 | NAT_BITMAP, |
| 170 | SIT_BITMAP |
| 171 | }; |
| 172 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 173 | #define CP_UMOUNT 0x00000001 |
| 174 | #define CP_FASTBOOT 0x00000002 |
| 175 | #define CP_SYNC 0x00000004 |
| 176 | #define CP_RECOVERY 0x00000008 |
| 177 | #define CP_DISCARD 0x00000010 |
| 178 | #define CP_TRIMMED 0x00000020 |
Jaegeuk Kim | 75ab4cb | 2014-09-20 21:57:51 -0700 | [diff] [blame] | 179 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 180 | #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) |
Chao Yu | 69a5967 | 2017-10-04 09:08:33 +0800 | [diff] [blame] | 181 | #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ |
Jaegeuk Kim | 8f6a2e7 | 2018-05-24 13:57:26 -0700 | [diff] [blame] | 182 | #define DEF_MAX_DISCARD_LEN 512 /* Max. 2MB per discard */ |
Chao Yu | efe24da | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 183 | #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ |
Yunlei He | 8d74ddc | 2018-04-08 15:11:11 +0800 | [diff] [blame] | 184 | #define DEF_MID_DISCARD_ISSUE_TIME 500 /* 500 ms, if device busy */ |
Chao Yu | efe24da | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 185 | #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ |
Jaegeuk Kim | 4105909 | 2018-05-29 09:58:42 -0700 | [diff] [blame] | 186 | #define DEF_DISCARD_URGENT_UTIL 80 /* do more discard over 80% */ |
Jaegeuk Kim | 60b99b4 | 2015-10-05 14:49:57 -0700 | [diff] [blame] | 187 | #define DEF_CP_INTERVAL 60 /* 60 secs */ |
Chao Yu | dcf25fe | 2016-07-15 19:25:47 +0800 | [diff] [blame] | 188 | #define DEF_IDLE_INTERVAL 5 /* 5 secs */ |
Jaegeuk Kim | bba681c | 2015-01-26 17:41:23 -0800 | [diff] [blame] | 189 | |
Jaegeuk Kim | 75ab4cb | 2014-09-20 21:57:51 -0700 | [diff] [blame] | 190 | struct cp_control { |
| 191 | int reason; |
Jaegeuk Kim | 4b2fecc | 2014-09-20 22:06:39 -0700 | [diff] [blame] | 192 | __u64 trim_start; |
| 193 | __u64 trim_end; |
| 194 | __u64 trim_minlen; |
Jaegeuk Kim | 75ab4cb | 2014-09-20 21:57:51 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
Chao Yu | 662befd | 2014-02-07 16:11:53 +0800 | [diff] [blame] | 197 | /* |
Chao Yu | 81c1a0f1 | 2014-02-27 19:12:24 +0800 | [diff] [blame] | 198 | * For CP/NAT/SIT/SSA readahead |
Chao Yu | 662befd | 2014-02-07 16:11:53 +0800 | [diff] [blame] | 199 | */ |
| 200 | enum { |
| 201 | META_CP, |
| 202 | META_NAT, |
Chao Yu | 81c1a0f1 | 2014-02-27 19:12:24 +0800 | [diff] [blame] | 203 | META_SIT, |
Jaegeuk Kim | 4c521f49 | 2014-09-11 13:49:55 -0700 | [diff] [blame] | 204 | META_SSA, |
| 205 | META_POR, |
Chao Yu | 662befd | 2014-02-07 16:11:53 +0800 | [diff] [blame] | 206 | }; |
| 207 | |
Jaegeuk Kim | 6451e04 | 2014-07-25 15:47:17 -0700 | [diff] [blame] | 208 | /* for the list of ino */ |
| 209 | enum { |
| 210 | ORPHAN_INO, /* for orphan ino list */ |
Jaegeuk Kim | fff04f9 | 2014-07-25 07:40:59 -0700 | [diff] [blame] | 211 | APPEND_INO, /* for append ino list */ |
| 212 | UPDATE_INO, /* for update ino list */ |
Jaegeuk Kim | 211cb7b | 2017-12-28 08:09:44 -0800 | [diff] [blame] | 213 | TRANS_DIR_INO, /* for trasactions dir ino list */ |
Chao Yu | f014be8 | 2017-09-29 13:59:38 +0800 | [diff] [blame] | 214 | FLUSH_INO, /* for multiple device flushing */ |
Jaegeuk Kim | 6451e04 | 2014-07-25 15:47:17 -0700 | [diff] [blame] | 215 | MAX_INO_ENTRY, /* max. list */ |
| 216 | }; |
| 217 | |
| 218 | struct ino_entry { |
Chao Yu | f014be8 | 2017-09-29 13:59:38 +0800 | [diff] [blame] | 219 | struct list_head list; /* list head */ |
| 220 | nid_t ino; /* inode number */ |
| 221 | unsigned int dirty_device; /* dirty device bitmap */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 222 | }; |
| 223 | |
Chao Yu | 2710fd7 | 2015-12-15 13:30:45 +0800 | [diff] [blame] | 224 | /* for the list of inodes to be GCed */ |
Chao Yu | 0629207 | 2014-12-29 15:56:18 +0800 | [diff] [blame] | 225 | struct inode_entry { |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 226 | struct list_head list; /* list head */ |
| 227 | struct inode *inode; /* vfs inode pointer */ |
| 228 | }; |
| 229 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 230 | /* for the bitmap indicate blocks to be discarded */ |
Jaegeuk Kim | 7fd9e54 | 2013-11-15 13:55:58 +0900 | [diff] [blame] | 231 | struct discard_entry { |
| 232 | struct list_head list; /* list head */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 233 | block_t start_blkaddr; /* start blockaddr of current segment */ |
| 234 | unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ |
Jaegeuk Kim | 7fd9e54 | 2013-11-15 13:55:58 +0900 | [diff] [blame] | 235 | }; |
| 236 | |
Chao Yu | efe24da | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 237 | /* default discard granularity of inner discard thread, unit: block count */ |
| 238 | #define DEFAULT_DISCARD_GRANULARITY 16 |
| 239 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 240 | /* max discard pend list number */ |
| 241 | #define MAX_PLIST_NUM 512 |
| 242 | #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ |
| 243 | (MAX_PLIST_NUM - 1) : (blk_num - 1)) |
| 244 | |
| 245 | enum { |
| 246 | D_PREP, |
| 247 | D_SUBMIT, |
| 248 | D_DONE, |
| 249 | }; |
| 250 | |
| 251 | struct discard_info { |
| 252 | block_t lstart; /* logical start address */ |
| 253 | block_t len; /* length */ |
| 254 | block_t start; /* actual start address in dev */ |
| 255 | }; |
| 256 | |
| 257 | struct discard_cmd { |
| 258 | struct rb_node rb_node; /* rb node located in rb-tree */ |
| 259 | union { |
| 260 | struct { |
| 261 | block_t lstart; /* logical start address */ |
| 262 | block_t len; /* length */ |
| 263 | block_t start; /* actual start address in dev */ |
| 264 | }; |
| 265 | struct discard_info di; /* discard info */ |
| 266 | |
| 267 | }; |
| 268 | struct list_head list; /* command list */ |
| 269 | struct completion wait; /* compleation */ |
| 270 | struct block_device *bdev; /* bdev */ |
| 271 | unsigned short ref; /* reference count */ |
| 272 | unsigned char state; /* state */ |
| 273 | int error; /* bio error */ |
| 274 | }; |
| 275 | |
Chao Yu | daf437d | 2017-10-04 09:08:34 +0800 | [diff] [blame] | 276 | enum { |
| 277 | DPOLICY_BG, |
| 278 | DPOLICY_FORCE, |
| 279 | DPOLICY_FSTRIM, |
| 280 | DPOLICY_UMOUNT, |
| 281 | MAX_DPOLICY, |
| 282 | }; |
| 283 | |
Chao Yu | 69a5967 | 2017-10-04 09:08:33 +0800 | [diff] [blame] | 284 | struct discard_policy { |
Chao Yu | daf437d | 2017-10-04 09:08:34 +0800 | [diff] [blame] | 285 | int type; /* type of discard */ |
Chao Yu | 69a5967 | 2017-10-04 09:08:33 +0800 | [diff] [blame] | 286 | unsigned int min_interval; /* used for candidates exist */ |
Yunlei He | 8d74ddc | 2018-04-08 15:11:11 +0800 | [diff] [blame] | 287 | unsigned int mid_interval; /* used for device busy */ |
Chao Yu | 69a5967 | 2017-10-04 09:08:33 +0800 | [diff] [blame] | 288 | unsigned int max_interval; /* used for candidates not exist */ |
| 289 | unsigned int max_requests; /* # of discards issued per round */ |
| 290 | unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ |
| 291 | bool io_aware; /* issue discard in idle time */ |
| 292 | bool sync; /* submit discard with REQ_SYNC flag */ |
Chao Yu | daf437d | 2017-10-04 09:08:34 +0800 | [diff] [blame] | 293 | unsigned int granularity; /* discard granularity */ |
Chao Yu | 69a5967 | 2017-10-04 09:08:33 +0800 | [diff] [blame] | 294 | }; |
| 295 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 296 | struct discard_cmd_control { |
| 297 | struct task_struct *f2fs_issue_discard; /* discard thread */ |
| 298 | struct list_head entry_list; /* 4KB discard entry list */ |
| 299 | struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ |
| 300 | struct list_head wait_list; /* store on-flushing entries */ |
Chao Yu | 28e1023 | 2017-10-04 09:08:32 +0800 | [diff] [blame] | 301 | struct list_head fstrim_list; /* in-flight discard from fstrim */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 302 | wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ |
Chao Yu | efe24da | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 303 | unsigned int discard_wake; /* to wake up discard thread */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 304 | struct mutex cmd_lock; |
| 305 | unsigned int nr_discards; /* # of discards in the list */ |
| 306 | unsigned int max_discards; /* max. discards to be issued */ |
Chao Yu | efe24da | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 307 | unsigned int discard_granularity; /* discard granularity */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 308 | unsigned int undiscard_blks; /* # of undiscard blocks */ |
| 309 | atomic_t issued_discard; /* # of issued discard */ |
| 310 | atomic_t issing_discard; /* # of issing discard */ |
| 311 | atomic_t discard_cmd_cnt; /* # of cached cmd count */ |
| 312 | struct rb_root root; /* root of discard rb-tree */ |
Chao Yu | 275b66b | 2016-08-29 23:58:34 +0800 | [diff] [blame] | 313 | }; |
| 314 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 315 | /* for the list of fsync inodes, used only during recovery */ |
| 316 | struct fsync_inode_entry { |
| 317 | struct list_head list; /* list head */ |
| 318 | struct inode *inode; /* vfs inode pointer */ |
Jaegeuk Kim | c52e1b1 | 2014-09-11 14:29:06 -0700 | [diff] [blame] | 319 | block_t blkaddr; /* block address locating the last fsync */ |
| 320 | block_t last_dentry; /* block address locating the last dentry */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 321 | }; |
| 322 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 323 | #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) |
| 324 | #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 325 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 326 | #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) |
| 327 | #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) |
| 328 | #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) |
| 329 | #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 330 | |
Chao Yu | dfc08a1 | 2016-02-14 18:50:40 +0800 | [diff] [blame] | 331 | #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) |
| 332 | #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) |
Jaegeuk Kim | 309cc2b | 2014-09-22 11:40:48 -0700 | [diff] [blame] | 333 | |
Chao Yu | dfc08a1 | 2016-02-14 18:50:40 +0800 | [diff] [blame] | 334 | static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 335 | { |
Chao Yu | dfc08a1 | 2016-02-14 18:50:40 +0800 | [diff] [blame] | 336 | int before = nats_in_cursum(journal); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 337 | |
Chao Yu | dfc08a1 | 2016-02-14 18:50:40 +0800 | [diff] [blame] | 338 | journal->n_nats = cpu_to_le16(before + i); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 339 | return before; |
| 340 | } |
| 341 | |
Chao Yu | dfc08a1 | 2016-02-14 18:50:40 +0800 | [diff] [blame] | 342 | static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 343 | { |
Chao Yu | dfc08a1 | 2016-02-14 18:50:40 +0800 | [diff] [blame] | 344 | int before = sits_in_cursum(journal); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 345 | |
Chao Yu | dfc08a1 | 2016-02-14 18:50:40 +0800 | [diff] [blame] | 346 | journal->n_sits = cpu_to_le16(before + i); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 347 | return before; |
| 348 | } |
| 349 | |
Chao Yu | dfc08a1 | 2016-02-14 18:50:40 +0800 | [diff] [blame] | 350 | static inline bool __has_cursum_space(struct f2fs_journal *journal, |
| 351 | int size, int type) |
Chao Yu | 184a5cd | 2014-09-04 18:13:01 +0800 | [diff] [blame] | 352 | { |
| 353 | if (type == NAT_JOURNAL) |
Chao Yu | dfc08a1 | 2016-02-14 18:50:40 +0800 | [diff] [blame] | 354 | return size <= MAX_NAT_JENTRIES(journal); |
| 355 | return size <= MAX_SIT_JENTRIES(journal); |
Chao Yu | 184a5cd | 2014-09-04 18:13:01 +0800 | [diff] [blame] | 356 | } |
| 357 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 358 | /* |
Namjae Jeon | e975082 | 2013-02-04 23:41:41 +0900 | [diff] [blame] | 359 | * ioctl commands |
| 360 | */ |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 361 | #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS |
| 362 | #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS |
Chao Yu | d49f3e8 | 2015-01-23 20:36:04 +0800 | [diff] [blame] | 363 | #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 364 | |
| 365 | #define F2FS_IOCTL_MAGIC 0xf5 |
| 366 | #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) |
| 367 | #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) |
Jaegeuk Kim | 02a1335 | 2014-10-06 16:11:16 -0700 | [diff] [blame] | 368 | #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 369 | #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) |
| 370 | #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 371 | #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32) |
Chao Yu | 456b88e | 2015-10-05 22:24:19 +0800 | [diff] [blame] | 372 | #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 373 | #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \ |
| 374 | struct f2fs_defragment) |
Jaegeuk Kim | 4dd6f97 | 2016-07-08 15:16:47 -0700 | [diff] [blame] | 375 | #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ |
| 376 | struct f2fs_move_range) |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 377 | #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ |
| 378 | struct f2fs_flush_device) |
Jaegeuk Kim | 0bb5306 | 2017-06-15 16:44:42 -0700 | [diff] [blame] | 379 | #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ |
| 380 | struct f2fs_gc_range) |
Jaegeuk Kim | 82925bb | 2017-07-21 12:58:59 -0700 | [diff] [blame] | 381 | #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 382 | #define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32) |
| 383 | #define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32) |
Chao Yu | 6bce963 | 2018-01-11 14:42:30 +0800 | [diff] [blame] | 384 | #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) |
Namjae Jeon | e975082 | 2013-02-04 23:41:41 +0900 | [diff] [blame] | 385 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 386 | #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY |
| 387 | #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY |
| 388 | #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT |
Jaegeuk Kim | f424f66 | 2015-04-20 15:19:06 -0700 | [diff] [blame] | 389 | |
Jaegeuk Kim | 1abff93 | 2015-01-08 19:15:53 -0800 | [diff] [blame] | 390 | /* |
| 391 | * should be same as XFS_IOC_GOINGDOWN. |
| 392 | * Flags for going down operation used by FS_IOC_GOINGDOWN |
| 393 | */ |
| 394 | #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ |
| 395 | #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ |
| 396 | #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ |
| 397 | #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ |
Jaegeuk Kim | c912a82 | 2015-10-07 09:46:37 -0700 | [diff] [blame] | 398 | #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ |
Jaegeuk Kim | 1abff93 | 2015-01-08 19:15:53 -0800 | [diff] [blame] | 399 | |
Namjae Jeon | e975082 | 2013-02-04 23:41:41 +0900 | [diff] [blame] | 400 | #if defined(__KERNEL__) && defined(CONFIG_COMPAT) |
| 401 | /* |
| 402 | * ioctl commands in 32 bit emulation |
| 403 | */ |
Chao Yu | 04ef4b6 | 2015-11-10 18:44:20 +0800 | [diff] [blame] | 404 | #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS |
| 405 | #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS |
| 406 | #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION |
Namjae Jeon | e975082 | 2013-02-04 23:41:41 +0900 | [diff] [blame] | 407 | #endif |
| 408 | |
Jaegeuk Kim | 0bb5306 | 2017-06-15 16:44:42 -0700 | [diff] [blame] | 409 | struct f2fs_gc_range { |
| 410 | u32 sync; |
| 411 | u64 start; |
| 412 | u64 len; |
| 413 | }; |
| 414 | |
Chao Yu | d323d00 | 2015-10-27 09:53:45 +0800 | [diff] [blame] | 415 | struct f2fs_defragment { |
| 416 | u64 start; |
| 417 | u64 len; |
| 418 | }; |
| 419 | |
Jaegeuk Kim | 4dd6f97 | 2016-07-08 15:16:47 -0700 | [diff] [blame] | 420 | struct f2fs_move_range { |
| 421 | u32 dst_fd; /* destination fd */ |
| 422 | u64 pos_in; /* start position in src_fd */ |
| 423 | u64 pos_out; /* start position in dst_fd */ |
| 424 | u64 len; /* size to move */ |
| 425 | }; |
| 426 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 427 | struct f2fs_flush_device { |
| 428 | u32 dev_num; /* device number to flush */ |
| 429 | u32 segments; /* # of segments to flush */ |
| 430 | }; |
| 431 | |
Chao Yu | e84f88e | 2017-07-19 00:19:05 +0800 | [diff] [blame] | 432 | /* for inline stuff */ |
| 433 | #define DEF_INLINE_RESERVED_SIZE 1 |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 434 | #define DEF_MIN_INLINE_SIZE 1 |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 435 | static inline int get_extra_isize(struct inode *inode); |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 436 | static inline int get_inline_xattr_addrs(struct inode *inode); |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 437 | #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ |
| 438 | (CUR_ADDRS_PER_INODE(inode) - \ |
Chao Yu | 3aa46e2 | 2018-01-17 16:31:36 +0800 | [diff] [blame] | 439 | get_inline_xattr_addrs(inode) - \ |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 440 | DEF_INLINE_RESERVED_SIZE)) |
Chao Yu | e84f88e | 2017-07-19 00:19:05 +0800 | [diff] [blame] | 441 | |
| 442 | /* for inline dir */ |
| 443 | #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ |
| 444 | ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ |
| 445 | BITS_PER_BYTE + 1)) |
| 446 | #define INLINE_DENTRY_BITMAP_SIZE(inode) ((NR_INLINE_DENTRY(inode) + \ |
| 447 | BITS_PER_BYTE - 1) / BITS_PER_BYTE) |
| 448 | #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ |
| 449 | ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ |
| 450 | NR_INLINE_DENTRY(inode) + \ |
| 451 | INLINE_DENTRY_BITMAP_SIZE(inode))) |
| 452 | |
Namjae Jeon | e975082 | 2013-02-04 23:41:41 +0900 | [diff] [blame] | 453 | /* |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 454 | * For INODE and NODE manager |
| 455 | */ |
Jaegeuk Kim | 7b3cd7d | 2014-10-18 22:52:52 -0700 | [diff] [blame] | 456 | /* for directory operations */ |
| 457 | struct f2fs_dentry_ptr { |
Jaegeuk Kim | d8c6822 | 2015-04-27 16:26:24 -0700 | [diff] [blame] | 458 | struct inode *inode; |
Chao Yu | b75c5f6 | 2017-07-16 15:08:54 +0800 | [diff] [blame] | 459 | void *bitmap; |
Jaegeuk Kim | 7b3cd7d | 2014-10-18 22:52:52 -0700 | [diff] [blame] | 460 | struct f2fs_dir_entry *dentry; |
| 461 | __u8 (*filename)[F2FS_SLOT_LEN]; |
| 462 | int max; |
Chao Yu | b75c5f6 | 2017-07-16 15:08:54 +0800 | [diff] [blame] | 463 | int nr_bitmap; |
Jaegeuk Kim | 7b3cd7d | 2014-10-18 22:52:52 -0700 | [diff] [blame] | 464 | }; |
| 465 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 466 | static inline void make_dentry_ptr_block(struct inode *inode, |
| 467 | struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) |
Jaegeuk Kim | 7b3cd7d | 2014-10-18 22:52:52 -0700 | [diff] [blame] | 468 | { |
Jaegeuk Kim | d8c6822 | 2015-04-27 16:26:24 -0700 | [diff] [blame] | 469 | d->inode = inode; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 470 | d->max = NR_DENTRY_IN_BLOCK; |
Chao Yu | b75c5f6 | 2017-07-16 15:08:54 +0800 | [diff] [blame] | 471 | d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; |
Yunlong Song | 270deeb | 2018-04-02 20:22:20 +0800 | [diff] [blame] | 472 | d->bitmap = t->dentry_bitmap; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 473 | d->dentry = t->dentry; |
| 474 | d->filename = t->filename; |
| 475 | } |
Jaegeuk Kim | d8c6822 | 2015-04-27 16:26:24 -0700 | [diff] [blame] | 476 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 477 | static inline void make_dentry_ptr_inline(struct inode *inode, |
Chao Yu | e84f88e | 2017-07-19 00:19:05 +0800 | [diff] [blame] | 478 | struct f2fs_dentry_ptr *d, void *t) |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 479 | { |
Chao Yu | e84f88e | 2017-07-19 00:19:05 +0800 | [diff] [blame] | 480 | int entry_cnt = NR_INLINE_DENTRY(inode); |
| 481 | int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); |
| 482 | int reserved_size = INLINE_RESERVED_SIZE(inode); |
| 483 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 484 | d->inode = inode; |
Chao Yu | e84f88e | 2017-07-19 00:19:05 +0800 | [diff] [blame] | 485 | d->max = entry_cnt; |
| 486 | d->nr_bitmap = bitmap_size; |
| 487 | d->bitmap = t; |
| 488 | d->dentry = t + bitmap_size + reserved_size; |
| 489 | d->filename = t + bitmap_size + reserved_size + |
| 490 | SIZE_OF_DIR_ENTRY * entry_cnt; |
Jaegeuk Kim | 7b3cd7d | 2014-10-18 22:52:52 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Jaegeuk Kim | dbe6a5f | 2013-08-09 08:14:06 +0900 | [diff] [blame] | 493 | /* |
| 494 | * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 |
| 495 | * as its node offset to distinguish from index node blocks. |
| 496 | * But some bits are used to mark the node block. |
| 497 | */ |
| 498 | #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ |
| 499 | >> OFFSET_BIT_SHIFT) |
Jaegeuk Kim | 266e97a | 2013-02-26 13:10:46 +0900 | [diff] [blame] | 500 | enum { |
| 501 | ALLOC_NODE, /* allocate a new node page if needed */ |
| 502 | LOOKUP_NODE, /* look up a node without readahead */ |
| 503 | LOOKUP_NODE_RA, /* |
| 504 | * look up a node with readahead called |
Chao Yu | 4f4124d | 2013-12-21 18:02:14 +0800 | [diff] [blame] | 505 | * by get_data_block. |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 506 | */ |
Jaegeuk Kim | 266e97a | 2013-02-26 13:10:46 +0900 | [diff] [blame] | 507 | }; |
| 508 | |
Jaegeuk Kim | a6db67f | 2015-08-10 15:01:12 -0700 | [diff] [blame] | 509 | #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 510 | |
Chao Yu | 817202d9 | 2014-04-28 17:59:43 +0800 | [diff] [blame] | 511 | #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ |
| 512 | |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 513 | /* vector size for gang look-up from extent cache that consists of radix tree */ |
| 514 | #define EXT_TREE_VEC_SIZE 64 |
| 515 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 516 | /* for in-memory extent cache entry */ |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 517 | #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ |
| 518 | |
| 519 | /* number of extent info in extent cache we try to shrink */ |
| 520 | #define EXTENT_CACHE_SHRINK_NUMBER 128 |
Jaegeuk Kim | c11abd1 | 2013-11-19 10:41:54 +0900 | [diff] [blame] | 521 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 522 | struct rb_entry { |
| 523 | struct rb_node rb_node; /* rb node located in rb-tree */ |
| 524 | unsigned int ofs; /* start offset of the entry */ |
| 525 | unsigned int len; /* length of the entry */ |
| 526 | }; |
| 527 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 528 | struct extent_info { |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 529 | unsigned int fofs; /* start offset in a file */ |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 530 | unsigned int len; /* length of the extent */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 531 | u32 blk; /* start block address of the extent */ |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 532 | }; |
| 533 | |
| 534 | struct extent_node { |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 535 | struct rb_node rb_node; |
| 536 | union { |
| 537 | struct { |
| 538 | unsigned int fofs; |
| 539 | unsigned int len; |
| 540 | u32 blk; |
| 541 | }; |
| 542 | struct extent_info ei; /* extent info */ |
| 543 | |
| 544 | }; |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 545 | struct list_head list; /* node in global extent list of sbi */ |
Hou Pengyang | 201ef5e | 2016-01-26 12:56:26 +0000 | [diff] [blame] | 546 | struct extent_tree *et; /* extent tree pointer */ |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 547 | }; |
| 548 | |
| 549 | struct extent_tree { |
| 550 | nid_t ino; /* inode number */ |
| 551 | struct rb_root root; /* root of extent info rb-tree */ |
Chao Yu | 62c8af6 | 2015-02-05 18:01:39 +0800 | [diff] [blame] | 552 | struct extent_node *cached_en; /* recently accessed extent node */ |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 553 | struct extent_info largest; /* largested extent info */ |
Jaegeuk Kim | 137d09f | 2015-12-31 15:02:16 -0800 | [diff] [blame] | 554 | struct list_head list; /* to be used by sbi->zombie_list */ |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 555 | rwlock_t lock; /* protect extent info rb-tree */ |
Chao Yu | 68e3538 | 2016-01-08 20:22:52 +0800 | [diff] [blame] | 556 | atomic_t node_cnt; /* # of extent node in rb-tree*/ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 557 | }; |
| 558 | |
| 559 | /* |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 560 | * This structure is taken from ext4_map_blocks. |
| 561 | * |
| 562 | * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). |
| 563 | */ |
| 564 | #define F2FS_MAP_NEW (1 << BH_New) |
| 565 | #define F2FS_MAP_MAPPED (1 << BH_Mapped) |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 566 | #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) |
| 567 | #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ |
| 568 | F2FS_MAP_UNWRITTEN) |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 569 | |
| 570 | struct f2fs_map_blocks { |
| 571 | block_t m_pblk; |
| 572 | block_t m_lblk; |
| 573 | unsigned int m_len; |
| 574 | unsigned int m_flags; |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 575 | pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ |
Chao Yu | 6bce963 | 2018-01-11 14:42:30 +0800 | [diff] [blame] | 576 | pgoff_t *m_next_extent; /* point to next possible extent */ |
Hyunchul Lee | 1a9d6a9 | 2017-11-28 09:23:00 +0900 | [diff] [blame] | 577 | int m_seg_type; |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 578 | }; |
| 579 | |
Chao Yu | e2b4e2b | 2015-08-19 19:11:19 +0800 | [diff] [blame] | 580 | /* for flag in get_data_block */ |
Qiuyang Sun | 9afa159 | 2017-08-09 17:27:30 +0800 | [diff] [blame] | 581 | enum { |
| 582 | F2FS_GET_BLOCK_DEFAULT, |
| 583 | F2FS_GET_BLOCK_FIEMAP, |
| 584 | F2FS_GET_BLOCK_BMAP, |
| 585 | F2FS_GET_BLOCK_PRE_DIO, |
| 586 | F2FS_GET_BLOCK_PRE_AIO, |
Chao Yu | 6bce963 | 2018-01-11 14:42:30 +0800 | [diff] [blame] | 587 | F2FS_GET_BLOCK_PRECACHE, |
Qiuyang Sun | 9afa159 | 2017-08-09 17:27:30 +0800 | [diff] [blame] | 588 | }; |
Chao Yu | e2b4e2b | 2015-08-19 19:11:19 +0800 | [diff] [blame] | 589 | |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 590 | /* |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 591 | * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. |
| 592 | */ |
| 593 | #define FADVISE_COLD_BIT 0x01 |
Jaegeuk Kim | 354a339 | 2013-06-14 08:52:35 +0900 | [diff] [blame] | 594 | #define FADVISE_LOST_PINO_BIT 0x02 |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 595 | #define FADVISE_ENCRYPT_BIT 0x04 |
Jaegeuk Kim | e7d5545 | 2015-04-29 17:02:18 -0700 | [diff] [blame] | 596 | #define FADVISE_ENC_NAME_BIT 0x08 |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 597 | #define FADVISE_KEEP_SIZE_BIT 0x10 |
Chao Yu | ac734c4 | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 598 | #define FADVISE_HOT_BIT 0x20 |
Eric Biggers | 29cead5 | 2018-03-28 11:15:09 -0700 | [diff] [blame] | 599 | #define FADVISE_VERITY_BIT 0x40 /* reserved */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 600 | |
Jaegeuk Kim | b5492af7 | 2015-04-20 13:44:41 -0700 | [diff] [blame] | 601 | #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) |
| 602 | #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) |
| 603 | #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) |
| 604 | #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) |
| 605 | #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) |
| 606 | #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 607 | #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) |
| 608 | #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) |
| 609 | #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) |
Jaegeuk Kim | e7d5545 | 2015-04-29 17:02:18 -0700 | [diff] [blame] | 610 | #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) |
| 611 | #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 612 | #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) |
| 613 | #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) |
Chao Yu | ac734c4 | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 614 | #define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT) |
| 615 | #define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT) |
| 616 | #define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT) |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 617 | |
Jaegeuk Kim | ab9fa66 | 2014-02-27 20:09:05 +0900 | [diff] [blame] | 618 | #define DEF_DIR_LEVEL 0 |
| 619 | |
Chao Yu | caf10c6 | 2018-05-07 20:28:54 +0800 | [diff] [blame] | 620 | enum { |
| 621 | GC_FAILURE_PIN, |
| 622 | GC_FAILURE_ATOMIC, |
| 623 | MAX_GC_FAILURE |
| 624 | }; |
| 625 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 626 | struct f2fs_inode_info { |
| 627 | struct inode vfs_inode; /* serve a vfs inode */ |
| 628 | unsigned long i_flags; /* keep an inode flags for ioctl */ |
| 629 | unsigned char i_advise; /* use to give file attribute hints */ |
Jaegeuk Kim | 3843154 | 2014-02-27 18:20:00 +0900 | [diff] [blame] | 630 | unsigned char i_dir_level; /* use for dentry level for large dir */ |
Chao Yu | caf10c6 | 2018-05-07 20:28:54 +0800 | [diff] [blame] | 631 | unsigned int i_current_depth; /* only for directory depth */ |
| 632 | /* for gc failure statistic */ |
| 633 | unsigned int i_gc_failures[MAX_GC_FAILURE]; |
Jaegeuk Kim | 6666e6a | 2012-12-10 17:52:48 +0900 | [diff] [blame] | 634 | unsigned int i_pino; /* parent inode number */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 635 | umode_t i_acl_mode; /* keep file acl mode temporarily */ |
| 636 | |
| 637 | /* Use below internally in f2fs*/ |
| 638 | unsigned long flags; /* use to pass per-file flags */ |
Jaegeuk Kim | d928bfb | 2014-03-20 19:10:08 +0900 | [diff] [blame] | 639 | struct rw_semaphore i_sem; /* protect fi info */ |
Jaegeuk Kim | a43e1c4 | 2016-12-02 15:11:32 -0800 | [diff] [blame] | 640 | atomic_t dirty_pages; /* # of dirty pages */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 641 | f2fs_hash_t chash; /* hash value of given file name */ |
| 642 | unsigned int clevel; /* maximum level of given file name */ |
Jaegeuk Kim | d00d1b7 | 2017-02-14 09:54:37 -0800 | [diff] [blame] | 643 | struct task_struct *task; /* lookup and create consistency */ |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 644 | struct task_struct *cp_task; /* separate cp/wb IO stats*/ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 645 | nid_t i_xattr_nid; /* node id that contains xattrs */ |
Jaegeuk Kim | 26de9b1 | 2016-05-20 20:42:37 -0700 | [diff] [blame] | 646 | loff_t last_disk_size; /* lastly written file size */ |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 647 | |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 648 | #ifdef CONFIG_QUOTA |
| 649 | struct dquot *i_dquot[MAXQUOTAS]; |
| 650 | |
| 651 | /* quota space reservation, managed internally by quota code */ |
| 652 | qsize_t i_reserved_quota; |
| 653 | #endif |
Jaegeuk Kim | 0f18b46 | 2016-05-20 11:10:10 -0700 | [diff] [blame] | 654 | struct list_head dirty_list; /* dirty list for dirs and files */ |
| 655 | struct list_head gdirty_list; /* linked in global dirty list */ |
Jaegeuk Kim | 35e13ca | 2017-10-18 19:05:57 -0700 | [diff] [blame] | 656 | struct list_head inmem_ilist; /* list for inmem inodes */ |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 657 | struct list_head inmem_pages; /* inmemory pages managed by f2fs */ |
Jaegeuk Kim | a778c4c | 2017-07-24 19:46:29 -0700 | [diff] [blame] | 658 | struct task_struct *inmem_task; /* store inmemory task */ |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 659 | struct mutex inmem_lock; /* lock for inmemory pages */ |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 660 | struct extent_tree *extent_tree; /* cached extent_tree entry */ |
Chao Yu | f6bd7d4 | 2018-04-24 10:55:28 +0800 | [diff] [blame] | 661 | |
| 662 | /* avoid racing between foreground op and gc */ |
| 663 | struct rw_semaphore i_gc_rwsem[2]; |
Qiuyang Sun | 7b23ea1 | 2017-05-18 11:06:45 +0800 | [diff] [blame] | 664 | struct rw_semaphore i_mmap_sem; |
Yunlei He | 5dd3add | 2017-09-07 10:40:54 +0800 | [diff] [blame] | 665 | struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ |
Chao Yu | e84f88e | 2017-07-19 00:19:05 +0800 | [diff] [blame] | 666 | |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 667 | int i_extra_isize; /* size of extra space located in i_addr */ |
Chao Yu | 5647b30 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 668 | kprojid_t i_projid; /* id for project quota */ |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 669 | int i_inline_xattr_size; /* inline xattr size */ |
Chao Yu | 71f8f04 | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 670 | struct timespec i_crtime; /* inode creation time */ |
Jaegeuk Kim | ac389af | 2018-03-29 22:50:41 -0700 | [diff] [blame] | 671 | struct timespec i_disk_time[4]; /* inode disk times */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 672 | }; |
| 673 | |
| 674 | static inline void get_extent_info(struct extent_info *ext, |
Chao Yu | bd933d4 | 2016-05-04 23:19:47 +0800 | [diff] [blame] | 675 | struct f2fs_extent *i_ext) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 676 | { |
Chao Yu | bd933d4 | 2016-05-04 23:19:47 +0800 | [diff] [blame] | 677 | ext->fofs = le32_to_cpu(i_ext->fofs); |
| 678 | ext->blk = le32_to_cpu(i_ext->blk); |
| 679 | ext->len = le32_to_cpu(i_ext->len); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | static inline void set_raw_extent(struct extent_info *ext, |
| 683 | struct f2fs_extent *i_ext) |
| 684 | { |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 685 | i_ext->fofs = cpu_to_le32(ext->fofs); |
Chao Yu | 4d0b0bd | 2015-02-05 17:47:25 +0800 | [diff] [blame] | 686 | i_ext->blk = cpu_to_le32(ext->blk); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 687 | i_ext->len = cpu_to_le32(ext->len); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 688 | } |
| 689 | |
Chao Yu | 429511c | 2015-02-05 17:54:31 +0800 | [diff] [blame] | 690 | static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, |
| 691 | u32 blk, unsigned int len) |
| 692 | { |
| 693 | ei->fofs = fofs; |
| 694 | ei->blk = blk; |
| 695 | ei->len = len; |
| 696 | } |
| 697 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 698 | static inline bool __is_discard_mergeable(struct discard_info *back, |
| 699 | struct discard_info *front) |
Chao Yu | 0bdee48 | 2015-03-19 19:27:51 +0800 | [diff] [blame] | 700 | { |
Jaegeuk Kim | 8f6a2e7 | 2018-05-24 13:57:26 -0700 | [diff] [blame] | 701 | return (back->lstart + back->len == front->lstart) && |
| 702 | (back->len + front->len < DEF_MAX_DISCARD_LEN); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | static inline bool __is_discard_back_mergeable(struct discard_info *cur, |
| 706 | struct discard_info *back) |
| 707 | { |
| 708 | return __is_discard_mergeable(back, cur); |
| 709 | } |
| 710 | |
| 711 | static inline bool __is_discard_front_mergeable(struct discard_info *cur, |
| 712 | struct discard_info *front) |
| 713 | { |
| 714 | return __is_discard_mergeable(cur, front); |
Chao Yu | 0bdee48 | 2015-03-19 19:27:51 +0800 | [diff] [blame] | 715 | } |
| 716 | |
Chao Yu | 429511c | 2015-02-05 17:54:31 +0800 | [diff] [blame] | 717 | static inline bool __is_extent_mergeable(struct extent_info *back, |
| 718 | struct extent_info *front) |
| 719 | { |
| 720 | return (back->fofs + back->len == front->fofs && |
| 721 | back->blk + back->len == front->blk); |
| 722 | } |
| 723 | |
| 724 | static inline bool __is_back_mergeable(struct extent_info *cur, |
| 725 | struct extent_info *back) |
| 726 | { |
| 727 | return __is_extent_mergeable(back, cur); |
| 728 | } |
| 729 | |
| 730 | static inline bool __is_front_mergeable(struct extent_info *cur, |
| 731 | struct extent_info *front) |
| 732 | { |
| 733 | return __is_extent_mergeable(cur, front); |
| 734 | } |
| 735 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 736 | extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 737 | static inline void __try_update_largest_extent(struct inode *inode, |
| 738 | struct extent_tree *et, struct extent_node *en) |
Chao Yu | 4abd3f5 | 2015-09-22 21:07:47 +0800 | [diff] [blame] | 739 | { |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 740 | if (en->ei.len > et->largest.len) { |
Chao Yu | 4abd3f5 | 2015-09-22 21:07:47 +0800 | [diff] [blame] | 741 | et->largest = en->ei; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 742 | f2fs_mark_inode_dirty_sync(inode, true); |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 743 | } |
Chao Yu | 4abd3f5 | 2015-09-22 21:07:47 +0800 | [diff] [blame] | 744 | } |
| 745 | |
Chao Yu | 84af6ae | 2017-09-29 13:59:35 +0800 | [diff] [blame] | 746 | /* |
| 747 | * For free nid management |
| 748 | */ |
| 749 | enum nid_state { |
| 750 | FREE_NID, /* newly added to free nid list */ |
| 751 | PREALLOC_NID, /* it is preallocated */ |
| 752 | MAX_NID_STATE, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 753 | }; |
| 754 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 755 | struct f2fs_nm_info { |
| 756 | block_t nat_blkaddr; /* base disk address of NAT */ |
| 757 | nid_t max_nid; /* maximum possible node ids */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 758 | nid_t available_nids; /* # of available node ids */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 759 | nid_t next_scan_nid; /* the next nid to be scanned */ |
Jaegeuk Kim | cdfc41c | 2014-03-19 13:31:37 +0900 | [diff] [blame] | 760 | unsigned int ram_thresh; /* control the memory footprint */ |
Chao Yu | ea1a29a0 | 2015-10-12 17:08:48 +0800 | [diff] [blame] | 761 | unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ |
Chao Yu | 2304cb0 | 2016-01-18 18:32:58 +0800 | [diff] [blame] | 762 | unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 763 | |
| 764 | /* NAT cache management */ |
| 765 | struct radix_tree_root nat_root;/* root of the nat entry cache */ |
Jaegeuk Kim | 309cc2b | 2014-09-22 11:40:48 -0700 | [diff] [blame] | 766 | struct radix_tree_root nat_set_root;/* root of the nat set cache */ |
Jaegeuk Kim | b873b79 | 2016-08-04 11:38:25 -0700 | [diff] [blame] | 767 | struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 768 | struct list_head nat_entries; /* cached nat entry list (clean) */ |
Jaegeuk Kim | 309cc2b | 2014-09-22 11:40:48 -0700 | [diff] [blame] | 769 | unsigned int nat_cnt; /* the # of cached nat entries */ |
Chao Yu | aec7138 | 2014-06-24 09:18:20 +0800 | [diff] [blame] | 770 | unsigned int dirty_nat_cnt; /* total num of nat entries in set */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 771 | unsigned int nat_blocks; /* # of nat blocks */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 772 | |
| 773 | /* free node ids management */ |
Jaegeuk Kim | 8a7ed66 | 2014-02-21 14:29:35 +0900 | [diff] [blame] | 774 | struct radix_tree_root free_nid_root;/* root of the free_nid cache */ |
Chao Yu | 84af6ae | 2017-09-29 13:59:35 +0800 | [diff] [blame] | 775 | struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ |
| 776 | unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 777 | spinlock_t nid_list_lock; /* protect nid lists ops */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 778 | struct mutex build_lock; /* lock for build free nids */ |
Jaegeuk Kim | 9f1896c | 2018-03-09 17:42:28 -0800 | [diff] [blame] | 779 | unsigned char **free_nid_bitmap; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 780 | unsigned char *nat_block_bitmap; |
| 781 | unsigned short *free_nid_count; /* free nid count of NAT block */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 782 | |
| 783 | /* for checkpoint */ |
| 784 | char *nat_bitmap; /* NAT bitmap pointer */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 785 | |
| 786 | unsigned int nat_bits_blocks; /* # of nat bits blocks */ |
| 787 | unsigned char *nat_bits; /* NAT bits blocks */ |
| 788 | unsigned char *full_nat_bits; /* full NAT pages */ |
| 789 | unsigned char *empty_nat_bits; /* empty NAT pages */ |
| 790 | #ifdef CONFIG_F2FS_CHECK_FS |
| 791 | char *nat_bitmap_mir; /* NAT bitmap mirror */ |
| 792 | #endif |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 793 | int bitmap_size; /* bitmap size */ |
| 794 | }; |
| 795 | |
| 796 | /* |
| 797 | * this structure is used as one of function parameters. |
| 798 | * all the information are dedicated to a given direct node block determined |
| 799 | * by the data offset in a file. |
| 800 | */ |
| 801 | struct dnode_of_data { |
| 802 | struct inode *inode; /* vfs inode pointer */ |
| 803 | struct page *inode_page; /* its inode page, NULL is possible */ |
| 804 | struct page *node_page; /* cached direct node page */ |
| 805 | nid_t nid; /* node id of the direct node block */ |
| 806 | unsigned int ofs_in_node; /* data offset in the node page */ |
| 807 | bool inode_page_locked; /* inode page is locked or not */ |
Jaegeuk Kim | 93bae09 | 2015-12-22 12:59:54 -0800 | [diff] [blame] | 808 | bool node_changed; /* is node block changed */ |
Chao Yu | 3cf4574 | 2016-01-26 15:40:44 +0800 | [diff] [blame] | 809 | char cur_level; /* level of hole node page */ |
| 810 | char max_level; /* level of current page located */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 811 | block_t data_blkaddr; /* block address of the node block */ |
| 812 | }; |
| 813 | |
| 814 | static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, |
| 815 | struct page *ipage, struct page *npage, nid_t nid) |
| 816 | { |
Jaegeuk Kim | d66d1f7 | 2013-01-03 08:57:21 +0900 | [diff] [blame] | 817 | memset(dn, 0, sizeof(*dn)); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 818 | dn->inode = inode; |
| 819 | dn->inode_page = ipage; |
| 820 | dn->node_page = npage; |
| 821 | dn->nid = nid; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /* |
| 825 | * For SIT manager |
| 826 | * |
| 827 | * By default, there are 6 active log areas across the whole main area. |
| 828 | * When considering hot and cold data separation to reduce cleaning overhead, |
| 829 | * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, |
| 830 | * respectively. |
| 831 | * In the current design, you should not change the numbers intentionally. |
| 832 | * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 |
| 833 | * logs individually according to the underlying devices. (default: 6) |
| 834 | * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for |
| 835 | * data and 8 for node logs. |
| 836 | */ |
| 837 | #define NR_CURSEG_DATA_TYPE (3) |
| 838 | #define NR_CURSEG_NODE_TYPE (3) |
| 839 | #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) |
| 840 | |
| 841 | enum { |
| 842 | CURSEG_HOT_DATA = 0, /* directory entry blocks */ |
| 843 | CURSEG_WARM_DATA, /* data blocks */ |
| 844 | CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ |
| 845 | CURSEG_HOT_NODE, /* direct node blocks of directory files */ |
| 846 | CURSEG_WARM_NODE, /* direct node blocks of normal files */ |
| 847 | CURSEG_COLD_NODE, /* indirect node blocks */ |
Jaegeuk Kim | 38aa088 | 2015-01-05 16:02:20 -0800 | [diff] [blame] | 848 | NO_CHECK_TYPE, |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 849 | }; |
| 850 | |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 851 | struct flush_cmd { |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 852 | struct completion wait; |
Gu Zheng | 721bd4d | 2014-09-05 18:31:00 +0800 | [diff] [blame] | 853 | struct llist_node llnode; |
Chao Yu | f014be8 | 2017-09-29 13:59:38 +0800 | [diff] [blame] | 854 | nid_t ino; |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 855 | int ret; |
| 856 | }; |
| 857 | |
Gu Zheng | a688b9d9e | 2014-04-27 14:21:21 +0800 | [diff] [blame] | 858 | struct flush_cmd_control { |
| 859 | struct task_struct *f2fs_issue_flush; /* flush thread */ |
| 860 | wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 861 | atomic_t issued_flush; /* # of issued flushes */ |
| 862 | atomic_t issing_flush; /* # of issing flushes */ |
Gu Zheng | 721bd4d | 2014-09-05 18:31:00 +0800 | [diff] [blame] | 863 | struct llist_head issue_list; /* list for command issue */ |
| 864 | struct llist_node *dispatch_list; /* list for command dispatch */ |
Gu Zheng | a688b9d9e | 2014-04-27 14:21:21 +0800 | [diff] [blame] | 865 | }; |
| 866 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 867 | struct f2fs_sm_info { |
| 868 | struct sit_info *sit_info; /* whole segment information */ |
| 869 | struct free_segmap_info *free_info; /* free segment information */ |
| 870 | struct dirty_seglist_info *dirty_info; /* dirty segment information */ |
| 871 | struct curseg_info *curseg_array; /* active segment information */ |
| 872 | |
Chao Yu | 7f41aab | 2017-11-02 20:41:03 +0800 | [diff] [blame] | 873 | struct rw_semaphore curseg_lock; /* for preventing curseg change */ |
| 874 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 875 | block_t seg0_blkaddr; /* block address of 0'th segment */ |
| 876 | block_t main_blkaddr; /* start block address of main area */ |
| 877 | block_t ssa_blkaddr; /* start block address of SSA area */ |
| 878 | |
| 879 | unsigned int segment_count; /* total # of segments */ |
| 880 | unsigned int main_segments; /* # of segments in main area */ |
| 881 | unsigned int reserved_segments; /* # of reserved segments */ |
| 882 | unsigned int ovp_segments; /* # of overprovision segments */ |
Jaegeuk Kim | 81eb8d6 | 2013-10-24 13:31:34 +0900 | [diff] [blame] | 883 | |
| 884 | /* a threshold to reclaim prefree segments */ |
| 885 | unsigned int rec_prefree_segments; |
Jaegeuk Kim | 7fd9e54 | 2013-11-15 13:55:58 +0900 | [diff] [blame] | 886 | |
Jaegeuk Kim | bba681c | 2015-01-26 17:41:23 -0800 | [diff] [blame] | 887 | /* for batched trimming */ |
| 888 | unsigned int trim_sections; /* # of sections to trim */ |
| 889 | |
Chao Yu | 184a5cd | 2014-09-04 18:13:01 +0800 | [diff] [blame] | 890 | struct list_head sit_entry_set; /* sit entry set list */ |
| 891 | |
Jaegeuk Kim | 216fbd6 | 2013-11-07 13:13:42 +0900 | [diff] [blame] | 892 | unsigned int ipu_policy; /* in-place-update policy */ |
| 893 | unsigned int min_ipu_util; /* in-place-update threshold */ |
Jaegeuk Kim | c1ce1b0 | 2014-09-10 16:53:02 -0700 | [diff] [blame] | 894 | unsigned int min_fsync_blocks; /* threshold for fsync */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 895 | unsigned int min_hot_blocks; /* threshold for hot block allocation */ |
Chao Yu | b9f7387 | 2017-10-28 16:52:33 +0800 | [diff] [blame] | 896 | unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 897 | |
| 898 | /* for flush command control */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 899 | struct flush_cmd_control *fcc_info; |
Gu Zheng | a688b9d9e | 2014-04-27 14:21:21 +0800 | [diff] [blame] | 900 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 901 | /* for discard command control */ |
| 902 | struct discard_cmd_control *dcc_info; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 903 | }; |
| 904 | |
| 905 | /* |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 906 | * For superblock |
| 907 | */ |
| 908 | /* |
| 909 | * COUNT_TYPE for monitoring |
| 910 | * |
| 911 | * f2fs monitors the number of several block types such as on-writeback, |
| 912 | * dirty dentry blocks, dirty node blocks, and dirty meta blocks. |
| 913 | */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 914 | #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 915 | enum count_type { |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 916 | F2FS_DIRTY_DENTS, |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 917 | F2FS_DIRTY_DATA, |
Jaegeuk Kim | 931ecc2 | 2017-11-13 17:46:38 -0800 | [diff] [blame] | 918 | F2FS_DIRTY_QDATA, |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 919 | F2FS_DIRTY_NODES, |
| 920 | F2FS_DIRTY_META, |
Jaegeuk Kim | 8dcf2ff7 | 2014-12-05 17:18:15 -0800 | [diff] [blame] | 921 | F2FS_INMEM_PAGES, |
Jaegeuk Kim | 0f18b46 | 2016-05-20 11:10:10 -0700 | [diff] [blame] | 922 | F2FS_DIRTY_IMETA, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 923 | F2FS_WB_CP_DATA, |
| 924 | F2FS_WB_DATA, |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 925 | NR_COUNT_TYPE, |
| 926 | }; |
| 927 | |
| 928 | /* |
arter97 | e1c4204 | 2014-08-06 23:22:50 +0900 | [diff] [blame] | 929 | * The below are the page types of bios used in submit_bio(). |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 930 | * The available types are: |
| 931 | * DATA User data pages. It operates as async mode. |
| 932 | * NODE Node pages. It operates as async mode. |
| 933 | * META FS metadata pages such as SIT, NAT, CP. |
| 934 | * NR_PAGE_TYPE The number of page types. |
| 935 | * META_FLUSH Make sure the previous pages are written |
| 936 | * with waiting the bio's completion |
| 937 | * ... Only can be used with META. |
| 938 | */ |
Jaegeuk Kim | 7d5e510 | 2013-11-18 17:13:35 +0900 | [diff] [blame] | 939 | #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 940 | enum page_type { |
| 941 | DATA, |
| 942 | NODE, |
| 943 | META, |
| 944 | NR_PAGE_TYPE, |
| 945 | META_FLUSH, |
Jaegeuk Kim | 8ce67cb | 2015-03-17 17:58:08 -0700 | [diff] [blame] | 946 | INMEM, /* the below types are used by tracepoints only. */ |
| 947 | INMEM_DROP, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 948 | INMEM_INVALIDATE, |
Chao Yu | 28bc106 | 2016-02-06 14:40:34 +0800 | [diff] [blame] | 949 | INMEM_REVOKE, |
Jaegeuk Kim | 8ce67cb | 2015-03-17 17:58:08 -0700 | [diff] [blame] | 950 | IPU, |
| 951 | OPU, |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 952 | }; |
| 953 | |
Jaegeuk Kim | c412726 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 954 | enum temp_type { |
| 955 | HOT = 0, /* must be zero for meta bio */ |
| 956 | WARM, |
| 957 | COLD, |
| 958 | NR_TEMP_TYPE, |
| 959 | }; |
| 960 | |
Jaegeuk Kim | 1b48ed6 | 2017-05-12 13:51:34 -0700 | [diff] [blame] | 961 | enum need_lock_type { |
| 962 | LOCK_REQ = 0, |
| 963 | LOCK_DONE, |
| 964 | LOCK_RETRY, |
| 965 | }; |
| 966 | |
Chao Yu | d75eb8d | 2017-11-06 22:51:45 +0800 | [diff] [blame] | 967 | enum cp_reason_type { |
| 968 | CP_NO_NEEDED, |
| 969 | CP_NON_REGULAR, |
| 970 | CP_HARDLINK, |
| 971 | CP_SB_NEED_CP, |
| 972 | CP_WRONG_PINO, |
| 973 | CP_NO_SPC_ROLL, |
| 974 | CP_NODE_NEED_CP, |
| 975 | CP_FASTBOOT_MODE, |
| 976 | CP_SPEC_LOG_NUM, |
Jaegeuk Kim | 211cb7b | 2017-12-28 08:09:44 -0800 | [diff] [blame] | 977 | CP_RECOVER_DIR, |
Chao Yu | d75eb8d | 2017-11-06 22:51:45 +0800 | [diff] [blame] | 978 | }; |
| 979 | |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 980 | enum iostat_type { |
| 981 | APP_DIRECT_IO, /* app direct IOs */ |
| 982 | APP_BUFFERED_IO, /* app buffered IOs */ |
| 983 | APP_WRITE_IO, /* app write IOs */ |
| 984 | APP_MAPPED_IO, /* app mapped IOs */ |
| 985 | FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ |
| 986 | FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ |
| 987 | FS_META_IO, /* meta IOs from kworker/reclaimer */ |
| 988 | FS_GC_DATA_IO, /* data IOs from forground gc */ |
| 989 | FS_GC_NODE_IO, /* node IOs from forground gc */ |
| 990 | FS_CP_DATA_IO, /* data IOs from checkpoint */ |
| 991 | FS_CP_NODE_IO, /* node IOs from checkpoint */ |
| 992 | FS_CP_META_IO, /* meta IOs from checkpoint */ |
| 993 | FS_DISCARD, /* discard */ |
| 994 | NR_IO_TYPE, |
| 995 | }; |
| 996 | |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 997 | struct f2fs_io_info { |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 998 | struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ |
Chao Yu | f014be8 | 2017-09-29 13:59:38 +0800 | [diff] [blame] | 999 | nid_t ino; /* inode number */ |
Gu Zheng | 7e8f230 | 2013-12-20 18:17:49 +0800 | [diff] [blame] | 1000 | enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ |
Jaegeuk Kim | c412726 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 1001 | enum temp_type temp; /* contains HOT/WARM/COLD */ |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 1002 | int op; /* contains REQ_OP_ */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1003 | int op_flags; /* req_flag_bits */ |
Chao Yu | 7a9d754 | 2016-02-22 18:36:38 +0800 | [diff] [blame] | 1004 | block_t new_blkaddr; /* new block address to be written */ |
Chao Yu | 28bc106 | 2016-02-06 14:40:34 +0800 | [diff] [blame] | 1005 | block_t old_blkaddr; /* old block address before Cow */ |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 1006 | struct page *page; /* page to be written */ |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 1007 | struct page *encrypted_page; /* encrypted page */ |
Chao Yu | c52dc0f | 2017-05-19 23:37:01 +0800 | [diff] [blame] | 1008 | struct list_head list; /* serialize IOs */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1009 | bool submitted; /* indicate IO submission */ |
Jaegeuk Kim | 1b48ed6 | 2017-05-12 13:51:34 -0700 | [diff] [blame] | 1010 | int need_lock; /* indicate we need to lock cp_rwsem */ |
Chao Yu | c52dc0f | 2017-05-19 23:37:01 +0800 | [diff] [blame] | 1011 | bool in_list; /* indicate fio is in io_list */ |
Yunlei He | a3f8ec8 | 2018-03-08 16:29:13 +0800 | [diff] [blame] | 1012 | bool is_meta; /* indicate borrow meta inode mapping or not */ |
Chao Yu | 34880e0 | 2018-05-28 23:47:18 +0800 | [diff] [blame] | 1013 | bool retry; /* need to reallocate block address */ |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 1014 | enum iostat_type io_type; /* io type */ |
Yufen Yu | cbd5e5a | 2018-01-09 19:33:39 +0800 | [diff] [blame] | 1015 | struct writeback_control *io_wbc; /* writeback control */ |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 1016 | }; |
| 1017 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1018 | #define is_read_io(rw) ((rw) == READ) |
Jaegeuk Kim | 1ff7bd3 | 2013-11-19 12:47:22 +0900 | [diff] [blame] | 1019 | struct f2fs_bio_info { |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 1020 | struct f2fs_sb_info *sbi; /* f2fs superblock */ |
Jaegeuk Kim | 1ff7bd3 | 2013-11-19 12:47:22 +0900 | [diff] [blame] | 1021 | struct bio *bio; /* bios to merge */ |
| 1022 | sector_t last_block_in_bio; /* last block number */ |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 1023 | struct f2fs_io_info fio; /* store buffered io info. */ |
Chao Yu | df0f8dc | 2014-03-22 14:57:23 +0800 | [diff] [blame] | 1024 | struct rw_semaphore io_rwsem; /* blocking op for bio */ |
Chao Yu | c52dc0f | 2017-05-19 23:37:01 +0800 | [diff] [blame] | 1025 | spinlock_t io_lock; /* serialize DATA/NODE IOs */ |
| 1026 | struct list_head io_list; /* track fios */ |
Jaegeuk Kim | 1ff7bd3 | 2013-11-19 12:47:22 +0900 | [diff] [blame] | 1027 | }; |
| 1028 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1029 | #define FDEV(i) (sbi->devs[i]) |
| 1030 | #define RDEV(i) (raw_super->devs[i]) |
| 1031 | struct f2fs_dev_info { |
| 1032 | struct block_device *bdev; |
| 1033 | char path[MAX_PATH_LEN]; |
| 1034 | unsigned int total_segments; |
| 1035 | block_t start_blk; |
| 1036 | block_t end_blk; |
| 1037 | #ifdef CONFIG_BLK_DEV_ZONED |
| 1038 | unsigned int nr_blkz; /* Total number of zones */ |
| 1039 | u8 *blkz_type; /* Array of zones type */ |
| 1040 | #endif |
| 1041 | }; |
| 1042 | |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 1043 | enum inode_type { |
| 1044 | DIR_INODE, /* for dirty dir inode */ |
| 1045 | FILE_INODE, /* for dirty regular/symlink inode */ |
Jaegeuk Kim | 0f18b46 | 2016-05-20 11:10:10 -0700 | [diff] [blame] | 1046 | DIRTY_META, /* for all dirtied inode metadata */ |
Jaegeuk Kim | 35e13ca | 2017-10-18 19:05:57 -0700 | [diff] [blame] | 1047 | ATOMIC_FILE, /* for all atomic files */ |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 1048 | NR_INODE_TYPE, |
| 1049 | }; |
| 1050 | |
Chao Yu | 6729880 | 2014-11-18 11:18:36 +0800 | [diff] [blame] | 1051 | /* for inner inode cache management */ |
| 1052 | struct inode_management { |
| 1053 | struct radix_tree_root ino_root; /* ino entry array */ |
| 1054 | spinlock_t ino_lock; /* for ino entry lock */ |
| 1055 | struct list_head ino_list; /* inode list head */ |
| 1056 | unsigned long ino_num; /* number of entries */ |
| 1057 | }; |
| 1058 | |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 1059 | /* For s_flag in struct f2fs_sb_info */ |
| 1060 | enum { |
| 1061 | SBI_IS_DIRTY, /* dirty flag for checkpoint */ |
| 1062 | SBI_IS_CLOSE, /* specify unmounting */ |
| 1063 | SBI_NEED_FSCK, /* need fsck.f2fs to fix */ |
| 1064 | SBI_POR_DOING, /* recovery is doing or not */ |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1065 | SBI_NEED_SB_WRITE, /* need to recover superblock */ |
Jaegeuk Kim | bbf156f | 2016-08-29 18:23:45 -0700 | [diff] [blame] | 1066 | SBI_NEED_CP, /* need to checkpoint */ |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 1067 | }; |
| 1068 | |
Jaegeuk Kim | 6beceb5 | 2016-01-08 15:51:50 -0800 | [diff] [blame] | 1069 | enum { |
| 1070 | CP_TIME, |
Jaegeuk Kim | d0239e1 | 2016-01-08 16:57:48 -0800 | [diff] [blame] | 1071 | REQ_TIME, |
Jaegeuk Kim | 6beceb5 | 2016-01-08 15:51:50 -0800 | [diff] [blame] | 1072 | MAX_TIME, |
| 1073 | }; |
| 1074 | |
Hyunchul Lee | bcdc571 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 1075 | enum { |
Jaegeuk Kim | 0390d83 | 2018-05-07 14:22:40 -0700 | [diff] [blame] | 1076 | GC_NORMAL, |
| 1077 | GC_IDLE_CB, |
| 1078 | GC_IDLE_GREEDY, |
| 1079 | GC_URGENT, |
| 1080 | }; |
| 1081 | |
| 1082 | enum { |
Hyunchul Lee | bcdc571 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 1083 | WHINT_MODE_OFF, /* not pass down write hints */ |
| 1084 | WHINT_MODE_USER, /* try to pass down hints given by users */ |
Hyunchul Lee | 87c1806 | 2018-01-31 11:36:58 +0900 | [diff] [blame] | 1085 | WHINT_MODE_FS, /* pass down hints with F2FS policy */ |
Hyunchul Lee | bcdc571 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 1086 | }; |
| 1087 | |
Jaegeuk Kim | 78c1fc2 | 2018-02-18 08:50:49 -0800 | [diff] [blame] | 1088 | enum { |
| 1089 | ALLOC_MODE_DEFAULT, /* stay default */ |
| 1090 | ALLOC_MODE_REUSE, /* reuse segments as much as possible */ |
| 1091 | }; |
| 1092 | |
Junling Zheng | 9a95481 | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 1093 | enum fsync_mode { |
| 1094 | FSYNC_MODE_POSIX, /* fsync follows posix semantics */ |
| 1095 | FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */ |
Jaegeuk Kim | 3a38cf1 | 2018-05-25 18:02:58 -0700 | [diff] [blame] | 1096 | FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */ |
Junling Zheng | 9a95481 | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 1097 | }; |
| 1098 | |
Sheng Yong | aa5bcfd | 2018-03-15 18:51:42 +0800 | [diff] [blame] | 1099 | #ifdef CONFIG_F2FS_FS_ENCRYPTION |
| 1100 | #define DUMMY_ENCRYPTION_ENABLED(sbi) \ |
| 1101 | (unlikely(F2FS_OPTION(sbi).test_dummy_encryption)) |
| 1102 | #else |
| 1103 | #define DUMMY_ENCRYPTION_ENABLED(sbi) (0) |
| 1104 | #endif |
| 1105 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1106 | struct f2fs_sb_info { |
| 1107 | struct super_block *sb; /* pointer to VFS super block */ |
Jaegeuk Kim | 5e176d5 | 2013-06-28 12:47:01 +0900 | [diff] [blame] | 1108 | struct proc_dir_entry *s_proc; /* proc entry */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1109 | struct f2fs_super_block *raw_super; /* raw super block pointer */ |
Chao Yu | 1e72cb2 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 1110 | struct rw_semaphore sb_lock; /* lock for raw super block */ |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 1111 | int valid_super_block; /* valid super block no */ |
Chao Yu | fadb2fb | 2016-09-20 10:29:47 +0800 | [diff] [blame] | 1112 | unsigned long s_flag; /* flags for sbi */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1113 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1114 | #ifdef CONFIG_BLK_DEV_ZONED |
| 1115 | unsigned int blocks_per_blkz; /* F2FS blocks per zone */ |
| 1116 | unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ |
Jaegeuk Kim | b5a7aef | 2016-05-04 22:05:01 -0700 | [diff] [blame] | 1117 | #endif |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1118 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1119 | /* for node-related operations */ |
| 1120 | struct f2fs_nm_info *nm_info; /* node manager */ |
| 1121 | struct inode *node_inode; /* cache node blocks */ |
| 1122 | |
| 1123 | /* for segment-related operations */ |
| 1124 | struct f2fs_sm_info *sm_info; /* segment manager */ |
Jaegeuk Kim | 1ff7bd3 | 2013-11-19 12:47:22 +0900 | [diff] [blame] | 1125 | |
| 1126 | /* for bio operations */ |
Jaegeuk Kim | c412726 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 1127 | struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ |
Chao Yu | 0650468 | 2017-05-19 23:37:00 +0800 | [diff] [blame] | 1128 | struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; |
| 1129 | /* bio ordering for NODE/DATA */ |
Chao Yu | bbab2dc | 2018-05-26 09:00:13 +0800 | [diff] [blame] | 1130 | /* keep migration IO order for LFS mode */ |
| 1131 | struct rw_semaphore io_order_lock; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1132 | mempool_t *write_io_dummy; /* Dummy pages */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1133 | |
| 1134 | /* for checkpoint */ |
| 1135 | struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ |
Jaegeuk Kim | 01e15b3 | 2016-11-24 12:45:15 -0800 | [diff] [blame] | 1136 | int cur_cp_pack; /* remain current cp pack */ |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1137 | spinlock_t cp_lock; /* for flag in ckpt */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1138 | struct inode *meta_inode; /* cache meta blocks */ |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1139 | struct mutex cp_mutex; /* checkpoint procedure lock */ |
Jaegeuk Kim | b873b79 | 2016-08-04 11:38:25 -0700 | [diff] [blame] | 1140 | struct rw_semaphore cp_rwsem; /* blocking FS operations */ |
Chao Yu | b3582c6 | 2014-07-03 18:58:39 +0800 | [diff] [blame] | 1141 | struct rw_semaphore node_write; /* locking node writes */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1142 | struct rw_semaphore node_change; /* locking node change */ |
Changman Lee | fb51b5e | 2013-11-07 12:48:25 +0900 | [diff] [blame] | 1143 | wait_queue_head_t cp_wait; |
Jaegeuk Kim | 6beceb5 | 2016-01-08 15:51:50 -0800 | [diff] [blame] | 1144 | unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ |
| 1145 | long interval_time[MAX_TIME]; /* to store thresholds */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1146 | |
Chao Yu | 6729880 | 2014-11-18 11:18:36 +0800 | [diff] [blame] | 1147 | struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ |
Jaegeuk Kim | 6451e04 | 2014-07-25 15:47:17 -0700 | [diff] [blame] | 1148 | |
| 1149 | /* for orphan inode, use 0'th array */ |
Gu Zheng | 0d47c1a | 2013-12-26 18:24:19 +0800 | [diff] [blame] | 1150 | unsigned int max_orphans; /* max orphan inodes */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1151 | |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 1152 | /* for inode management */ |
| 1153 | struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ |
| 1154 | spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1155 | |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 1156 | /* for extent tree cache */ |
| 1157 | struct radix_tree_root extent_tree_root;/* cache extent cache entries */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1158 | struct mutex extent_tree_lock; /* locking extent radix tree */ |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 1159 | struct list_head extent_list; /* lru list for shrinker */ |
| 1160 | spinlock_t extent_lock; /* locking extent lru list */ |
Jaegeuk Kim | 7441cce | 2015-12-21 19:20:15 -0800 | [diff] [blame] | 1161 | atomic_t total_ext_tree; /* extent tree count */ |
Jaegeuk Kim | 137d09f | 2015-12-31 15:02:16 -0800 | [diff] [blame] | 1162 | struct list_head zombie_list; /* extent zombie tree list */ |
Jaegeuk Kim | 74fd8d9 | 2015-12-21 19:25:50 -0800 | [diff] [blame] | 1163 | atomic_t total_zombie_tree; /* extent zombie tree count */ |
Chao Yu | 13054c5 | 2015-02-05 17:52:58 +0800 | [diff] [blame] | 1164 | atomic_t total_ext_node; /* extent info count */ |
| 1165 | |
arter97 | e1c4204 | 2014-08-06 23:22:50 +0900 | [diff] [blame] | 1166 | /* basic filesystem units */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1167 | unsigned int log_sectors_per_block; /* log2 sectors per block */ |
| 1168 | unsigned int log_blocksize; /* log2 block size */ |
| 1169 | unsigned int blocksize; /* block size */ |
| 1170 | unsigned int root_ino_num; /* root inode number*/ |
| 1171 | unsigned int node_ino_num; /* node inode number*/ |
| 1172 | unsigned int meta_ino_num; /* meta inode number*/ |
| 1173 | unsigned int log_blocks_per_seg; /* log2 blocks per segment */ |
| 1174 | unsigned int blocks_per_seg; /* blocks per segment */ |
| 1175 | unsigned int segs_per_sec; /* segments per section */ |
| 1176 | unsigned int secs_per_zone; /* sections per zone */ |
| 1177 | unsigned int total_sections; /* total section count */ |
| 1178 | unsigned int total_node_count; /* total node block count */ |
| 1179 | unsigned int total_valid_node_count; /* valid node block count */ |
Chao Yu | e0afc4d | 2015-12-31 14:35:37 +0800 | [diff] [blame] | 1180 | loff_t max_file_blocks; /* max block index of file */ |
Jaegeuk Kim | ab9fa66 | 2014-02-27 20:09:05 +0900 | [diff] [blame] | 1181 | int dir_level; /* directory level */ |
Chao Yu | b9f7387 | 2017-10-28 16:52:33 +0800 | [diff] [blame] | 1182 | unsigned int trigger_ssr_threshold; /* threshold to trigger ssr */ |
Sheng Yong | 1ed7533 | 2017-11-22 18:23:38 +0800 | [diff] [blame] | 1183 | int readdir_ra; /* readahead inode in readdir */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1184 | |
| 1185 | block_t user_block_count; /* # of user blocks */ |
| 1186 | block_t total_valid_block_count; /* # of valid blocks */ |
Jaegeuk Kim | a66cdd9 | 2015-04-30 22:37:50 -0700 | [diff] [blame] | 1187 | block_t discard_blks; /* discard command candidats */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1188 | block_t last_valid_block_count; /* for recovery */ |
Chao Yu | 026bd9d | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 1189 | block_t reserved_blocks; /* configurable reserved blocks */ |
Yunlong Song | 68ab6f8 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 1190 | block_t current_reserved_blocks; /* current reserved blocks */ |
Chao Yu | 026bd9d | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 1191 | |
Chao Yu | 09234be | 2017-11-16 16:59:14 +0800 | [diff] [blame] | 1192 | unsigned int nquota_files; /* # of quota sysfile */ |
| 1193 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1194 | u32 s_next_generation; /* for NFS support */ |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 1195 | |
| 1196 | /* # of pages, see count_type */ |
Jaegeuk Kim | 725ba1a | 2016-10-20 19:09:57 -0700 | [diff] [blame] | 1197 | atomic_t nr_pages[NR_COUNT_TYPE]; |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 1198 | /* # of allocated blocks */ |
| 1199 | struct percpu_counter alloc_valid_block_count; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1200 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1201 | /* writeback control */ |
| 1202 | atomic_t wb_sync_req; /* count # of WB_SYNC threads */ |
| 1203 | |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 1204 | /* valid inode count */ |
| 1205 | struct percpu_counter total_valid_inode_count; |
| 1206 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1207 | struct f2fs_mount_info mount_opt; /* mount options */ |
| 1208 | |
| 1209 | /* for cleaning operations */ |
| 1210 | struct mutex gc_mutex; /* mutex for GC */ |
| 1211 | struct f2fs_gc_kthread *gc_thread; /* GC thread */ |
Jaegeuk Kim | 5ec4e49 | 2013-03-31 13:26:03 +0900 | [diff] [blame] | 1212 | unsigned int cur_victim_sec; /* current victim section num */ |
Jaegeuk Kim | 0390d83 | 2018-05-07 14:22:40 -0700 | [diff] [blame] | 1213 | unsigned int gc_mode; /* current GC state */ |
Chao Yu | caf10c6 | 2018-05-07 20:28:54 +0800 | [diff] [blame] | 1214 | /* for skip statistic */ |
| 1215 | unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1216 | |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 1217 | /* threshold for gc trials on pinned files */ |
| 1218 | u64 gc_pin_file_threshold; |
| 1219 | |
Jaegeuk Kim | b1c57c1 | 2014-01-08 13:45:08 +0900 | [diff] [blame] | 1220 | /* maximum # of trials to find a victim segment for SSR and GC */ |
| 1221 | unsigned int max_victim_search; |
| 1222 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1223 | /* |
| 1224 | * for stat information. |
| 1225 | * one is for the LFS mode, and the other is for the SSR mode. |
| 1226 | */ |
Namjae Jeon | 35b09d8 | 2013-05-23 22:57:53 +0900 | [diff] [blame] | 1227 | #ifdef CONFIG_F2FS_STAT_FS |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1228 | struct f2fs_stat_info *stat_info; /* FS status information */ |
| 1229 | unsigned int segment_count[2]; /* # of allocated segments */ |
| 1230 | unsigned int block_count[2]; /* # of allocated blocks */ |
Changman Lee | b9a2c25 | 2014-12-24 02:16:54 +0900 | [diff] [blame] | 1231 | atomic_t inplace_count; /* # of inplace update */ |
Chao Yu | 5b7ee37 | 2015-09-30 17:38:48 +0800 | [diff] [blame] | 1232 | atomic64_t total_hit_ext; /* # of lookup extent cache */ |
| 1233 | atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ |
| 1234 | atomic64_t read_hit_largest; /* # of hit largest extent node */ |
| 1235 | atomic64_t read_hit_cached; /* # of hit cached extent node */ |
Chao Yu | d5e8f6c | 2015-07-15 17:28:53 +0800 | [diff] [blame] | 1236 | atomic_t inline_xattr; /* # of inline_xattr inodes */ |
Chao Yu | 03e14d5 | 2014-12-08 19:08:20 +0800 | [diff] [blame] | 1237 | atomic_t inline_inode; /* # of inline_data inodes */ |
| 1238 | atomic_t inline_dir; /* # of inline_dentry inodes */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1239 | atomic_t aw_cnt; /* # of atomic writes */ |
| 1240 | atomic_t vw_cnt; /* # of volatile writes */ |
| 1241 | atomic_t max_aw_cnt; /* max # of atomic writes */ |
| 1242 | atomic_t max_vw_cnt; /* max # of volatile writes */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1243 | int bg_gc; /* background gc calls */ |
Chao Yu | 33fbd51 | 2015-12-17 17:14:44 +0800 | [diff] [blame] | 1244 | unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ |
Namjae Jeon | 35b09d8 | 2013-05-23 22:57:53 +0900 | [diff] [blame] | 1245 | #endif |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1246 | spinlock_t stat_lock; /* lock for stat operations */ |
Namjae Jeon | b59d0ba | 2013-08-04 23:09:40 +0900 | [diff] [blame] | 1247 | |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 1248 | /* For app/fs IO statistics */ |
| 1249 | spinlock_t iostat_lock; |
| 1250 | unsigned long long write_iostat[NR_IO_TYPE]; |
| 1251 | bool iostat_enable; |
| 1252 | |
Namjae Jeon | b59d0ba | 2013-08-04 23:09:40 +0900 | [diff] [blame] | 1253 | /* For sysfs suppport */ |
| 1254 | struct kobject s_kobj; |
| 1255 | struct completion s_kobj_unregister; |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 1256 | |
| 1257 | /* For shrinker support */ |
| 1258 | struct list_head s_list; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1259 | int s_ndevs; /* number of devices */ |
| 1260 | struct f2fs_dev_info *devs; /* for device list */ |
Chao Yu | fd6422e | 2017-09-29 13:59:39 +0800 | [diff] [blame] | 1261 | unsigned int dirty_device; /* for checkpoint data flush */ |
| 1262 | spinlock_t dev_lock; /* protect dirty_device */ |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 1263 | struct mutex umount_mutex; |
| 1264 | unsigned int shrinker_run_no; |
Shuoran Liu | 8f1dbbb | 2016-01-27 09:57:30 +0800 | [diff] [blame] | 1265 | |
| 1266 | /* For write statistics */ |
| 1267 | u64 sectors_written_start; |
| 1268 | u64 kbytes_written; |
Keith Mok | 43b6573 | 2016-03-02 12:04:24 -0800 | [diff] [blame] | 1269 | |
| 1270 | /* Reference to checksum algorithm driver via cryptoapi */ |
| 1271 | struct crypto_shash *s_chksum_driver; |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 1272 | |
Chao Yu | 4310125 | 2017-07-31 20:19:09 +0800 | [diff] [blame] | 1273 | /* Precomputed FS UUID checksum for seeding other checksums */ |
| 1274 | __u32 s_chksum_seed; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1275 | }; |
| 1276 | |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 1277 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1278 | #define f2fs_show_injection_info(type) \ |
| 1279 | printk("%sF2FS-fs : inject %s in %s of %pF\n", \ |
| 1280 | KERN_INFO, fault_name[type], \ |
| 1281 | __func__, __builtin_return_address(0)) |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 1282 | static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) |
| 1283 | { |
Chao Yu | e9a50e6 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1284 | struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 1285 | |
| 1286 | if (!ffi->inject_rate) |
| 1287 | return false; |
| 1288 | |
| 1289 | if (!IS_FAULT_SET(ffi, type)) |
| 1290 | return false; |
| 1291 | |
| 1292 | atomic_inc(&ffi->inject_ops); |
| 1293 | if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { |
| 1294 | atomic_set(&ffi->inject_ops, 0); |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 1295 | return true; |
| 1296 | } |
| 1297 | return false; |
| 1298 | } |
| 1299 | #endif |
| 1300 | |
Shuoran Liu | 8f1dbbb | 2016-01-27 09:57:30 +0800 | [diff] [blame] | 1301 | /* For write statistics. Suppose sector size is 512 bytes, |
| 1302 | * and the return value is in kbytes. s is of struct f2fs_sb_info. |
| 1303 | */ |
| 1304 | #define BD_PART_WRITTEN(s) \ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1305 | (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ |
| 1306 | (s)->sectors_written_start) >> 1) |
Shuoran Liu | 8f1dbbb | 2016-01-27 09:57:30 +0800 | [diff] [blame] | 1307 | |
Jaegeuk Kim | 6beceb5 | 2016-01-08 15:51:50 -0800 | [diff] [blame] | 1308 | static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) |
| 1309 | { |
| 1310 | sbi->last_time[type] = jiffies; |
| 1311 | } |
| 1312 | |
| 1313 | static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) |
| 1314 | { |
Arnd Bergmann | bf823c8 | 2017-10-19 11:52:47 +0200 | [diff] [blame] | 1315 | unsigned long interval = sbi->interval_time[type] * HZ; |
Jaegeuk Kim | 6beceb5 | 2016-01-08 15:51:50 -0800 | [diff] [blame] | 1316 | |
| 1317 | return time_after(jiffies, sbi->last_time[type] + interval); |
| 1318 | } |
| 1319 | |
Jaegeuk Kim | d0239e1 | 2016-01-08 16:57:48 -0800 | [diff] [blame] | 1320 | static inline bool is_idle(struct f2fs_sb_info *sbi) |
| 1321 | { |
| 1322 | struct block_device *bdev = sbi->sb->s_bdev; |
| 1323 | struct request_queue *q = bdev_get_queue(bdev); |
| 1324 | struct request_list *rl = &q->root_rl; |
| 1325 | |
| 1326 | if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) |
| 1327 | return 0; |
| 1328 | |
| 1329 | return f2fs_time_over(sbi, REQ_TIME); |
| 1330 | } |
| 1331 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1332 | /* |
| 1333 | * Inline functions |
| 1334 | */ |
Chao Yu | d7714cb | 2017-11-30 19:28:21 +0800 | [diff] [blame] | 1335 | static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc, |
Chao Yu | 4310125 | 2017-07-31 20:19:09 +0800 | [diff] [blame] | 1336 | const void *address, unsigned int length) |
| 1337 | { |
| 1338 | struct { |
| 1339 | struct shash_desc shash; |
| 1340 | char ctx[4]; |
| 1341 | } desc; |
| 1342 | int err; |
| 1343 | |
| 1344 | BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); |
| 1345 | |
| 1346 | desc.shash.tfm = sbi->s_chksum_driver; |
| 1347 | desc.shash.flags = 0; |
| 1348 | *(u32 *)desc.ctx = crc; |
| 1349 | |
| 1350 | err = crypto_shash_update(&desc.shash, address, length); |
| 1351 | BUG_ON(err); |
| 1352 | |
| 1353 | return *(u32 *)desc.ctx; |
| 1354 | } |
| 1355 | |
Chao Yu | d7714cb | 2017-11-30 19:28:21 +0800 | [diff] [blame] | 1356 | static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, |
| 1357 | unsigned int length) |
| 1358 | { |
| 1359 | return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length); |
| 1360 | } |
| 1361 | |
| 1362 | static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, |
| 1363 | void *buf, size_t buf_size) |
| 1364 | { |
| 1365 | return f2fs_crc32(sbi, buf, buf_size) == blk_crc; |
| 1366 | } |
| 1367 | |
| 1368 | static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, |
| 1369 | const void *address, unsigned int length) |
| 1370 | { |
| 1371 | return __f2fs_crc32(sbi, crc, address, length); |
| 1372 | } |
| 1373 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1374 | static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) |
| 1375 | { |
| 1376 | return container_of(inode, struct f2fs_inode_info, vfs_inode); |
| 1377 | } |
| 1378 | |
| 1379 | static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) |
| 1380 | { |
| 1381 | return sb->s_fs_info; |
| 1382 | } |
| 1383 | |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 1384 | static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) |
| 1385 | { |
| 1386 | return F2FS_SB(inode->i_sb); |
| 1387 | } |
| 1388 | |
| 1389 | static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) |
| 1390 | { |
| 1391 | return F2FS_I_SB(mapping->host); |
| 1392 | } |
| 1393 | |
| 1394 | static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) |
| 1395 | { |
| 1396 | return F2FS_M_SB(page->mapping); |
| 1397 | } |
| 1398 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1399 | static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) |
| 1400 | { |
| 1401 | return (struct f2fs_super_block *)(sbi->raw_super); |
| 1402 | } |
| 1403 | |
| 1404 | static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) |
| 1405 | { |
| 1406 | return (struct f2fs_checkpoint *)(sbi->ckpt); |
| 1407 | } |
| 1408 | |
Gu Zheng | 4559071 | 2013-07-15 17:57:38 +0800 | [diff] [blame] | 1409 | static inline struct f2fs_node *F2FS_NODE(struct page *page) |
| 1410 | { |
| 1411 | return (struct f2fs_node *)page_address(page); |
| 1412 | } |
| 1413 | |
Jaegeuk Kim | 58bfaf4 | 2013-12-26 16:30:41 +0900 | [diff] [blame] | 1414 | static inline struct f2fs_inode *F2FS_INODE(struct page *page) |
| 1415 | { |
| 1416 | return &((struct f2fs_node *)page_address(page))->i; |
| 1417 | } |
| 1418 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1419 | static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) |
| 1420 | { |
| 1421 | return (struct f2fs_nm_info *)(sbi->nm_info); |
| 1422 | } |
| 1423 | |
| 1424 | static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) |
| 1425 | { |
| 1426 | return (struct f2fs_sm_info *)(sbi->sm_info); |
| 1427 | } |
| 1428 | |
| 1429 | static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) |
| 1430 | { |
| 1431 | return (struct sit_info *)(SM_I(sbi)->sit_info); |
| 1432 | } |
| 1433 | |
| 1434 | static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) |
| 1435 | { |
| 1436 | return (struct free_segmap_info *)(SM_I(sbi)->free_info); |
| 1437 | } |
| 1438 | |
| 1439 | static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) |
| 1440 | { |
| 1441 | return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); |
| 1442 | } |
| 1443 | |
Gu Zheng | 9df27d9 | 2014-01-20 18:37:04 +0800 | [diff] [blame] | 1444 | static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) |
| 1445 | { |
| 1446 | return sbi->meta_inode->i_mapping; |
| 1447 | } |
| 1448 | |
Jaegeuk Kim | 4ef51a8 | 2014-01-21 18:51:16 +0900 | [diff] [blame] | 1449 | static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) |
| 1450 | { |
| 1451 | return sbi->node_inode->i_mapping; |
| 1452 | } |
| 1453 | |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 1454 | static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1455 | { |
Chao Yu | fadb2fb | 2016-09-20 10:29:47 +0800 | [diff] [blame] | 1456 | return test_bit(type, &sbi->s_flag); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1457 | } |
| 1458 | |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 1459 | static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1460 | { |
Chao Yu | fadb2fb | 2016-09-20 10:29:47 +0800 | [diff] [blame] | 1461 | set_bit(type, &sbi->s_flag); |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) |
| 1465 | { |
Chao Yu | fadb2fb | 2016-09-20 10:29:47 +0800 | [diff] [blame] | 1466 | clear_bit(type, &sbi->s_flag); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1467 | } |
| 1468 | |
Jaegeuk Kim | d71b556 | 2013-08-09 15:03:21 +0900 | [diff] [blame] | 1469 | static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) |
| 1470 | { |
| 1471 | return le64_to_cpu(cp->checkpoint_ver); |
| 1472 | } |
| 1473 | |
Jaegeuk Kim | 0108c48 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 1474 | static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) |
| 1475 | { |
| 1476 | if (type < F2FS_MAX_QUOTAS) |
| 1477 | return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); |
| 1478 | return 0; |
| 1479 | } |
| 1480 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1481 | static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) |
| 1482 | { |
| 1483 | size_t crc_offset = le32_to_cpu(cp->checksum_offset); |
| 1484 | return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); |
| 1485 | } |
| 1486 | |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1487 | static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 1488 | { |
| 1489 | unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1490 | |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 1491 | return ckpt_flags & f; |
| 1492 | } |
| 1493 | |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1494 | static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 1495 | { |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1496 | return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); |
| 1497 | } |
| 1498 | |
| 1499 | static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) |
| 1500 | { |
| 1501 | unsigned int ckpt_flags; |
| 1502 | |
| 1503 | ckpt_flags = le32_to_cpu(cp->ckpt_flags); |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 1504 | ckpt_flags |= f; |
| 1505 | cp->ckpt_flags = cpu_to_le32(ckpt_flags); |
| 1506 | } |
| 1507 | |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1508 | static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 1509 | { |
Chao Yu | 67295cd | 2017-07-07 14:10:15 +0800 | [diff] [blame] | 1510 | unsigned long flags; |
| 1511 | |
| 1512 | spin_lock_irqsave(&sbi->cp_lock, flags); |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1513 | __set_ckpt_flags(F2FS_CKPT(sbi), f); |
Chao Yu | 67295cd | 2017-07-07 14:10:15 +0800 | [diff] [blame] | 1514 | spin_unlock_irqrestore(&sbi->cp_lock, flags); |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) |
| 1518 | { |
| 1519 | unsigned int ckpt_flags; |
| 1520 | |
| 1521 | ckpt_flags = le32_to_cpu(cp->ckpt_flags); |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 1522 | ckpt_flags &= (~f); |
| 1523 | cp->ckpt_flags = cpu_to_le32(ckpt_flags); |
| 1524 | } |
| 1525 | |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1526 | static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) |
| 1527 | { |
Chao Yu | 67295cd | 2017-07-07 14:10:15 +0800 | [diff] [blame] | 1528 | unsigned long flags; |
| 1529 | |
| 1530 | spin_lock_irqsave(&sbi->cp_lock, flags); |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1531 | __clear_ckpt_flags(F2FS_CKPT(sbi), f); |
Chao Yu | 67295cd | 2017-07-07 14:10:15 +0800 | [diff] [blame] | 1532 | spin_unlock_irqrestore(&sbi->cp_lock, flags); |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1533 | } |
| 1534 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1535 | static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) |
Jaegeuk Kim | 3e02574 | 2016-08-02 10:56:40 -0700 | [diff] [blame] | 1536 | { |
Chao Yu | 67295cd | 2017-07-07 14:10:15 +0800 | [diff] [blame] | 1537 | unsigned long flags; |
| 1538 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1539 | set_sbi_flag(sbi, SBI_NEED_FSCK); |
Jaegeuk Kim | 3e02574 | 2016-08-02 10:56:40 -0700 | [diff] [blame] | 1540 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1541 | if (lock) |
Chao Yu | 67295cd | 2017-07-07 14:10:15 +0800 | [diff] [blame] | 1542 | spin_lock_irqsave(&sbi->cp_lock, flags); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1543 | __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); |
| 1544 | kfree(NM_I(sbi)->nat_bits); |
| 1545 | NM_I(sbi)->nat_bits = NULL; |
| 1546 | if (lock) |
Chao Yu | 67295cd | 2017-07-07 14:10:15 +0800 | [diff] [blame] | 1547 | spin_unlock_irqrestore(&sbi->cp_lock, flags); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, |
| 1551 | struct cp_control *cpc) |
| 1552 | { |
| 1553 | bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); |
| 1554 | |
| 1555 | return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; |
Jaegeuk Kim | 3e02574 | 2016-08-02 10:56:40 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 1558 | static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1559 | { |
Jaegeuk Kim | b873b79 | 2016-08-04 11:38:25 -0700 | [diff] [blame] | 1560 | down_read(&sbi->cp_rwsem); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1561 | } |
| 1562 | |
Jaegeuk Kim | 1b48ed6 | 2017-05-12 13:51:34 -0700 | [diff] [blame] | 1563 | static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) |
| 1564 | { |
| 1565 | return down_read_trylock(&sbi->cp_rwsem); |
| 1566 | } |
| 1567 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 1568 | static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1569 | { |
Jaegeuk Kim | b873b79 | 2016-08-04 11:38:25 -0700 | [diff] [blame] | 1570 | up_read(&sbi->cp_rwsem); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1571 | } |
| 1572 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 1573 | static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1574 | { |
Jaegeuk Kim | b873b79 | 2016-08-04 11:38:25 -0700 | [diff] [blame] | 1575 | down_write(&sbi->cp_rwsem); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1576 | } |
| 1577 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 1578 | static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1579 | { |
Jaegeuk Kim | b873b79 | 2016-08-04 11:38:25 -0700 | [diff] [blame] | 1580 | up_write(&sbi->cp_rwsem); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1581 | } |
| 1582 | |
Jaegeuk Kim | 119ee91 | 2015-01-29 11:45:33 -0800 | [diff] [blame] | 1583 | static inline int __get_cp_reason(struct f2fs_sb_info *sbi) |
| 1584 | { |
| 1585 | int reason = CP_SYNC; |
| 1586 | |
| 1587 | if (test_opt(sbi, FASTBOOT)) |
| 1588 | reason = CP_FASTBOOT; |
| 1589 | if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) |
| 1590 | reason = CP_UMOUNT; |
| 1591 | return reason; |
| 1592 | } |
| 1593 | |
| 1594 | static inline bool __remain_node_summaries(int reason) |
| 1595 | { |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1596 | return (reason & (CP_UMOUNT | CP_FASTBOOT)); |
Jaegeuk Kim | 119ee91 | 2015-01-29 11:45:33 -0800 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) |
| 1600 | { |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1601 | return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || |
| 1602 | is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); |
Jaegeuk Kim | 119ee91 | 2015-01-29 11:45:33 -0800 | [diff] [blame] | 1603 | } |
| 1604 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1605 | /* |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1606 | * Check whether the inode has blocks or not |
| 1607 | */ |
| 1608 | static inline int F2FS_HAS_BLOCKS(struct inode *inode) |
| 1609 | { |
Chao Yu | 56a0d93 | 2017-06-14 23:00:56 +0800 | [diff] [blame] | 1610 | block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; |
| 1611 | |
Chao Yu | d9bfbbb | 2017-07-06 01:11:31 +0800 | [diff] [blame] | 1612 | return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1613 | } |
| 1614 | |
Chao Yu | 4bc8e9b | 2014-03-17 16:35:06 +0800 | [diff] [blame] | 1615 | static inline bool f2fs_has_xattr_block(unsigned int ofs) |
| 1616 | { |
| 1617 | return ofs == XATTR_NODE_OFFSET; |
| 1618 | } |
| 1619 | |
Jaegeuk Kim | 4be98c9 | 2018-01-05 16:02:36 -0800 | [diff] [blame] | 1620 | static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | c8fb245 | 2018-04-20 23:44:59 -0700 | [diff] [blame] | 1621 | struct inode *inode, bool cap) |
Jaegeuk Kim | 462d762 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 1622 | { |
Jaegeuk Kim | 4be98c9 | 2018-01-05 16:02:36 -0800 | [diff] [blame] | 1623 | if (!inode) |
| 1624 | return true; |
Jaegeuk Kim | 462d762 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 1625 | if (!test_opt(sbi, RESERVE_ROOT)) |
| 1626 | return false; |
Jaegeuk Kim | 4be98c9 | 2018-01-05 16:02:36 -0800 | [diff] [blame] | 1627 | if (IS_NOQUOTA(inode)) |
| 1628 | return true; |
Chao Yu | e9a50e6 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1629 | if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid())) |
Jaegeuk Kim | 462d762 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 1630 | return true; |
Chao Yu | e9a50e6 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1631 | if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) && |
| 1632 | in_group_p(F2FS_OPTION(sbi).s_resgid)) |
Jaegeuk Kim | 462d762 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 1633 | return true; |
Jaegeuk Kim | c8fb245 | 2018-04-20 23:44:59 -0700 | [diff] [blame] | 1634 | if (cap && capable(CAP_SYS_RESOURCE)) |
Jaegeuk Kim | c07478e | 2018-03-08 20:47:33 -0800 | [diff] [blame] | 1635 | return true; |
Jaegeuk Kim | 462d762 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 1636 | return false; |
| 1637 | } |
| 1638 | |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1639 | static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); |
| 1640 | static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 1641 | struct inode *inode, blkcnt_t *count) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1642 | { |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1643 | blkcnt_t diff = 0, release = 0; |
Chao Yu | 026bd9d | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 1644 | block_t avail_user_block_count; |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1645 | int ret; |
| 1646 | |
| 1647 | ret = dquot_reserve_block(inode, *count); |
| 1648 | if (ret) |
| 1649 | return ret; |
Jaegeuk Kim | dd11a5d | 2016-07-19 19:20:11 -0700 | [diff] [blame] | 1650 | |
Jaegeuk Kim | cb78942 | 2016-04-29 16:29:22 -0700 | [diff] [blame] | 1651 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1652 | if (time_to_inject(sbi, FAULT_BLOCK)) { |
| 1653 | f2fs_show_injection_info(FAULT_BLOCK); |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1654 | release = *count; |
| 1655 | goto enospc; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1656 | } |
Jaegeuk Kim | cb78942 | 2016-04-29 16:29:22 -0700 | [diff] [blame] | 1657 | #endif |
Jaegeuk Kim | dd11a5d | 2016-07-19 19:20:11 -0700 | [diff] [blame] | 1658 | /* |
| 1659 | * let's increase this in prior to actual block count change in order |
| 1660 | * for f2fs_sync_file to avoid data races when deciding checkpoint. |
| 1661 | */ |
| 1662 | percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); |
Chao Yu | cfb271d | 2013-12-05 17:15:22 +0800 | [diff] [blame] | 1663 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1664 | spin_lock(&sbi->stat_lock); |
Jaegeuk Kim | 2555a2d | 2016-06-30 19:02:06 -0700 | [diff] [blame] | 1665 | sbi->total_valid_block_count += (block_t)(*count); |
Yunlong Song | 68ab6f8 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 1666 | avail_user_block_count = sbi->user_block_count - |
| 1667 | sbi->current_reserved_blocks; |
Jaegeuk Kim | 5fee540 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 1668 | |
Jaegeuk Kim | c8fb245 | 2018-04-20 23:44:59 -0700 | [diff] [blame] | 1669 | if (!__allow_reserved_blocks(sbi, inode, true)) |
Chao Yu | e9a50e6 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1670 | avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; |
Jaegeuk Kim | 5fee540 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 1671 | |
Chao Yu | 026bd9d | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 1672 | if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { |
| 1673 | diff = sbi->total_valid_block_count - avail_user_block_count; |
Jaegeuk Kim | 5fee540 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 1674 | if (diff > *count) |
| 1675 | diff = *count; |
Jaegeuk Kim | dd11a5d | 2016-07-19 19:20:11 -0700 | [diff] [blame] | 1676 | *count -= diff; |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1677 | release = diff; |
Jaegeuk Kim | 5fee540 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 1678 | sbi->total_valid_block_count -= diff; |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 1679 | if (!*count) { |
| 1680 | spin_unlock(&sbi->stat_lock); |
Jaegeuk Kim | dd11a5d | 2016-07-19 19:20:11 -0700 | [diff] [blame] | 1681 | percpu_counter_sub(&sbi->alloc_valid_block_count, diff); |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1682 | goto enospc; |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 1683 | } |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1684 | } |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1685 | spin_unlock(&sbi->stat_lock); |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 1686 | |
LiFan | fdd41a8 | 2017-12-05 16:38:01 +0800 | [diff] [blame] | 1687 | if (unlikely(release)) |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1688 | dquot_release_reservation_block(inode, release); |
| 1689 | f2fs_i_blocks_write(inode, *count, true, true); |
| 1690 | return 0; |
| 1691 | |
| 1692 | enospc: |
| 1693 | dquot_release_reservation_block(inode, release); |
| 1694 | return -ENOSPC; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1695 | } |
| 1696 | |
Gu Zheng | da19b0d | 2013-11-19 18:03:27 +0800 | [diff] [blame] | 1697 | static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1698 | struct inode *inode, |
Chao Yu | 56a0d93 | 2017-06-14 23:00:56 +0800 | [diff] [blame] | 1699 | block_t count) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1700 | { |
Chao Yu | 56a0d93 | 2017-06-14 23:00:56 +0800 | [diff] [blame] | 1701 | blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; |
| 1702 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1703 | spin_lock(&sbi->stat_lock); |
Jaegeuk Kim | 9850cf4 | 2014-09-02 15:52:58 -0700 | [diff] [blame] | 1704 | f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); |
Chao Yu | 56a0d93 | 2017-06-14 23:00:56 +0800 | [diff] [blame] | 1705 | f2fs_bug_on(sbi, inode->i_blocks < sectors); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1706 | sbi->total_valid_block_count -= (block_t)count; |
Yunlong Song | 68ab6f8 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 1707 | if (sbi->reserved_blocks && |
| 1708 | sbi->current_reserved_blocks < sbi->reserved_blocks) |
| 1709 | sbi->current_reserved_blocks = min(sbi->reserved_blocks, |
| 1710 | sbi->current_reserved_blocks + count); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1711 | spin_unlock(&sbi->stat_lock); |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1712 | f2fs_i_blocks_write(inode, count, false, true); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) |
| 1716 | { |
Jaegeuk Kim | 725ba1a | 2016-10-20 19:09:57 -0700 | [diff] [blame] | 1717 | atomic_inc(&sbi->nr_pages[count_type]); |
Chao Yu | 7c4abcb | 2016-08-18 17:46:14 +0800 | [diff] [blame] | 1718 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1719 | if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || |
| 1720 | count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) |
Chao Yu | 7c4abcb | 2016-08-18 17:46:14 +0800 | [diff] [blame] | 1721 | return; |
| 1722 | |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 1723 | set_sbi_flag(sbi, SBI_IS_DIRTY); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1724 | } |
| 1725 | |
Jaegeuk Kim | a7ffdbe | 2014-09-12 15:53:45 -0700 | [diff] [blame] | 1726 | static inline void inode_inc_dirty_pages(struct inode *inode) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1727 | { |
Jaegeuk Kim | a43e1c4 | 2016-12-02 15:11:32 -0800 | [diff] [blame] | 1728 | atomic_inc(&F2FS_I(inode)->dirty_pages); |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 1729 | inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? |
| 1730 | F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); |
Jaegeuk Kim | 931ecc2 | 2017-11-13 17:46:38 -0800 | [diff] [blame] | 1731 | if (IS_NOQUOTA(inode)) |
| 1732 | inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) |
| 1736 | { |
Jaegeuk Kim | 725ba1a | 2016-10-20 19:09:57 -0700 | [diff] [blame] | 1737 | atomic_dec(&sbi->nr_pages[count_type]); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1738 | } |
| 1739 | |
Jaegeuk Kim | a7ffdbe | 2014-09-12 15:53:45 -0700 | [diff] [blame] | 1740 | static inline void inode_dec_dirty_pages(struct inode *inode) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1741 | { |
Chao Yu | 5ac9f36 | 2015-06-29 18:14:10 +0800 | [diff] [blame] | 1742 | if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && |
| 1743 | !S_ISLNK(inode->i_mode)) |
Jaegeuk Kim | 1fe54f9 | 2014-02-07 10:00:06 +0900 | [diff] [blame] | 1744 | return; |
| 1745 | |
Jaegeuk Kim | a43e1c4 | 2016-12-02 15:11:32 -0800 | [diff] [blame] | 1746 | atomic_dec(&F2FS_I(inode)->dirty_pages); |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 1747 | dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? |
| 1748 | F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); |
Jaegeuk Kim | 931ecc2 | 2017-11-13 17:46:38 -0800 | [diff] [blame] | 1749 | if (IS_NOQUOTA(inode)) |
| 1750 | dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1751 | } |
| 1752 | |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 1753 | static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1754 | { |
Jaegeuk Kim | 725ba1a | 2016-10-20 19:09:57 -0700 | [diff] [blame] | 1755 | return atomic_read(&sbi->nr_pages[count_type]); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1756 | } |
| 1757 | |
Jaegeuk Kim | a43e1c4 | 2016-12-02 15:11:32 -0800 | [diff] [blame] | 1758 | static inline int get_dirty_pages(struct inode *inode) |
Jaegeuk Kim | f8b2c1f | 2014-03-18 12:33:06 +0900 | [diff] [blame] | 1759 | { |
Jaegeuk Kim | a43e1c4 | 2016-12-02 15:11:32 -0800 | [diff] [blame] | 1760 | return atomic_read(&F2FS_I(inode)->dirty_pages); |
Jaegeuk Kim | f8b2c1f | 2014-03-18 12:33:06 +0900 | [diff] [blame] | 1761 | } |
| 1762 | |
Namjae Jeon | 5ac206c | 2013-02-02 23:52:59 +0900 | [diff] [blame] | 1763 | static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) |
| 1764 | { |
Chao Yu | 3519e3f | 2015-12-01 11:56:52 +0800 | [diff] [blame] | 1765 | unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 1766 | unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> |
| 1767 | sbi->log_blocks_per_seg; |
| 1768 | |
| 1769 | return segs / sbi->segs_per_sec; |
Namjae Jeon | 5ac206c | 2013-02-02 23:52:59 +0900 | [diff] [blame] | 1770 | } |
| 1771 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1772 | static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) |
| 1773 | { |
Jaegeuk Kim | 8b8343f | 2014-02-24 13:00:13 +0900 | [diff] [blame] | 1774 | return sbi->total_valid_block_count; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1775 | } |
| 1776 | |
Yunlei He | f83a258 | 2016-08-18 21:01:18 +0800 | [diff] [blame] | 1777 | static inline block_t discard_blocks(struct f2fs_sb_info *sbi) |
| 1778 | { |
| 1779 | return sbi->discard_blks; |
| 1780 | } |
| 1781 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1782 | static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) |
| 1783 | { |
| 1784 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); |
| 1785 | |
| 1786 | /* return NAT or SIT bitmap */ |
| 1787 | if (flag == NAT_BITMAP) |
| 1788 | return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); |
| 1789 | else if (flag == SIT_BITMAP) |
| 1790 | return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); |
| 1791 | |
| 1792 | return 0; |
| 1793 | } |
| 1794 | |
Wanpeng Li | 5514148 | 2015-02-26 07:57:20 +0800 | [diff] [blame] | 1795 | static inline block_t __cp_payload(struct f2fs_sb_info *sbi) |
| 1796 | { |
| 1797 | return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); |
| 1798 | } |
| 1799 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1800 | static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) |
| 1801 | { |
| 1802 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); |
Changman Lee | 1dbe415 | 2014-05-12 12:27:43 +0900 | [diff] [blame] | 1803 | int offset; |
| 1804 | |
Chao Yu | a1afb55 | 2018-01-25 19:40:08 +0800 | [diff] [blame] | 1805 | if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { |
| 1806 | offset = (flag == SIT_BITMAP) ? |
| 1807 | le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; |
| 1808 | return &ckpt->sit_nat_version_bitmap + offset; |
| 1809 | } |
| 1810 | |
Wanpeng Li | 5514148 | 2015-02-26 07:57:20 +0800 | [diff] [blame] | 1811 | if (__cp_payload(sbi) > 0) { |
Changman Lee | 1dbe415 | 2014-05-12 12:27:43 +0900 | [diff] [blame] | 1812 | if (flag == NAT_BITMAP) |
| 1813 | return &ckpt->sit_nat_version_bitmap; |
| 1814 | else |
Jaegeuk Kim | 65b85cc | 2014-07-30 17:25:54 -0700 | [diff] [blame] | 1815 | return (unsigned char *)ckpt + F2FS_BLKSIZE; |
Changman Lee | 1dbe415 | 2014-05-12 12:27:43 +0900 | [diff] [blame] | 1816 | } else { |
| 1817 | offset = (flag == NAT_BITMAP) ? |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 1818 | le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; |
Changman Lee | 1dbe415 | 2014-05-12 12:27:43 +0900 | [diff] [blame] | 1819 | return &ckpt->sit_nat_version_bitmap + offset; |
| 1820 | } |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) |
| 1824 | { |
Jaegeuk Kim | 01e15b3 | 2016-11-24 12:45:15 -0800 | [diff] [blame] | 1825 | block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1826 | |
Jaegeuk Kim | 01e15b3 | 2016-11-24 12:45:15 -0800 | [diff] [blame] | 1827 | if (sbi->cur_cp_pack == 2) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1828 | start_addr += sbi->blocks_per_seg; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1829 | return start_addr; |
| 1830 | } |
| 1831 | |
Jaegeuk Kim | 01e15b3 | 2016-11-24 12:45:15 -0800 | [diff] [blame] | 1832 | static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) |
| 1833 | { |
| 1834 | block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); |
| 1835 | |
| 1836 | if (sbi->cur_cp_pack == 1) |
| 1837 | start_addr += sbi->blocks_per_seg; |
| 1838 | return start_addr; |
| 1839 | } |
| 1840 | |
| 1841 | static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) |
| 1842 | { |
| 1843 | sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; |
| 1844 | } |
| 1845 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1846 | static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) |
| 1847 | { |
| 1848 | return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); |
| 1849 | } |
| 1850 | |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1851 | static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, |
Chao Yu | d9bfbbb | 2017-07-06 01:11:31 +0800 | [diff] [blame] | 1852 | struct inode *inode, bool is_inode) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1853 | { |
| 1854 | block_t valid_block_count; |
| 1855 | unsigned int valid_node_count; |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1856 | bool quota = inode && !is_inode; |
| 1857 | |
| 1858 | if (quota) { |
| 1859 | int ret = dquot_reserve_block(inode, 1); |
| 1860 | if (ret) |
| 1861 | return ret; |
| 1862 | } |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1863 | |
Chao Yu | 05dac2e | 2017-11-13 17:32:40 +0800 | [diff] [blame] | 1864 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 1865 | if (time_to_inject(sbi, FAULT_BLOCK)) { |
| 1866 | f2fs_show_injection_info(FAULT_BLOCK); |
| 1867 | goto enospc; |
| 1868 | } |
| 1869 | #endif |
| 1870 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1871 | spin_lock(&sbi->stat_lock); |
| 1872 | |
Jaegeuk Kim | 5fee540 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 1873 | valid_block_count = sbi->total_valid_block_count + |
| 1874 | sbi->current_reserved_blocks + 1; |
| 1875 | |
Jaegeuk Kim | c8fb245 | 2018-04-20 23:44:59 -0700 | [diff] [blame] | 1876 | if (!__allow_reserved_blocks(sbi, inode, false)) |
Chao Yu | e9a50e6 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1877 | valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; |
Jaegeuk Kim | 5fee540 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 1878 | |
| 1879 | if (unlikely(valid_block_count > sbi->user_block_count)) { |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1880 | spin_unlock(&sbi->stat_lock); |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1881 | goto enospc; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1882 | } |
| 1883 | |
Gu Zheng | ef86d70 | 2013-11-19 18:03:38 +0800 | [diff] [blame] | 1884 | valid_node_count = sbi->total_valid_node_count + 1; |
Chao Yu | cfb271d | 2013-12-05 17:15:22 +0800 | [diff] [blame] | 1885 | if (unlikely(valid_node_count > sbi->total_node_count)) { |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1886 | spin_unlock(&sbi->stat_lock); |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1887 | goto enospc; |
Chao Yu | d9bfbbb | 2017-07-06 01:11:31 +0800 | [diff] [blame] | 1888 | } |
Gu Zheng | ef86d70 | 2013-11-19 18:03:38 +0800 | [diff] [blame] | 1889 | |
Gu Zheng | ef86d70 | 2013-11-19 18:03:38 +0800 | [diff] [blame] | 1890 | sbi->total_valid_node_count++; |
| 1891 | sbi->total_valid_block_count++; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1892 | spin_unlock(&sbi->stat_lock); |
| 1893 | |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1894 | if (inode) { |
| 1895 | if (is_inode) |
| 1896 | f2fs_mark_inode_dirty_sync(inode, true); |
| 1897 | else |
| 1898 | f2fs_i_blocks_write(inode, 1, true, true); |
| 1899 | } |
| 1900 | |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 1901 | percpu_counter_inc(&sbi->alloc_valid_block_count); |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1902 | return 0; |
| 1903 | |
| 1904 | enospc: |
| 1905 | if (quota) |
| 1906 | dquot_release_reservation_block(inode, 1); |
| 1907 | return -ENOSPC; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, |
Chao Yu | d9bfbbb | 2017-07-06 01:11:31 +0800 | [diff] [blame] | 1911 | struct inode *inode, bool is_inode) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1912 | { |
| 1913 | spin_lock(&sbi->stat_lock); |
| 1914 | |
Jaegeuk Kim | 9850cf4 | 2014-09-02 15:52:58 -0700 | [diff] [blame] | 1915 | f2fs_bug_on(sbi, !sbi->total_valid_block_count); |
| 1916 | f2fs_bug_on(sbi, !sbi->total_valid_node_count); |
Chao Yu | d9bfbbb | 2017-07-06 01:11:31 +0800 | [diff] [blame] | 1917 | f2fs_bug_on(sbi, !is_inode && !inode->i_blocks); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1918 | |
Gu Zheng | ef86d70 | 2013-11-19 18:03:38 +0800 | [diff] [blame] | 1919 | sbi->total_valid_node_count--; |
| 1920 | sbi->total_valid_block_count--; |
Yunlong Song | 68ab6f8 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 1921 | if (sbi->reserved_blocks && |
| 1922 | sbi->current_reserved_blocks < sbi->reserved_blocks) |
| 1923 | sbi->current_reserved_blocks++; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1924 | |
| 1925 | spin_unlock(&sbi->stat_lock); |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1926 | |
| 1927 | if (!is_inode) |
| 1928 | f2fs_i_blocks_write(inode, 1, false, true); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) |
| 1932 | { |
Jaegeuk Kim | 8b8343f | 2014-02-24 13:00:13 +0900 | [diff] [blame] | 1933 | return sbi->total_valid_node_count; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) |
| 1937 | { |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 1938 | percpu_counter_inc(&sbi->total_valid_inode_count); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1939 | } |
| 1940 | |
Jaegeuk Kim | 0e80220 | 2013-11-26 16:36:20 +0900 | [diff] [blame] | 1941 | static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1942 | { |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 1943 | percpu_counter_dec(&sbi->total_valid_inode_count); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1944 | } |
| 1945 | |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 1946 | static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1947 | { |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 1948 | return percpu_counter_sum_positive(&sbi->total_valid_inode_count); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1949 | } |
| 1950 | |
Jaegeuk Kim | a56c7c6 | 2015-10-09 15:11:38 -0700 | [diff] [blame] | 1951 | static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, |
| 1952 | pgoff_t index, bool for_write) |
| 1953 | { |
Jaegeuk Kim | c41f3cc3 | 2016-04-29 16:17:09 -0700 | [diff] [blame] | 1954 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 1955 | struct page *page = find_lock_page(mapping, index); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1956 | |
Jaegeuk Kim | c41f3cc3 | 2016-04-29 16:17:09 -0700 | [diff] [blame] | 1957 | if (page) |
| 1958 | return page; |
| 1959 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1960 | if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { |
| 1961 | f2fs_show_injection_info(FAULT_PAGE_ALLOC); |
Jaegeuk Kim | c41f3cc3 | 2016-04-29 16:17:09 -0700 | [diff] [blame] | 1962 | return NULL; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 1963 | } |
Jaegeuk Kim | c41f3cc3 | 2016-04-29 16:17:09 -0700 | [diff] [blame] | 1964 | #endif |
Jaegeuk Kim | a56c7c6 | 2015-10-09 15:11:38 -0700 | [diff] [blame] | 1965 | if (!for_write) |
| 1966 | return grab_cache_page(mapping, index); |
| 1967 | return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); |
| 1968 | } |
| 1969 | |
Chao Yu | 58ddec8 | 2017-10-28 16:52:30 +0800 | [diff] [blame] | 1970 | static inline struct page *f2fs_pagecache_get_page( |
| 1971 | struct address_space *mapping, pgoff_t index, |
| 1972 | int fgp_flags, gfp_t gfp_mask) |
| 1973 | { |
| 1974 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 1975 | if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { |
| 1976 | f2fs_show_injection_info(FAULT_PAGE_GET); |
| 1977 | return NULL; |
| 1978 | } |
| 1979 | #endif |
| 1980 | return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); |
| 1981 | } |
| 1982 | |
Jaegeuk Kim | 6e2c64a | 2015-10-07 12:28:41 -0700 | [diff] [blame] | 1983 | static inline void f2fs_copy_page(struct page *src, struct page *dst) |
| 1984 | { |
| 1985 | char *src_kaddr = kmap(src); |
| 1986 | char *dst_kaddr = kmap(dst); |
| 1987 | |
| 1988 | memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); |
| 1989 | kunmap(dst); |
| 1990 | kunmap(src); |
| 1991 | } |
| 1992 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1993 | static inline void f2fs_put_page(struct page *page, int unlock) |
| 1994 | { |
Jaegeuk Kim | 031fa8c | 2013-11-28 12:55:13 +0900 | [diff] [blame] | 1995 | if (!page) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 1996 | return; |
| 1997 | |
| 1998 | if (unlock) { |
Jaegeuk Kim | 9850cf4 | 2014-09-02 15:52:58 -0700 | [diff] [blame] | 1999 | f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2000 | unlock_page(page); |
| 2001 | } |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2002 | put_page(page); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | static inline void f2fs_put_dnode(struct dnode_of_data *dn) |
| 2006 | { |
| 2007 | if (dn->node_page) |
| 2008 | f2fs_put_page(dn->node_page, 1); |
| 2009 | if (dn->inode_page && dn->node_page != dn->inode_page) |
| 2010 | f2fs_put_page(dn->inode_page, 0); |
| 2011 | dn->node_page = NULL; |
| 2012 | dn->inode_page = NULL; |
| 2013 | } |
| 2014 | |
| 2015 | static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, |
Gu Zheng | e8512d2 | 2014-03-07 18:43:28 +0800 | [diff] [blame] | 2016 | size_t size) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2017 | { |
Gu Zheng | e8512d2 | 2014-03-07 18:43:28 +0800 | [diff] [blame] | 2018 | return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2019 | } |
| 2020 | |
Gu Zheng | 7bd5938 | 2013-10-22 14:52:26 +0800 | [diff] [blame] | 2021 | static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, |
| 2022 | gfp_t flags) |
| 2023 | { |
| 2024 | void *entry; |
Gu Zheng | 7bd5938 | 2013-10-22 14:52:26 +0800 | [diff] [blame] | 2025 | |
Jaegeuk Kim | 80c5450 | 2015-08-20 08:51:56 -0700 | [diff] [blame] | 2026 | entry = kmem_cache_alloc(cachep, flags); |
| 2027 | if (!entry) |
| 2028 | entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); |
Gu Zheng | 7bd5938 | 2013-10-22 14:52:26 +0800 | [diff] [blame] | 2029 | return entry; |
| 2030 | } |
| 2031 | |
Chao Yu | b5db2de | 2017-10-28 16:52:31 +0800 | [diff] [blame] | 2032 | static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, |
| 2033 | int npages, bool no_fail) |
Jaegeuk Kim | 740432f | 2015-08-14 11:43:56 -0700 | [diff] [blame] | 2034 | { |
| 2035 | struct bio *bio; |
| 2036 | |
Chao Yu | b5db2de | 2017-10-28 16:52:31 +0800 | [diff] [blame] | 2037 | if (no_fail) { |
| 2038 | /* No failure on bio allocation */ |
| 2039 | bio = bio_alloc(GFP_NOIO, npages); |
| 2040 | if (!bio) |
| 2041 | bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); |
| 2042 | return bio; |
| 2043 | } |
| 2044 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 2045 | if (time_to_inject(sbi, FAULT_ALLOC_BIO)) { |
| 2046 | f2fs_show_injection_info(FAULT_ALLOC_BIO); |
| 2047 | return NULL; |
| 2048 | } |
| 2049 | #endif |
| 2050 | return bio_alloc(GFP_KERNEL, npages); |
Jaegeuk Kim | 740432f | 2015-08-14 11:43:56 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
Jaegeuk Kim | 9be32d7 | 2014-12-05 10:39:49 -0800 | [diff] [blame] | 2053 | static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, |
| 2054 | unsigned long index, void *item) |
| 2055 | { |
| 2056 | while (radix_tree_insert(root, index, item)) |
| 2057 | cond_resched(); |
| 2058 | } |
| 2059 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2060 | #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) |
| 2061 | |
| 2062 | static inline bool IS_INODE(struct page *page) |
| 2063 | { |
Gu Zheng | 4559071 | 2013-07-15 17:57:38 +0800 | [diff] [blame] | 2064 | struct f2fs_node *p = F2FS_NODE(page); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2065 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2066 | return RAW_IS_INODE(p); |
| 2067 | } |
| 2068 | |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2069 | static inline int offset_in_addr(struct f2fs_inode *i) |
| 2070 | { |
| 2071 | return (i->i_inline & F2FS_EXTRA_ATTR) ? |
| 2072 | (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; |
| 2073 | } |
| 2074 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2075 | static inline __le32 *blkaddr_in_node(struct f2fs_node *node) |
| 2076 | { |
| 2077 | return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; |
| 2078 | } |
| 2079 | |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2080 | static inline int f2fs_has_extra_attr(struct inode *inode); |
| 2081 | static inline block_t datablock_addr(struct inode *inode, |
| 2082 | struct page *node_page, unsigned int offset) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2083 | { |
| 2084 | struct f2fs_node *raw_node; |
| 2085 | __le32 *addr_array; |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2086 | int base = 0; |
| 2087 | bool is_inode = IS_INODE(node_page); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2088 | |
Gu Zheng | 4559071 | 2013-07-15 17:57:38 +0800 | [diff] [blame] | 2089 | raw_node = F2FS_NODE(node_page); |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2090 | |
| 2091 | /* from GC path only */ |
LiFan | 8234ed5 | 2017-11-28 20:17:41 +0800 | [diff] [blame] | 2092 | if (is_inode) { |
| 2093 | if (!inode) |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2094 | base = offset_in_addr(&raw_node->i); |
LiFan | 8234ed5 | 2017-11-28 20:17:41 +0800 | [diff] [blame] | 2095 | else if (f2fs_has_extra_attr(inode)) |
| 2096 | base = get_extra_isize(inode); |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2097 | } |
| 2098 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2099 | addr_array = blkaddr_in_node(raw_node); |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2100 | return le32_to_cpu(addr_array[base + offset]); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | static inline int f2fs_test_bit(unsigned int nr, char *addr) |
| 2104 | { |
| 2105 | int mask; |
| 2106 | |
| 2107 | addr += (nr >> 3); |
| 2108 | mask = 1 << (7 - (nr & 0x07)); |
| 2109 | return mask & *addr; |
| 2110 | } |
| 2111 | |
Jaegeuk Kim | a66cdd9 | 2015-04-30 22:37:50 -0700 | [diff] [blame] | 2112 | static inline void f2fs_set_bit(unsigned int nr, char *addr) |
| 2113 | { |
| 2114 | int mask; |
| 2115 | |
| 2116 | addr += (nr >> 3); |
| 2117 | mask = 1 << (7 - (nr & 0x07)); |
| 2118 | *addr |= mask; |
| 2119 | } |
| 2120 | |
| 2121 | static inline void f2fs_clear_bit(unsigned int nr, char *addr) |
| 2122 | { |
| 2123 | int mask; |
| 2124 | |
| 2125 | addr += (nr >> 3); |
| 2126 | mask = 1 << (7 - (nr & 0x07)); |
| 2127 | *addr &= ~mask; |
| 2128 | } |
| 2129 | |
Gu Zheng | 52aca07 | 2014-10-20 17:45:51 +0800 | [diff] [blame] | 2130 | static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2131 | { |
| 2132 | int mask; |
| 2133 | int ret; |
| 2134 | |
| 2135 | addr += (nr >> 3); |
| 2136 | mask = 1 << (7 - (nr & 0x07)); |
| 2137 | ret = mask & *addr; |
| 2138 | *addr |= mask; |
| 2139 | return ret; |
| 2140 | } |
| 2141 | |
Gu Zheng | 52aca07 | 2014-10-20 17:45:51 +0800 | [diff] [blame] | 2142 | static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2143 | { |
| 2144 | int mask; |
| 2145 | int ret; |
| 2146 | |
| 2147 | addr += (nr >> 3); |
| 2148 | mask = 1 << (7 - (nr & 0x07)); |
| 2149 | ret = mask & *addr; |
| 2150 | *addr &= ~mask; |
| 2151 | return ret; |
| 2152 | } |
| 2153 | |
Gu Zheng | c6ac4c0 | 2014-10-20 17:45:50 +0800 | [diff] [blame] | 2154 | static inline void f2fs_change_bit(unsigned int nr, char *addr) |
| 2155 | { |
| 2156 | int mask; |
| 2157 | |
| 2158 | addr += (nr >> 3); |
| 2159 | mask = 1 << (7 - (nr & 0x07)); |
| 2160 | *addr ^= mask; |
| 2161 | } |
| 2162 | |
Chao Yu | 9bafde6 | 2018-04-03 15:08:17 +0800 | [diff] [blame] | 2163 | /* |
| 2164 | * Inode flags |
| 2165 | */ |
| 2166 | #define F2FS_SECRM_FL 0x00000001 /* Secure deletion */ |
| 2167 | #define F2FS_UNRM_FL 0x00000002 /* Undelete */ |
| 2168 | #define F2FS_COMPR_FL 0x00000004 /* Compress file */ |
| 2169 | #define F2FS_SYNC_FL 0x00000008 /* Synchronous updates */ |
| 2170 | #define F2FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ |
| 2171 | #define F2FS_APPEND_FL 0x00000020 /* writes to file may only append */ |
| 2172 | #define F2FS_NODUMP_FL 0x00000040 /* do not dump file */ |
| 2173 | #define F2FS_NOATIME_FL 0x00000080 /* do not update atime */ |
| 2174 | /* Reserved for compression usage... */ |
| 2175 | #define F2FS_DIRTY_FL 0x00000100 |
| 2176 | #define F2FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ |
| 2177 | #define F2FS_NOCOMPR_FL 0x00000400 /* Don't compress */ |
| 2178 | #define F2FS_ENCRYPT_FL 0x00000800 /* encrypted file */ |
| 2179 | /* End compression flags --- maybe not all used */ |
| 2180 | #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ |
| 2181 | #define F2FS_IMAGIC_FL 0x00002000 /* AFS directory */ |
| 2182 | #define F2FS_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ |
| 2183 | #define F2FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */ |
| 2184 | #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ |
| 2185 | #define F2FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ |
| 2186 | #define F2FS_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ |
| 2187 | #define F2FS_EXTENTS_FL 0x00080000 /* Inode uses extents */ |
| 2188 | #define F2FS_EA_INODE_FL 0x00200000 /* Inode used for large EA */ |
| 2189 | #define F2FS_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */ |
| 2190 | #define F2FS_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */ |
| 2191 | #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ |
| 2192 | #define F2FS_RESERVED_FL 0x80000000 /* reserved for ext4 lib */ |
| 2193 | |
| 2194 | #define F2FS_FL_USER_VISIBLE 0x304BDFFF /* User visible flags */ |
| 2195 | #define F2FS_FL_USER_MODIFIABLE 0x204BC0FF /* User modifiable flags */ |
| 2196 | |
| 2197 | /* Flags we can manipulate with through F2FS_IOC_FSSETXATTR */ |
| 2198 | #define F2FS_FL_XFLAG_VISIBLE (F2FS_SYNC_FL | \ |
| 2199 | F2FS_IMMUTABLE_FL | \ |
| 2200 | F2FS_APPEND_FL | \ |
| 2201 | F2FS_NODUMP_FL | \ |
| 2202 | F2FS_NOATIME_FL | \ |
| 2203 | F2FS_PROJINHERIT_FL) |
| 2204 | |
| 2205 | /* Flags that should be inherited by new inodes from their parent. */ |
| 2206 | #define F2FS_FL_INHERITED (F2FS_SECRM_FL | F2FS_UNRM_FL | F2FS_COMPR_FL |\ |
| 2207 | F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL |\ |
| 2208 | F2FS_NOCOMPR_FL | F2FS_JOURNAL_DATA_FL |\ |
| 2209 | F2FS_NOTAIL_FL | F2FS_DIRSYNC_FL |\ |
| 2210 | F2FS_PROJINHERIT_FL) |
| 2211 | |
| 2212 | /* Flags that are appropriate for regular files (all but dir-specific ones). */ |
| 2213 | #define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_TOPDIR_FL)) |
| 2214 | |
| 2215 | /* Flags that are appropriate for non-directories/regular files. */ |
| 2216 | #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL) |
Chao Yu | 5647b30 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 2217 | |
| 2218 | static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) |
| 2219 | { |
| 2220 | if (S_ISDIR(mode)) |
| 2221 | return flags; |
| 2222 | else if (S_ISREG(mode)) |
| 2223 | return flags & F2FS_REG_FLMASK; |
| 2224 | else |
| 2225 | return flags & F2FS_OTHER_FLMASK; |
| 2226 | } |
| 2227 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2228 | /* used for f2fs_inode_info->flags */ |
| 2229 | enum { |
| 2230 | FI_NEW_INODE, /* indicate newly allocated inode */ |
Jaegeuk Kim | b378387 | 2013-06-10 09:17:01 +0900 | [diff] [blame] | 2231 | FI_DIRTY_INODE, /* indicate inode is dirty or not */ |
Jaegeuk Kim | 26de9b1 | 2016-05-20 20:42:37 -0700 | [diff] [blame] | 2232 | FI_AUTO_RECOVER, /* indicate inode is recoverable */ |
Jaegeuk Kim | ed57c27 | 2014-04-15 11:19:28 +0900 | [diff] [blame] | 2233 | FI_DIRTY_DIR, /* indicate directory has dirty pages */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2234 | FI_INC_LINK, /* need to increment i_nlink */ |
| 2235 | FI_ACL_MODE, /* indicate acl mode */ |
| 2236 | FI_NO_ALLOC, /* should not allocate any blocks */ |
Jaegeuk Kim | c9b63bd | 2015-06-23 10:36:08 -0700 | [diff] [blame] | 2237 | FI_FREE_NID, /* free allocated nide */ |
Jaegeuk Kim | c11abd1 | 2013-11-19 10:41:54 +0900 | [diff] [blame] | 2238 | FI_NO_EXTENT, /* not to use the extent cache */ |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 2239 | FI_INLINE_XATTR, /* used for inline xattr */ |
Huajun Li | 1001b34 | 2013-11-10 23:13:16 +0800 | [diff] [blame] | 2240 | FI_INLINE_DATA, /* used for inline data*/ |
Chao Yu | 34d67de | 2014-09-24 18:15:19 +0800 | [diff] [blame] | 2241 | FI_INLINE_DENTRY, /* used for inline dentry */ |
Jaegeuk Kim | fff04f9 | 2014-07-25 07:40:59 -0700 | [diff] [blame] | 2242 | FI_APPEND_WRITE, /* inode has appended data */ |
| 2243 | FI_UPDATE_WRITE, /* inode has in-place-update data */ |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 2244 | FI_NEED_IPU, /* used for ipu per file */ |
| 2245 | FI_ATOMIC_FILE, /* indicate atomic file */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2246 | FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ |
Jaegeuk Kim | 02a1335 | 2014-10-06 16:11:16 -0700 | [diff] [blame] | 2247 | FI_VOLATILE_FILE, /* indicate volatile file */ |
Jaegeuk Kim | 3c6c2be | 2015-03-17 17:16:35 -0700 | [diff] [blame] | 2248 | FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 2249 | FI_DROP_CACHE, /* drop dirty page cache */ |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 2250 | FI_DATA_EXIST, /* indicate data exists */ |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 2251 | FI_INLINE_DOTS, /* indicate inline dot dentries */ |
Chao Yu | d323d00 | 2015-10-27 09:53:45 +0800 | [diff] [blame] | 2252 | FI_DO_DEFRAG, /* indicate defragment is running */ |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 2253 | FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2254 | FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ |
| 2255 | FI_HOT_DATA, /* indicate file is hot */ |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2256 | FI_EXTRA_ATTR, /* indicate file has extra attribute */ |
Chao Yu | 5647b30 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 2257 | FI_PROJ_INHERIT, /* indicate file inherits projectid */ |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 2258 | FI_PIN_FILE, /* indicate file should not be gced */ |
Chao Yu | caf10c6 | 2018-05-07 20:28:54 +0800 | [diff] [blame] | 2259 | FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2260 | }; |
| 2261 | |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2262 | static inline void __mark_inode_dirty_flag(struct inode *inode, |
| 2263 | int flag, bool set) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2264 | { |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2265 | switch (flag) { |
| 2266 | case FI_INLINE_XATTR: |
| 2267 | case FI_INLINE_DATA: |
| 2268 | case FI_INLINE_DENTRY: |
Daeho Jeong | 9ef5e65 | 2018-01-11 11:26:19 +0900 | [diff] [blame] | 2269 | case FI_NEW_INODE: |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2270 | if (set) |
| 2271 | return; |
| 2272 | case FI_DATA_EXIST: |
| 2273 | case FI_INLINE_DOTS: |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 2274 | case FI_PIN_FILE: |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2275 | f2fs_mark_inode_dirty_sync(inode, true); |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2276 | } |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2277 | } |
| 2278 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2279 | static inline void set_inode_flag(struct inode *inode, int flag) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2280 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2281 | if (!test_bit(flag, &F2FS_I(inode)->flags)) |
| 2282 | set_bit(flag, &F2FS_I(inode)->flags); |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2283 | __mark_inode_dirty_flag(inode, flag, true); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2284 | } |
| 2285 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2286 | static inline int is_inode_flag_set(struct inode *inode, int flag) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2287 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2288 | return test_bit(flag, &F2FS_I(inode)->flags); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2289 | } |
| 2290 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2291 | static inline void clear_inode_flag(struct inode *inode, int flag) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2292 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2293 | if (test_bit(flag, &F2FS_I(inode)->flags)) |
| 2294 | clear_bit(flag, &F2FS_I(inode)->flags); |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2295 | __mark_inode_dirty_flag(inode, flag, false); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2296 | } |
| 2297 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2298 | static inline void set_acl_inode(struct inode *inode, umode_t mode) |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 2299 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2300 | F2FS_I(inode)->i_acl_mode = mode; |
| 2301 | set_inode_flag(inode, FI_ACL_MODE); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2302 | f2fs_mark_inode_dirty_sync(inode, false); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2303 | } |
| 2304 | |
Jaegeuk Kim | a196124 | 2016-05-20 09:43:20 -0700 | [diff] [blame] | 2305 | static inline void f2fs_i_links_write(struct inode *inode, bool inc) |
| 2306 | { |
| 2307 | if (inc) |
| 2308 | inc_nlink(inode); |
| 2309 | else |
| 2310 | drop_nlink(inode); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2311 | f2fs_mark_inode_dirty_sync(inode, true); |
Jaegeuk Kim | a196124 | 2016-05-20 09:43:20 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
Jaegeuk Kim | 8edd03c | 2016-05-20 09:26:06 -0700 | [diff] [blame] | 2314 | static inline void f2fs_i_blocks_write(struct inode *inode, |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2315 | block_t diff, bool add, bool claim) |
Jaegeuk Kim | 8edd03c | 2016-05-20 09:26:06 -0700 | [diff] [blame] | 2316 | { |
Jaegeuk Kim | 26de9b1 | 2016-05-20 20:42:37 -0700 | [diff] [blame] | 2317 | bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); |
| 2318 | bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); |
| 2319 | |
Chao Yu | 09c3a72 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2320 | /* add = 1, claim = 1 should be dquot_reserve_block in pair */ |
| 2321 | if (add) { |
| 2322 | if (claim) |
| 2323 | dquot_claim_block(inode, diff); |
| 2324 | else |
| 2325 | dquot_alloc_block_nofail(inode, diff); |
| 2326 | } else { |
| 2327 | dquot_free_block(inode, diff); |
| 2328 | } |
| 2329 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2330 | f2fs_mark_inode_dirty_sync(inode, true); |
Jaegeuk Kim | 26de9b1 | 2016-05-20 20:42:37 -0700 | [diff] [blame] | 2331 | if (clean || recover) |
| 2332 | set_inode_flag(inode, FI_AUTO_RECOVER); |
Jaegeuk Kim | 8edd03c | 2016-05-20 09:26:06 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
Jaegeuk Kim | fc9581c | 2016-05-20 09:22:03 -0700 | [diff] [blame] | 2335 | static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) |
| 2336 | { |
Jaegeuk Kim | 26de9b1 | 2016-05-20 20:42:37 -0700 | [diff] [blame] | 2337 | bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); |
| 2338 | bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); |
| 2339 | |
Jaegeuk Kim | fc9581c | 2016-05-20 09:22:03 -0700 | [diff] [blame] | 2340 | if (i_size_read(inode) == i_size) |
| 2341 | return; |
| 2342 | |
| 2343 | i_size_write(inode, i_size); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2344 | f2fs_mark_inode_dirty_sync(inode, true); |
Jaegeuk Kim | 26de9b1 | 2016-05-20 20:42:37 -0700 | [diff] [blame] | 2345 | if (clean || recover) |
| 2346 | set_inode_flag(inode, FI_AUTO_RECOVER); |
| 2347 | } |
| 2348 | |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2349 | static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) |
| 2350 | { |
| 2351 | F2FS_I(inode)->i_current_depth = depth; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2352 | f2fs_mark_inode_dirty_sync(inode, true); |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 2355 | static inline void f2fs_i_gc_failures_write(struct inode *inode, |
| 2356 | unsigned int count) |
| 2357 | { |
Chao Yu | caf10c6 | 2018-05-07 20:28:54 +0800 | [diff] [blame] | 2358 | F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count; |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 2359 | f2fs_mark_inode_dirty_sync(inode, true); |
| 2360 | } |
| 2361 | |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2362 | static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) |
| 2363 | { |
| 2364 | F2FS_I(inode)->i_xattr_nid = xnid; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2365 | f2fs_mark_inode_dirty_sync(inode, true); |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) |
| 2369 | { |
| 2370 | F2FS_I(inode)->i_pino = pino; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2371 | f2fs_mark_inode_dirty_sync(inode, true); |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2372 | } |
| 2373 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2374 | static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 2375 | { |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2376 | struct f2fs_inode_info *fi = F2FS_I(inode); |
| 2377 | |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 2378 | if (ri->i_inline & F2FS_INLINE_XATTR) |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2379 | set_bit(FI_INLINE_XATTR, &fi->flags); |
Huajun Li | 1001b34 | 2013-11-10 23:13:16 +0800 | [diff] [blame] | 2380 | if (ri->i_inline & F2FS_INLINE_DATA) |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2381 | set_bit(FI_INLINE_DATA, &fi->flags); |
Chao Yu | 34d67de | 2014-09-24 18:15:19 +0800 | [diff] [blame] | 2382 | if (ri->i_inline & F2FS_INLINE_DENTRY) |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2383 | set_bit(FI_INLINE_DENTRY, &fi->flags); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 2384 | if (ri->i_inline & F2FS_DATA_EXIST) |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2385 | set_bit(FI_DATA_EXIST, &fi->flags); |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 2386 | if (ri->i_inline & F2FS_INLINE_DOTS) |
Jaegeuk Kim | 205b982 | 2016-05-20 09:52:20 -0700 | [diff] [blame] | 2387 | set_bit(FI_INLINE_DOTS, &fi->flags); |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2388 | if (ri->i_inline & F2FS_EXTRA_ATTR) |
| 2389 | set_bit(FI_EXTRA_ATTR, &fi->flags); |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 2390 | if (ri->i_inline & F2FS_PIN_FILE) |
| 2391 | set_bit(FI_PIN_FILE, &fi->flags); |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 2392 | } |
| 2393 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2394 | static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 2395 | { |
| 2396 | ri->i_inline = 0; |
| 2397 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2398 | if (is_inode_flag_set(inode, FI_INLINE_XATTR)) |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 2399 | ri->i_inline |= F2FS_INLINE_XATTR; |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2400 | if (is_inode_flag_set(inode, FI_INLINE_DATA)) |
Huajun Li | 1001b34 | 2013-11-10 23:13:16 +0800 | [diff] [blame] | 2401 | ri->i_inline |= F2FS_INLINE_DATA; |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2402 | if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) |
Chao Yu | 34d67de | 2014-09-24 18:15:19 +0800 | [diff] [blame] | 2403 | ri->i_inline |= F2FS_INLINE_DENTRY; |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2404 | if (is_inode_flag_set(inode, FI_DATA_EXIST)) |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 2405 | ri->i_inline |= F2FS_DATA_EXIST; |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2406 | if (is_inode_flag_set(inode, FI_INLINE_DOTS)) |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 2407 | ri->i_inline |= F2FS_INLINE_DOTS; |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2408 | if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) |
| 2409 | ri->i_inline |= F2FS_EXTRA_ATTR; |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 2410 | if (is_inode_flag_set(inode, FI_PIN_FILE)) |
| 2411 | ri->i_inline |= F2FS_PIN_FILE; |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | static inline int f2fs_has_extra_attr(struct inode *inode) |
| 2415 | { |
| 2416 | return is_inode_flag_set(inode, FI_EXTRA_ATTR); |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 2417 | } |
| 2418 | |
Chao Yu | 987c7c3 | 2014-03-12 15:59:03 +0800 | [diff] [blame] | 2419 | static inline int f2fs_has_inline_xattr(struct inode *inode) |
| 2420 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2421 | return is_inode_flag_set(inode, FI_INLINE_XATTR); |
Chao Yu | 987c7c3 | 2014-03-12 15:59:03 +0800 | [diff] [blame] | 2422 | } |
| 2423 | |
Chao Yu | 81ca735 | 2016-01-26 15:39:35 +0800 | [diff] [blame] | 2424 | static inline unsigned int addrs_per_inode(struct inode *inode) |
Jaegeuk Kim | de93653 | 2013-08-12 21:08:03 +0900 | [diff] [blame] | 2425 | { |
Chao Yu | 3aa46e2 | 2018-01-17 16:31:36 +0800 | [diff] [blame] | 2426 | return CUR_ADDRS_PER_INODE(inode) - get_inline_xattr_addrs(inode); |
Jaegeuk Kim | de93653 | 2013-08-12 21:08:03 +0900 | [diff] [blame] | 2427 | } |
| 2428 | |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 2429 | static inline void *inline_xattr_addr(struct inode *inode, struct page *page) |
Jaegeuk Kim | 65985d9 | 2013-08-14 21:57:27 +0900 | [diff] [blame] | 2430 | { |
Chao Yu | 695fd1e | 2014-02-27 19:52:21 +0800 | [diff] [blame] | 2431 | struct f2fs_inode *ri = F2FS_INODE(page); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2432 | |
Jaegeuk Kim | 65985d9 | 2013-08-14 21:57:27 +0900 | [diff] [blame] | 2433 | return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - |
Chao Yu | 3aa46e2 | 2018-01-17 16:31:36 +0800 | [diff] [blame] | 2434 | get_inline_xattr_addrs(inode)]); |
Jaegeuk Kim | 65985d9 | 2013-08-14 21:57:27 +0900 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | static inline int inline_xattr_size(struct inode *inode) |
| 2438 | { |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 2439 | return get_inline_xattr_addrs(inode) * sizeof(__le32); |
Jaegeuk Kim | 65985d9 | 2013-08-14 21:57:27 +0900 | [diff] [blame] | 2440 | } |
| 2441 | |
Jaegeuk Kim | 0dbdc2a | 2013-11-26 11:08:57 +0900 | [diff] [blame] | 2442 | static inline int f2fs_has_inline_data(struct inode *inode) |
| 2443 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2444 | return is_inode_flag_set(inode, FI_INLINE_DATA); |
Jaegeuk Kim | 0dbdc2a | 2013-11-26 11:08:57 +0900 | [diff] [blame] | 2445 | } |
| 2446 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 2447 | static inline int f2fs_exist_data(struct inode *inode) |
| 2448 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2449 | return is_inode_flag_set(inode, FI_DATA_EXIST); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 2450 | } |
| 2451 | |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 2452 | static inline int f2fs_has_inline_dots(struct inode *inode) |
| 2453 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2454 | return is_inode_flag_set(inode, FI_INLINE_DOTS); |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 2457 | static inline bool f2fs_is_pinned_file(struct inode *inode) |
| 2458 | { |
| 2459 | return is_inode_flag_set(inode, FI_PIN_FILE); |
| 2460 | } |
| 2461 | |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 2462 | static inline bool f2fs_is_atomic_file(struct inode *inode) |
| 2463 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2464 | return is_inode_flag_set(inode, FI_ATOMIC_FILE); |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2467 | static inline bool f2fs_is_commit_atomic_write(struct inode *inode) |
| 2468 | { |
| 2469 | return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); |
| 2470 | } |
| 2471 | |
Jaegeuk Kim | 02a1335 | 2014-10-06 16:11:16 -0700 | [diff] [blame] | 2472 | static inline bool f2fs_is_volatile_file(struct inode *inode) |
| 2473 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2474 | return is_inode_flag_set(inode, FI_VOLATILE_FILE); |
Jaegeuk Kim | 02a1335 | 2014-10-06 16:11:16 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
Jaegeuk Kim | 3c6c2be | 2015-03-17 17:16:35 -0700 | [diff] [blame] | 2477 | static inline bool f2fs_is_first_block_written(struct inode *inode) |
| 2478 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2479 | return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); |
Jaegeuk Kim | 3c6c2be | 2015-03-17 17:16:35 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 2482 | static inline bool f2fs_is_drop_cache(struct inode *inode) |
| 2483 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2484 | return is_inode_flag_set(inode, FI_DROP_CACHE); |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 2485 | } |
| 2486 | |
Chao Yu | e84f88e | 2017-07-19 00:19:05 +0800 | [diff] [blame] | 2487 | static inline void *inline_data_addr(struct inode *inode, struct page *page) |
Huajun Li | 1001b34 | 2013-11-10 23:13:16 +0800 | [diff] [blame] | 2488 | { |
Chao Yu | 695fd1e | 2014-02-27 19:52:21 +0800 | [diff] [blame] | 2489 | struct f2fs_inode *ri = F2FS_INODE(page); |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2490 | int extra_size = get_extra_isize(inode); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2491 | |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2492 | return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); |
Huajun Li | 1001b34 | 2013-11-10 23:13:16 +0800 | [diff] [blame] | 2493 | } |
| 2494 | |
Chao Yu | 34d67de | 2014-09-24 18:15:19 +0800 | [diff] [blame] | 2495 | static inline int f2fs_has_inline_dentry(struct inode *inode) |
| 2496 | { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2497 | return is_inode_flag_set(inode, FI_INLINE_DENTRY); |
Chao Yu | 34d67de | 2014-09-24 18:15:19 +0800 | [diff] [blame] | 2498 | } |
| 2499 | |
Jaegeuk Kim | b5492af7 | 2015-04-20 13:44:41 -0700 | [diff] [blame] | 2500 | static inline int is_file(struct inode *inode, int type) |
| 2501 | { |
| 2502 | return F2FS_I(inode)->i_advise & type; |
| 2503 | } |
| 2504 | |
| 2505 | static inline void set_file(struct inode *inode, int type) |
| 2506 | { |
| 2507 | F2FS_I(inode)->i_advise |= type; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2508 | f2fs_mark_inode_dirty_sync(inode, true); |
Jaegeuk Kim | b5492af7 | 2015-04-20 13:44:41 -0700 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | static inline void clear_file(struct inode *inode, int type) |
| 2512 | { |
| 2513 | F2FS_I(inode)->i_advise &= ~type; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2514 | f2fs_mark_inode_dirty_sync(inode, true); |
| 2515 | } |
| 2516 | |
| 2517 | static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) |
| 2518 | { |
Chao Yu | 33fdebb | 2017-10-09 17:55:19 +0800 | [diff] [blame] | 2519 | bool ret; |
| 2520 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2521 | if (dsync) { |
| 2522 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2523 | |
| 2524 | spin_lock(&sbi->inode_lock[DIRTY_META]); |
| 2525 | ret = list_empty(&F2FS_I(inode)->gdirty_list); |
| 2526 | spin_unlock(&sbi->inode_lock[DIRTY_META]); |
| 2527 | return ret; |
| 2528 | } |
| 2529 | if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || |
| 2530 | file_keep_isize(inode) || |
Junling Zheng | 4478970 | 2018-03-29 19:27:12 +0800 | [diff] [blame] | 2531 | i_size_read(inode) & ~PAGE_MASK) |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2532 | return false; |
Chao Yu | 33fdebb | 2017-10-09 17:55:19 +0800 | [diff] [blame] | 2533 | |
Jaegeuk Kim | ac389af | 2018-03-29 22:50:41 -0700 | [diff] [blame] | 2534 | if (!timespec_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime)) |
| 2535 | return false; |
| 2536 | if (!timespec_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime)) |
| 2537 | return false; |
| 2538 | if (!timespec_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime)) |
| 2539 | return false; |
| 2540 | if (!timespec_equal(F2FS_I(inode)->i_disk_time + 3, |
| 2541 | &F2FS_I(inode)->i_crtime)) |
| 2542 | return false; |
| 2543 | |
Chao Yu | 33fdebb | 2017-10-09 17:55:19 +0800 | [diff] [blame] | 2544 | down_read(&F2FS_I(inode)->i_sem); |
| 2545 | ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); |
| 2546 | up_read(&F2FS_I(inode)->i_sem); |
| 2547 | |
| 2548 | return ret; |
Jaegeuk Kim | b5492af7 | 2015-04-20 13:44:41 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
Chao Yu | 8f711c3 | 2018-03-01 23:40:31 +0800 | [diff] [blame] | 2551 | static inline bool f2fs_readonly(struct super_block *sb) |
Jaegeuk Kim | 77888c1 | 2013-05-20 20:28:47 +0900 | [diff] [blame] | 2552 | { |
| 2553 | return sb->s_flags & MS_RDONLY; |
| 2554 | } |
| 2555 | |
Jaegeuk Kim | 1e968fd | 2014-08-11 16:49:25 -0700 | [diff] [blame] | 2556 | static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) |
| 2557 | { |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 2558 | return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); |
Jaegeuk Kim | 1e968fd | 2014-08-11 16:49:25 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
Jaegeuk Kim | eaa693f | 2015-04-26 00:15:29 -0700 | [diff] [blame] | 2561 | static inline bool is_dot_dotdot(const struct qstr *str) |
| 2562 | { |
| 2563 | if (str->len == 1 && str->name[0] == '.') |
| 2564 | return true; |
| 2565 | |
| 2566 | if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') |
| 2567 | return true; |
| 2568 | |
| 2569 | return false; |
| 2570 | } |
| 2571 | |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 2572 | static inline bool f2fs_may_extent_tree(struct inode *inode) |
| 2573 | { |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 2574 | if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2575 | is_inode_flag_set(inode, FI_NO_EXTENT)) |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 2576 | return false; |
| 2577 | |
Al Viro | 886f56f | 2015-12-05 03:56:06 -0500 | [diff] [blame] | 2578 | return S_ISREG(inode->i_mode); |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 2581 | static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, |
| 2582 | size_t size, gfp_t flags) |
Jaegeuk Kim | 0414b00 | 2016-04-29 15:16:42 -0700 | [diff] [blame] | 2583 | { |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 2584 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2585 | if (time_to_inject(sbi, FAULT_KMALLOC)) { |
| 2586 | f2fs_show_injection_info(FAULT_KMALLOC); |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 2587 | return NULL; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2588 | } |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 2589 | #endif |
Jaegeuk Kim | 0414b00 | 2016-04-29 15:16:42 -0700 | [diff] [blame] | 2590 | return kmalloc(size, flags); |
| 2591 | } |
| 2592 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2593 | static inline void *kvmalloc(size_t size, gfp_t flags) |
Jaegeuk Kim | 39307a8 | 2015-09-22 13:50:47 -0700 | [diff] [blame] | 2594 | { |
| 2595 | void *ret; |
| 2596 | |
| 2597 | ret = kmalloc(size, flags | __GFP_NOWARN); |
| 2598 | if (!ret) |
| 2599 | ret = __vmalloc(size, flags, PAGE_KERNEL); |
| 2600 | return ret; |
| 2601 | } |
| 2602 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2603 | static inline void *kvzalloc(size_t size, gfp_t flags) |
Jaegeuk Kim | 39307a8 | 2015-09-22 13:50:47 -0700 | [diff] [blame] | 2604 | { |
| 2605 | void *ret; |
| 2606 | |
| 2607 | ret = kzalloc(size, flags | __GFP_NOWARN); |
| 2608 | if (!ret) |
| 2609 | ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); |
| 2610 | return ret; |
| 2611 | } |
| 2612 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2613 | static inline int wbc_to_write_flags(struct writeback_control *wbc) |
| 2614 | { |
| 2615 | if (wbc->sync_mode == WB_SYNC_ALL) |
| 2616 | return REQ_SYNC; |
| 2617 | else if (wbc->for_kupdate || wbc->for_background) |
| 2618 | return 0; |
| 2619 | |
| 2620 | return 0; |
| 2621 | } |
| 2622 | |
Chao Yu | e585ca2 | 2017-11-30 19:28:17 +0800 | [diff] [blame] | 2623 | static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, |
| 2624 | size_t size, gfp_t flags) |
| 2625 | { |
| 2626 | return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); |
| 2627 | } |
| 2628 | |
Chao Yu | ead5259 | 2017-11-30 19:28:18 +0800 | [diff] [blame] | 2629 | static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, |
| 2630 | size_t size, gfp_t flags) |
| 2631 | { |
| 2632 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 2633 | if (time_to_inject(sbi, FAULT_KVMALLOC)) { |
| 2634 | f2fs_show_injection_info(FAULT_KVMALLOC); |
| 2635 | return NULL; |
| 2636 | } |
| 2637 | #endif |
| 2638 | return kvmalloc(size, flags); |
| 2639 | } |
| 2640 | |
| 2641 | static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi, |
| 2642 | size_t size, gfp_t flags) |
| 2643 | { |
| 2644 | return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO); |
| 2645 | } |
| 2646 | |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2647 | static inline int get_extra_isize(struct inode *inode) |
Chao Yu | e84f88e | 2017-07-19 00:19:05 +0800 | [diff] [blame] | 2648 | { |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2649 | return F2FS_I(inode)->i_extra_isize / sizeof(__le32); |
Chao Yu | e84f88e | 2017-07-19 00:19:05 +0800 | [diff] [blame] | 2650 | } |
| 2651 | |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 2652 | static inline int get_inline_xattr_addrs(struct inode *inode) |
| 2653 | { |
| 2654 | return F2FS_I(inode)->i_inline_xattr_size; |
| 2655 | } |
| 2656 | |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2657 | #define f2fs_get_inode_mode(i) \ |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 2658 | ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ |
Christoph Hellwig | a6dda0e | 2013-12-20 05:16:45 -0800 | [diff] [blame] | 2659 | (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) |
| 2660 | |
Chao Yu | fbcf931 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2661 | #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ |
| 2662 | (offsetof(struct f2fs_inode, i_extra_end) - \ |
| 2663 | offsetof(struct f2fs_inode, i_extra_isize)) \ |
| 2664 | |
Chao Yu | 5647b30 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 2665 | #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) |
| 2666 | #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ |
| 2667 | ((offsetof(typeof(*f2fs_inode), field) + \ |
| 2668 | sizeof((f2fs_inode)->field)) \ |
| 2669 | <= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize)) \ |
| 2670 | |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 2671 | static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) |
| 2672 | { |
| 2673 | int i; |
| 2674 | |
| 2675 | spin_lock(&sbi->iostat_lock); |
| 2676 | for (i = 0; i < NR_IO_TYPE; i++) |
| 2677 | sbi->write_iostat[i] = 0; |
| 2678 | spin_unlock(&sbi->iostat_lock); |
| 2679 | } |
| 2680 | |
| 2681 | static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, |
| 2682 | enum iostat_type type, unsigned long long io_bytes) |
| 2683 | { |
| 2684 | if (!sbi->iostat_enable) |
| 2685 | return; |
| 2686 | spin_lock(&sbi->iostat_lock); |
| 2687 | sbi->write_iostat[type] += io_bytes; |
| 2688 | |
| 2689 | if (type == APP_WRITE_IO || type == APP_DIRECT_IO) |
| 2690 | sbi->write_iostat[APP_BUFFERED_IO] = |
| 2691 | sbi->write_iostat[APP_WRITE_IO] - |
| 2692 | sbi->write_iostat[APP_DIRECT_IO]; |
| 2693 | spin_unlock(&sbi->iostat_lock); |
| 2694 | } |
| 2695 | |
Chao Yu | 158d9bb | 2018-05-23 22:25:08 +0800 | [diff] [blame] | 2696 | static inline bool is_valid_blkaddr(block_t blkaddr) |
| 2697 | { |
| 2698 | if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) |
| 2699 | return false; |
| 2700 | return true; |
| 2701 | } |
| 2702 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2703 | /* |
| 2704 | * file.c |
| 2705 | */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2706 | int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2707 | void f2fs_truncate_data_blocks(struct dnode_of_data *dn); |
| 2708 | int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2709 | int f2fs_truncate(struct inode *inode); |
| 2710 | int f2fs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 2711 | struct kstat *stat); |
| 2712 | int f2fs_setattr(struct dentry *dentry, struct iattr *attr); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2713 | int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); |
| 2714 | void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); |
Chao Yu | 6bce963 | 2018-01-11 14:42:30 +0800 | [diff] [blame] | 2715 | int f2fs_precache_extents(struct inode *inode); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2716 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); |
| 2717 | long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 2718 | int f2fs_pin_file_control(struct inode *inode, bool inc); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2719 | |
| 2720 | /* |
| 2721 | * inode.c |
| 2722 | */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2723 | void f2fs_set_inode_flags(struct inode *inode); |
Chao Yu | 4310125 | 2017-07-31 20:19:09 +0800 | [diff] [blame] | 2724 | bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); |
| 2725 | void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2726 | struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); |
| 2727 | struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2728 | int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); |
| 2729 | void f2fs_update_inode(struct inode *inode, struct page *node_page); |
| 2730 | void f2fs_update_inode_page(struct inode *inode); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2731 | int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); |
| 2732 | void f2fs_evict_inode(struct inode *inode); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2733 | void f2fs_handle_failed_inode(struct inode *inode); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2734 | |
| 2735 | /* |
| 2736 | * namei.c |
| 2737 | */ |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2738 | int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, |
Chao Yu | ac734c4 | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 2739 | bool hot, bool set); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2740 | struct dentry *f2fs_get_parent(struct dentry *child); |
| 2741 | |
| 2742 | /* |
| 2743 | * dir.c |
| 2744 | */ |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2745 | unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de); |
| 2746 | struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2747 | f2fs_hash_t namehash, int *max_slots, |
| 2748 | struct f2fs_dentry_ptr *d); |
| 2749 | int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, |
| 2750 | unsigned int start_pos, struct fscrypt_str *fstr); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2751 | void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2752 | struct f2fs_dentry_ptr *d); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2753 | struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2754 | const struct qstr *new_name, |
| 2755 | const struct qstr *orig_name, struct page *dpage); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2756 | void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2757 | unsigned int current_depth); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2758 | int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2759 | void f2fs_drop_nlink(struct inode *dir, struct inode *inode); |
| 2760 | struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, |
| 2761 | struct fscrypt_name *fname, struct page **res_page); |
| 2762 | struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, |
| 2763 | const struct qstr *child, struct page **res_page); |
| 2764 | struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); |
| 2765 | ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, |
| 2766 | struct page **page); |
| 2767 | void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, |
| 2768 | struct page *page, struct inode *inode); |
| 2769 | void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, |
| 2770 | const struct qstr *name, f2fs_hash_t name_hash, |
| 2771 | unsigned int bit_pos); |
| 2772 | int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, |
| 2773 | const struct qstr *orig_name, |
| 2774 | struct inode *inode, nid_t ino, umode_t mode); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2775 | int f2fs_add_dentry(struct inode *dir, struct fscrypt_name *fname, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2776 | struct inode *inode, nid_t ino, umode_t mode); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2777 | int f2fs_do_add_link(struct inode *dir, const struct qstr *name, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2778 | struct inode *inode, nid_t ino, umode_t mode); |
| 2779 | void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, |
| 2780 | struct inode *dir, struct inode *inode); |
| 2781 | int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); |
| 2782 | bool f2fs_empty_dir(struct inode *dir); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2783 | |
Al Viro | b7f7a5e | 2013-01-25 16:15:43 -0500 | [diff] [blame] | 2784 | static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) |
| 2785 | { |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2786 | return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name, |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 2787 | inode, inode->i_ino, inode->i_mode); |
Al Viro | b7f7a5e | 2013-01-25 16:15:43 -0500 | [diff] [blame] | 2788 | } |
| 2789 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2790 | /* |
| 2791 | * super.c |
| 2792 | */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2793 | int f2fs_inode_dirtied(struct inode *inode, bool sync); |
| 2794 | void f2fs_inode_synced(struct inode *inode); |
Jaegeuk Kim | 0108c48 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2795 | int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); |
Chao Yu | 41ad73f | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2796 | void f2fs_quota_off_umount(struct super_block *sb); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2797 | int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); |
| 2798 | int f2fs_sync_fs(struct super_block *sb, int sync); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2799 | extern __printf(3, 4) |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2800 | void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2801 | int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2802 | |
| 2803 | /* |
| 2804 | * hash.c |
| 2805 | */ |
Jaegeuk Kim | 8daed21 | 2017-04-24 10:00:08 -0700 | [diff] [blame] | 2806 | f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, |
| 2807 | struct fscrypt_name *fname); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2808 | |
| 2809 | /* |
| 2810 | * node.c |
| 2811 | */ |
| 2812 | struct dnode_of_data; |
| 2813 | struct node_info; |
| 2814 | |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2815 | int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid); |
| 2816 | bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type); |
| 2817 | int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); |
| 2818 | bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); |
| 2819 | bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); |
| 2820 | void f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, |
| 2821 | struct node_info *ni); |
| 2822 | pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); |
| 2823 | int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); |
| 2824 | int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from); |
| 2825 | int f2fs_truncate_xattr_node(struct inode *inode); |
| 2826 | int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); |
| 2827 | int f2fs_remove_inode_page(struct inode *inode); |
| 2828 | struct page *f2fs_new_inode_page(struct inode *inode); |
| 2829 | struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs); |
| 2830 | void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); |
| 2831 | struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); |
| 2832 | struct page *f2fs_get_node_page_ra(struct page *parent, int start); |
| 2833 | void f2fs_move_node_page(struct page *node_page, int gc_type); |
| 2834 | int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2835 | struct writeback_control *wbc, bool atomic); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2836 | int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, |
| 2837 | struct writeback_control *wbc, |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 2838 | bool do_balance, enum iostat_type io_type); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2839 | void f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); |
| 2840 | bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); |
| 2841 | void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); |
| 2842 | void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); |
| 2843 | int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); |
| 2844 | void f2fs_recover_inline_xattr(struct inode *inode, struct page *page); |
| 2845 | int f2fs_recover_xattr_data(struct inode *inode, struct page *page); |
| 2846 | int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); |
| 2847 | void f2fs_restore_node_summary(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2848 | unsigned int segno, struct f2fs_summary_block *sum); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2849 | void f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); |
| 2850 | int f2fs_build_node_manager(struct f2fs_sb_info *sbi); |
| 2851 | void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi); |
| 2852 | int __init f2fs_create_node_manager_caches(void); |
| 2853 | void f2fs_destroy_node_manager_caches(void); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2854 | |
| 2855 | /* |
| 2856 | * segment.c |
| 2857 | */ |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2858 | bool f2fs_need_SSR(struct f2fs_sb_info *sbi); |
| 2859 | void f2fs_register_inmem_page(struct inode *inode, struct page *page); |
| 2860 | void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure); |
| 2861 | void f2fs_drop_inmem_pages(struct inode *inode); |
| 2862 | void f2fs_drop_inmem_page(struct inode *inode, struct page *page); |
| 2863 | int f2fs_commit_inmem_pages(struct inode *inode); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2864 | void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); |
| 2865 | void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); |
Chao Yu | f014be8 | 2017-09-29 13:59:38 +0800 | [diff] [blame] | 2866 | int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2867 | int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi); |
Chao Yu | fd6422e | 2017-09-29 13:59:39 +0800 | [diff] [blame] | 2868 | int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2869 | void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); |
| 2870 | void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); |
| 2871 | bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); |
| 2872 | void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi); |
| 2873 | void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi); |
Chao Yu | 1e5305a | 2017-10-04 09:08:37 +0800 | [diff] [blame] | 2874 | bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2875 | void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, |
| 2876 | struct cp_control *cpc); |
| 2877 | void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi); |
| 2878 | int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); |
| 2879 | void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2880 | int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2881 | bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, |
| 2882 | struct cp_control *cpc); |
| 2883 | struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); |
| 2884 | void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src, |
| 2885 | block_t blk_addr); |
| 2886 | void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page, |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 2887 | enum iostat_type io_type); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2888 | void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio); |
| 2889 | void f2fs_outplace_write_data(struct dnode_of_data *dn, |
| 2890 | struct f2fs_io_info *fio); |
| 2891 | int f2fs_inplace_write_data(struct f2fs_io_info *fio); |
| 2892 | void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2893 | block_t old_blkaddr, block_t new_blkaddr, |
| 2894 | bool recover_curseg, bool recover_newaddr); |
| 2895 | void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, |
| 2896 | block_t old_addr, block_t new_addr, |
| 2897 | unsigned char version, bool recover_curseg, |
| 2898 | bool recover_newaddr); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2899 | void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2900 | block_t old_blkaddr, block_t *new_blkaddr, |
Chao Yu | c52dc0f | 2017-05-19 23:37:01 +0800 | [diff] [blame] | 2901 | struct f2fs_summary *sum, int type, |
| 2902 | struct f2fs_io_info *fio, bool add_list); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2903 | void f2fs_wait_on_page_writeback(struct page *page, |
| 2904 | enum page_type type, bool ordered); |
Jaegeuk Kim | fb605d0 | 2017-09-05 17:04:35 -0700 | [diff] [blame] | 2905 | void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2906 | void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); |
| 2907 | void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); |
| 2908 | int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2909 | unsigned int val, int alloc); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2910 | void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); |
| 2911 | int f2fs_build_segment_manager(struct f2fs_sb_info *sbi); |
| 2912 | void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi); |
| 2913 | int __init f2fs_create_segment_manager_caches(void); |
| 2914 | void f2fs_destroy_segment_manager_caches(void); |
| 2915 | int f2fs_rw_hint_to_seg_type(enum rw_hint hint); |
| 2916 | enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, |
| 2917 | enum page_type type, enum temp_type temp); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2918 | |
| 2919 | /* |
| 2920 | * checkpoint.c |
| 2921 | */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2922 | void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2923 | struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); |
| 2924 | struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); |
| 2925 | struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); |
| 2926 | bool f2fs_is_valid_meta_blkaddr(struct f2fs_sb_info *sbi, |
| 2927 | block_t blkaddr, int type); |
| 2928 | int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2929 | int type, bool sync); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2930 | void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); |
| 2931 | long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 2932 | long nr_to_write, enum iostat_type io_type); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2933 | void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); |
| 2934 | void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); |
| 2935 | void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all); |
| 2936 | bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); |
| 2937 | void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, |
Chao Yu | f014be8 | 2017-09-29 13:59:38 +0800 | [diff] [blame] | 2938 | unsigned int devidx, int type); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2939 | bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, |
Chao Yu | f014be8 | 2017-09-29 13:59:38 +0800 | [diff] [blame] | 2940 | unsigned int devidx, int type); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2941 | int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2942 | int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi); |
| 2943 | void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi); |
| 2944 | void f2fs_add_orphan_inode(struct inode *inode); |
| 2945 | void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); |
| 2946 | int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi); |
| 2947 | int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi); |
| 2948 | void f2fs_update_dirty_page(struct inode *inode, struct page *page); |
| 2949 | void f2fs_remove_dirty_inode(struct inode *inode); |
| 2950 | int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); |
| 2951 | int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); |
| 2952 | void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi); |
| 2953 | int __init f2fs_create_checkpoint_caches(void); |
| 2954 | void f2fs_destroy_checkpoint_caches(void); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 2955 | |
| 2956 | /* |
| 2957 | * data.c |
| 2958 | */ |
Eric Biggers | f69e814 | 2018-04-18 11:09:48 -0700 | [diff] [blame] | 2959 | int f2fs_init_post_read_processing(void); |
| 2960 | void f2fs_destroy_post_read_processing(void); |
Jaegeuk Kim | 9bc576a | 2017-05-10 11:28:38 -0700 | [diff] [blame] | 2961 | void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); |
| 2962 | void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2963 | struct inode *inode, nid_t ino, pgoff_t idx, |
Jaegeuk Kim | 9bc576a | 2017-05-10 11:28:38 -0700 | [diff] [blame] | 2964 | enum page_type type); |
| 2965 | void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2966 | int f2fs_submit_page_bio(struct f2fs_io_info *fio); |
Chao Yu | 34880e0 | 2018-05-28 23:47:18 +0800 | [diff] [blame] | 2967 | void f2fs_submit_page_write(struct f2fs_io_info *fio); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2968 | struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, |
| 2969 | block_t blk_addr, struct bio *bio); |
| 2970 | int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2971 | void f2fs_set_data_blkaddr(struct dnode_of_data *dn); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2972 | void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2973 | int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); |
| 2974 | int f2fs_reserve_new_block(struct dnode_of_data *dn); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2975 | int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); |
| 2976 | int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); |
| 2977 | int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2978 | struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2979 | int op_flags, bool for_write); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2980 | struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index); |
| 2981 | struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2982 | bool for_write); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2983 | struct page *f2fs_get_new_data_page(struct inode *inode, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2984 | struct page *ipage, pgoff_t index, bool new_i_size); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2985 | int f2fs_do_write_data_page(struct f2fs_io_info *fio); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2986 | int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, |
| 2987 | int create, int flag); |
| 2988 | int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
| 2989 | u64 start, u64 len); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2990 | bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); |
| 2991 | bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2992 | void f2fs_invalidate_page(struct page *page, unsigned int offset, |
| 2993 | unsigned int length); |
| 2994 | int f2fs_release_page(struct page *page, gfp_t wait); |
Weichao Guo | 5b7a487 | 2016-09-20 05:03:27 +0800 | [diff] [blame] | 2995 | #ifdef CONFIG_MIGRATION |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 2996 | int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, |
| 2997 | struct page *page, enum migrate_mode mode); |
Weichao Guo | 5b7a487 | 2016-09-20 05:03:27 +0800 | [diff] [blame] | 2998 | #endif |
Hyunchul Lee | 355d234 | 2018-03-08 19:34:38 +0900 | [diff] [blame] | 2999 | bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3000 | void f2fs_clear_radix_tree_dirty_tag(struct page *page); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3001 | |
| 3002 | /* |
| 3003 | * gc.c |
| 3004 | */ |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3005 | int f2fs_start_gc_thread(struct f2fs_sb_info *sbi); |
| 3006 | void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi); |
| 3007 | block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3008 | int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, |
| 3009 | unsigned int segno); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3010 | void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3011 | |
| 3012 | /* |
| 3013 | * recovery.c |
| 3014 | */ |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3015 | int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); |
| 3016 | bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3017 | |
| 3018 | /* |
| 3019 | * debug.c |
| 3020 | */ |
| 3021 | #ifdef CONFIG_F2FS_STAT_FS |
| 3022 | struct f2fs_stat_info { |
| 3023 | struct list_head stat_list; |
| 3024 | struct f2fs_sb_info *sbi; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3025 | int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; |
| 3026 | int main_area_segs, main_area_sections, main_area_zones; |
Chao Yu | 5b7ee37 | 2015-09-30 17:38:48 +0800 | [diff] [blame] | 3027 | unsigned long long hit_largest, hit_cached, hit_rbtree; |
| 3028 | unsigned long long hit_total, total_ext; |
Jaegeuk Kim | c00ba55 | 2015-12-31 15:24:14 -0800 | [diff] [blame] | 3029 | int ext_tree, zombie_tree, ext_node; |
Jaegeuk Kim | 931ecc2 | 2017-11-13 17:46:38 -0800 | [diff] [blame] | 3030 | int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; |
| 3031 | int ndirty_data, ndirty_qdata; |
Jaegeuk Kim | 725ba1a | 2016-10-20 19:09:57 -0700 | [diff] [blame] | 3032 | int inmem_pages; |
Jaegeuk Kim | 931ecc2 | 2017-11-13 17:46:38 -0800 | [diff] [blame] | 3033 | unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3034 | int nats, dirty_nats, sits, dirty_sits; |
| 3035 | int free_nids, avail_nids, alloc_nids; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3036 | int total_count, utilization; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3037 | int bg_gc, nr_wb_cp_data, nr_wb_data; |
Chao Yu | 2f0df25 | 2017-09-14 10:18:01 +0800 | [diff] [blame] | 3038 | int nr_flushing, nr_flushed, flush_list_empty; |
| 3039 | int nr_discarding, nr_discarded; |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3040 | int nr_discard_cmd; |
| 3041 | unsigned int undiscard_blks; |
| 3042 | int inline_xattr, inline_inode, inline_dir, append, update, orphans; |
| 3043 | int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; |
Yunlei He | f83a258 | 2016-08-18 21:01:18 +0800 | [diff] [blame] | 3044 | unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3045 | unsigned int bimodal, avg_vblocks; |
| 3046 | int util_free, util_valid, util_invalid; |
| 3047 | int rsvd_segs, overp_segs; |
| 3048 | int dirty_count, node_pages, meta_pages; |
Jaegeuk Kim | 42190d2 | 2016-01-09 13:45:17 -0800 | [diff] [blame] | 3049 | int prefree_count, call_count, cp_count, bg_cp_count; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3050 | int tot_segs, node_segs, data_segs, free_segs, free_secs; |
Changman Lee | e123598 | 2014-12-23 08:37:39 +0900 | [diff] [blame] | 3051 | int bg_node_segs, bg_data_segs; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3052 | int tot_blks, data_blks, node_blks; |
Changman Lee | e123598 | 2014-12-23 08:37:39 +0900 | [diff] [blame] | 3053 | int bg_data_blks, bg_node_blks; |
Chao Yu | caf10c6 | 2018-05-07 20:28:54 +0800 | [diff] [blame] | 3054 | unsigned long long skipped_atomic_files[2]; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3055 | int curseg[NR_CURSEG_TYPE]; |
| 3056 | int cursec[NR_CURSEG_TYPE]; |
| 3057 | int curzone[NR_CURSEG_TYPE]; |
| 3058 | |
| 3059 | unsigned int segment_count[2]; |
| 3060 | unsigned int block_count[2]; |
Changman Lee | b9a2c25 | 2014-12-24 02:16:54 +0900 | [diff] [blame] | 3061 | unsigned int inplace_count; |
Chao Yu | 9edcdab | 2015-09-11 14:43:52 +0800 | [diff] [blame] | 3062 | unsigned long long base_mem, cache_mem, page_mem; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3063 | }; |
| 3064 | |
Gu Zheng | 963d4f7 | 2013-07-12 14:47:11 +0800 | [diff] [blame] | 3065 | static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) |
| 3066 | { |
Chris Fries | 6c311ec | 2014-01-17 14:44:39 -0600 | [diff] [blame] | 3067 | return (struct f2fs_stat_info *)sbi->stat_info; |
Gu Zheng | 963d4f7 | 2013-07-12 14:47:11 +0800 | [diff] [blame] | 3068 | } |
| 3069 | |
Changman Lee | 942e0be | 2014-02-13 15:12:29 +0900 | [diff] [blame] | 3070 | #define stat_inc_cp_count(si) ((si)->cp_count++) |
Jaegeuk Kim | 42190d2 | 2016-01-09 13:45:17 -0800 | [diff] [blame] | 3071 | #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) |
Jaegeuk Kim | dcdfff6 | 2013-10-22 20:56:10 +0900 | [diff] [blame] | 3072 | #define stat_inc_call_count(si) ((si)->call_count++) |
| 3073 | #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) |
Chao Yu | 33fbd51 | 2015-12-17 17:14:44 +0800 | [diff] [blame] | 3074 | #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) |
| 3075 | #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) |
Chao Yu | 5b7ee37 | 2015-09-30 17:38:48 +0800 | [diff] [blame] | 3076 | #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) |
| 3077 | #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) |
| 3078 | #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) |
| 3079 | #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) |
Chao Yu | d5e8f6c | 2015-07-15 17:28:53 +0800 | [diff] [blame] | 3080 | #define stat_inc_inline_xattr(inode) \ |
| 3081 | do { \ |
| 3082 | if (f2fs_has_inline_xattr(inode)) \ |
| 3083 | (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ |
| 3084 | } while (0) |
| 3085 | #define stat_dec_inline_xattr(inode) \ |
| 3086 | do { \ |
| 3087 | if (f2fs_has_inline_xattr(inode)) \ |
| 3088 | (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ |
| 3089 | } while (0) |
Jaegeuk Kim | 0dbdc2a | 2013-11-26 11:08:57 +0900 | [diff] [blame] | 3090 | #define stat_inc_inline_inode(inode) \ |
| 3091 | do { \ |
| 3092 | if (f2fs_has_inline_data(inode)) \ |
Chao Yu | 03e14d5 | 2014-12-08 19:08:20 +0800 | [diff] [blame] | 3093 | (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ |
Jaegeuk Kim | 0dbdc2a | 2013-11-26 11:08:57 +0900 | [diff] [blame] | 3094 | } while (0) |
| 3095 | #define stat_dec_inline_inode(inode) \ |
| 3096 | do { \ |
| 3097 | if (f2fs_has_inline_data(inode)) \ |
Chao Yu | 03e14d5 | 2014-12-08 19:08:20 +0800 | [diff] [blame] | 3098 | (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ |
Jaegeuk Kim | 0dbdc2a | 2013-11-26 11:08:57 +0900 | [diff] [blame] | 3099 | } while (0) |
Jaegeuk Kim | 3289c06 | 2014-10-13 20:00:16 -0700 | [diff] [blame] | 3100 | #define stat_inc_inline_dir(inode) \ |
| 3101 | do { \ |
| 3102 | if (f2fs_has_inline_dentry(inode)) \ |
Chao Yu | 03e14d5 | 2014-12-08 19:08:20 +0800 | [diff] [blame] | 3103 | (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ |
Jaegeuk Kim | 3289c06 | 2014-10-13 20:00:16 -0700 | [diff] [blame] | 3104 | } while (0) |
| 3105 | #define stat_dec_inline_dir(inode) \ |
| 3106 | do { \ |
| 3107 | if (f2fs_has_inline_dentry(inode)) \ |
Chao Yu | 03e14d5 | 2014-12-08 19:08:20 +0800 | [diff] [blame] | 3108 | (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ |
Jaegeuk Kim | 3289c06 | 2014-10-13 20:00:16 -0700 | [diff] [blame] | 3109 | } while (0) |
Jaegeuk Kim | dcdfff6 | 2013-10-22 20:56:10 +0900 | [diff] [blame] | 3110 | #define stat_inc_seg_type(sbi, curseg) \ |
| 3111 | ((sbi)->segment_count[(curseg)->alloc_type]++) |
| 3112 | #define stat_inc_block_count(sbi, curseg) \ |
| 3113 | ((sbi)->block_count[(curseg)->alloc_type]++) |
Changman Lee | b9a2c25 | 2014-12-24 02:16:54 +0900 | [diff] [blame] | 3114 | #define stat_inc_inplace_blocks(sbi) \ |
| 3115 | (atomic_inc(&(sbi)->inplace_count)) |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3116 | #define stat_inc_atomic_write(inode) \ |
| 3117 | (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) |
| 3118 | #define stat_dec_atomic_write(inode) \ |
| 3119 | (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) |
| 3120 | #define stat_update_max_atomic_write(inode) \ |
| 3121 | do { \ |
| 3122 | int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ |
| 3123 | int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ |
| 3124 | if (cur > max) \ |
| 3125 | atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ |
| 3126 | } while (0) |
| 3127 | #define stat_inc_volatile_write(inode) \ |
| 3128 | (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) |
| 3129 | #define stat_dec_volatile_write(inode) \ |
| 3130 | (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) |
| 3131 | #define stat_update_max_volatile_write(inode) \ |
| 3132 | do { \ |
| 3133 | int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ |
| 3134 | int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ |
| 3135 | if (cur > max) \ |
| 3136 | atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ |
| 3137 | } while (0) |
Changman Lee | e123598 | 2014-12-23 08:37:39 +0900 | [diff] [blame] | 3138 | #define stat_inc_seg_count(sbi, type, gc_type) \ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3139 | do { \ |
Gu Zheng | 963d4f7 | 2013-07-12 14:47:11 +0800 | [diff] [blame] | 3140 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3141 | si->tot_segs++; \ |
| 3142 | if ((type) == SUM_TYPE_DATA) { \ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3143 | si->data_segs++; \ |
Changman Lee | e123598 | 2014-12-23 08:37:39 +0900 | [diff] [blame] | 3144 | si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ |
| 3145 | } else { \ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3146 | si->node_segs++; \ |
Changman Lee | e123598 | 2014-12-23 08:37:39 +0900 | [diff] [blame] | 3147 | si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ |
| 3148 | } \ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3149 | } while (0) |
| 3150 | |
| 3151 | #define stat_inc_tot_blk_count(si, blks) \ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3152 | ((si)->tot_blks += (blks)) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3153 | |
Changman Lee | e123598 | 2014-12-23 08:37:39 +0900 | [diff] [blame] | 3154 | #define stat_inc_data_blk_count(sbi, blks, gc_type) \ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3155 | do { \ |
Gu Zheng | 963d4f7 | 2013-07-12 14:47:11 +0800 | [diff] [blame] | 3156 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3157 | stat_inc_tot_blk_count(si, blks); \ |
| 3158 | si->data_blks += (blks); \ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3159 | si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3160 | } while (0) |
| 3161 | |
Changman Lee | e123598 | 2014-12-23 08:37:39 +0900 | [diff] [blame] | 3162 | #define stat_inc_node_blk_count(sbi, blks, gc_type) \ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3163 | do { \ |
Gu Zheng | 963d4f7 | 2013-07-12 14:47:11 +0800 | [diff] [blame] | 3164 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3165 | stat_inc_tot_blk_count(si, blks); \ |
| 3166 | si->node_blks += (blks); \ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3167 | si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3168 | } while (0) |
| 3169 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3170 | int f2fs_build_stats(struct f2fs_sb_info *sbi); |
| 3171 | void f2fs_destroy_stats(struct f2fs_sb_info *sbi); |
Chao Yu | 787c7b8c | 2015-10-29 09:13:04 +0800 | [diff] [blame] | 3172 | int __init f2fs_create_root_stats(void); |
Namjae Jeon | 4589d25 | 2013-01-15 19:58:47 +0900 | [diff] [blame] | 3173 | void f2fs_destroy_root_stats(void); |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3174 | #else |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3175 | #define stat_inc_cp_count(si) do { } while (0) |
| 3176 | #define stat_inc_bg_cp_count(si) do { } while (0) |
| 3177 | #define stat_inc_call_count(si) do { } while (0) |
| 3178 | #define stat_inc_bggc_count(si) do { } while (0) |
| 3179 | #define stat_inc_dirty_inode(sbi, type) do { } while (0) |
| 3180 | #define stat_dec_dirty_inode(sbi, type) do { } while (0) |
| 3181 | #define stat_inc_total_hit(sb) do { } while (0) |
| 3182 | #define stat_inc_rbtree_node_hit(sb) do { } while (0) |
| 3183 | #define stat_inc_largest_node_hit(sbi) do { } while (0) |
| 3184 | #define stat_inc_cached_node_hit(sbi) do { } while (0) |
| 3185 | #define stat_inc_inline_xattr(inode) do { } while (0) |
| 3186 | #define stat_dec_inline_xattr(inode) do { } while (0) |
| 3187 | #define stat_inc_inline_inode(inode) do { } while (0) |
| 3188 | #define stat_dec_inline_inode(inode) do { } while (0) |
| 3189 | #define stat_inc_inline_dir(inode) do { } while (0) |
| 3190 | #define stat_dec_inline_dir(inode) do { } while (0) |
| 3191 | #define stat_inc_atomic_write(inode) do { } while (0) |
| 3192 | #define stat_dec_atomic_write(inode) do { } while (0) |
| 3193 | #define stat_update_max_atomic_write(inode) do { } while (0) |
| 3194 | #define stat_inc_volatile_write(inode) do { } while (0) |
| 3195 | #define stat_dec_volatile_write(inode) do { } while (0) |
| 3196 | #define stat_update_max_volatile_write(inode) do { } while (0) |
| 3197 | #define stat_inc_seg_type(sbi, curseg) do { } while (0) |
| 3198 | #define stat_inc_block_count(sbi, curseg) do { } while (0) |
| 3199 | #define stat_inc_inplace_blocks(sbi) do { } while (0) |
| 3200 | #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) |
| 3201 | #define stat_inc_tot_blk_count(si, blks) do { } while (0) |
| 3202 | #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) |
| 3203 | #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3204 | |
| 3205 | static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } |
| 3206 | static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } |
Chao Yu | 787c7b8c | 2015-10-29 09:13:04 +0800 | [diff] [blame] | 3207 | static inline int __init f2fs_create_root_stats(void) { return 0; } |
Namjae Jeon | 4589d25 | 2013-01-15 19:58:47 +0900 | [diff] [blame] | 3208 | static inline void f2fs_destroy_root_stats(void) { } |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3209 | #endif |
| 3210 | |
| 3211 | extern const struct file_operations f2fs_dir_operations; |
| 3212 | extern const struct file_operations f2fs_file_operations; |
| 3213 | extern const struct inode_operations f2fs_file_inode_operations; |
| 3214 | extern const struct address_space_operations f2fs_dblock_aops; |
| 3215 | extern const struct address_space_operations f2fs_node_aops; |
| 3216 | extern const struct address_space_operations f2fs_meta_aops; |
| 3217 | extern const struct inode_operations f2fs_dir_inode_operations; |
| 3218 | extern const struct inode_operations f2fs_symlink_inode_operations; |
Jaegeuk Kim | cbaf042 | 2015-04-29 15:10:53 -0700 | [diff] [blame] | 3219 | extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3220 | extern const struct inode_operations f2fs_special_inode_operations; |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3221 | extern struct kmem_cache *f2fs_inode_entry_slab; |
Huajun Li | 1001b34 | 2013-11-10 23:13:16 +0800 | [diff] [blame] | 3222 | |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 3223 | /* |
| 3224 | * inline.c |
| 3225 | */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3226 | bool f2fs_may_inline_data(struct inode *inode); |
| 3227 | bool f2fs_may_inline_dentry(struct inode *inode); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3228 | void f2fs_do_read_inline_data(struct page *page, struct page *ipage); |
| 3229 | void f2fs_truncate_inline_inode(struct inode *inode, |
| 3230 | struct page *ipage, u64 from); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3231 | int f2fs_read_inline_data(struct inode *inode, struct page *page); |
| 3232 | int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); |
| 3233 | int f2fs_convert_inline_inode(struct inode *inode); |
| 3234 | int f2fs_write_inline_data(struct inode *inode, struct page *page); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3235 | bool f2fs_recover_inline_data(struct inode *inode, struct page *npage); |
| 3236 | struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3237 | struct fscrypt_name *fname, struct page **res_page); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3238 | int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3239 | struct page *ipage); |
| 3240 | int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, |
| 3241 | const struct qstr *orig_name, |
| 3242 | struct inode *inode, nid_t ino, umode_t mode); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3243 | void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, |
| 3244 | struct page *page, struct inode *dir, |
| 3245 | struct inode *inode); |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3246 | bool f2fs_empty_inline_dir(struct inode *dir); |
| 3247 | int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, |
| 3248 | struct fscrypt_str *fstr); |
| 3249 | int f2fs_inline_data_fiemap(struct inode *inode, |
| 3250 | struct fiemap_extent_info *fieinfo, |
| 3251 | __u64 start, __u64 len); |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 3252 | |
| 3253 | /* |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 3254 | * shrinker.c |
| 3255 | */ |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3256 | unsigned long f2fs_shrink_count(struct shrinker *shrink, |
| 3257 | struct shrink_control *sc); |
| 3258 | unsigned long f2fs_shrink_scan(struct shrinker *shrink, |
| 3259 | struct shrink_control *sc); |
| 3260 | void f2fs_join_shrinker(struct f2fs_sb_info *sbi); |
| 3261 | void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 3262 | |
| 3263 | /* |
Chao Yu | a28ef1f | 2015-07-08 17:59:36 +0800 | [diff] [blame] | 3264 | * extent_cache.c |
| 3265 | */ |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3266 | struct rb_entry *f2fs_lookup_rb_tree(struct rb_root *root, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3267 | struct rb_entry *cached_re, unsigned int ofs); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3268 | struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3269 | struct rb_root *root, struct rb_node **parent, |
| 3270 | unsigned int ofs); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3271 | struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root *root, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3272 | struct rb_entry *cached_re, unsigned int ofs, |
| 3273 | struct rb_entry **prev_entry, struct rb_entry **next_entry, |
| 3274 | struct rb_node ***insert_p, struct rb_node **insert_parent, |
| 3275 | bool force); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3276 | bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3277 | struct rb_root *root); |
| 3278 | unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); |
| 3279 | bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); |
| 3280 | void f2fs_drop_extent_tree(struct inode *inode); |
| 3281 | unsigned int f2fs_destroy_extent_node(struct inode *inode); |
| 3282 | void f2fs_destroy_extent_tree(struct inode *inode); |
| 3283 | bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, |
| 3284 | struct extent_info *ei); |
| 3285 | void f2fs_update_extent_cache(struct dnode_of_data *dn); |
Chao Yu | 19b2c30 | 2015-08-26 20:34:48 +0800 | [diff] [blame] | 3286 | void f2fs_update_extent_cache_range(struct dnode_of_data *dn, |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3287 | pgoff_t fofs, block_t blkaddr, unsigned int len); |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3288 | void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi); |
| 3289 | int __init f2fs_create_extent_cache(void); |
| 3290 | void f2fs_destroy_extent_cache(void); |
Chao Yu | a28ef1f | 2015-07-08 17:59:36 +0800 | [diff] [blame] | 3291 | |
| 3292 | /* |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 3293 | * sysfs.c |
| 3294 | */ |
Jaegeuk Kim | 883d553 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 3295 | int __init f2fs_init_sysfs(void); |
| 3296 | void f2fs_exit_sysfs(void); |
| 3297 | int f2fs_register_sysfs(struct f2fs_sb_info *sbi); |
| 3298 | void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 3299 | |
| 3300 | /* |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 3301 | * crypto support |
| 3302 | */ |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 3303 | static inline bool f2fs_encrypted_inode(struct inode *inode) |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 3304 | { |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 3305 | return file_is_encrypt(inode); |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 3306 | } |
| 3307 | |
Jaegeuk Kim | a4fb189 | 2017-09-05 16:54:24 -0700 | [diff] [blame] | 3308 | static inline bool f2fs_encrypted_file(struct inode *inode) |
| 3309 | { |
| 3310 | return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode); |
| 3311 | } |
| 3312 | |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 3313 | static inline void f2fs_set_encrypted_inode(struct inode *inode) |
| 3314 | { |
| 3315 | #ifdef CONFIG_F2FS_FS_ENCRYPTION |
| 3316 | file_set_encrypt(inode); |
Eric Biggers | 685285b | 2017-10-09 12:15:35 -0700 | [diff] [blame] | 3317 | inode->i_flags |= S_ENCRYPTED; |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 3318 | #endif |
| 3319 | } |
| 3320 | |
Eric Biggers | f69e814 | 2018-04-18 11:09:48 -0700 | [diff] [blame] | 3321 | /* |
| 3322 | * Returns true if the reads of the inode's data need to undergo some |
| 3323 | * postprocessing step, like decryption or authenticity verification. |
| 3324 | */ |
| 3325 | static inline bool f2fs_post_read_required(struct inode *inode) |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 3326 | { |
Eric Biggers | f69e814 | 2018-04-18 11:09:48 -0700 | [diff] [blame] | 3327 | return f2fs_encrypted_file(inode); |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 3328 | } |
| 3329 | |
Sheng Yong | 770611e | 2018-02-06 12:31:17 +0800 | [diff] [blame] | 3330 | #define F2FS_FEATURE_FUNCS(name, flagname) \ |
| 3331 | static inline int f2fs_sb_has_##name(struct super_block *sb) \ |
| 3332 | { \ |
| 3333 | return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_##flagname); \ |
Jaegeuk Kim | cde4de1 | 2015-04-20 13:57:51 -0700 | [diff] [blame] | 3334 | } |
Jaegeuk Kim | f424f66 | 2015-04-20 15:19:06 -0700 | [diff] [blame] | 3335 | |
Sheng Yong | 770611e | 2018-02-06 12:31:17 +0800 | [diff] [blame] | 3336 | F2FS_FEATURE_FUNCS(encrypt, ENCRYPT); |
| 3337 | F2FS_FEATURE_FUNCS(blkzoned, BLKZONED); |
| 3338 | F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR); |
| 3339 | F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA); |
| 3340 | F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM); |
| 3341 | F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); |
| 3342 | F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); |
| 3343 | F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); |
Sheng Yong | 9b880fe | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 3344 | F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); |
Chao Yu | 71f8f04 | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 3345 | |
Jaegeuk Kim | e6b120d | 2017-07-10 12:55:09 -0700 | [diff] [blame] | 3346 | #ifdef CONFIG_BLK_DEV_ZONED |
| 3347 | static inline int get_blkz_type(struct f2fs_sb_info *sbi, |
| 3348 | struct block_device *bdev, block_t blkaddr) |
| 3349 | { |
| 3350 | unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; |
| 3351 | int i; |
| 3352 | |
| 3353 | for (i = 0; i < sbi->s_ndevs; i++) |
| 3354 | if (FDEV(i).bdev == bdev) |
| 3355 | return FDEV(i).blkz_type[zno]; |
| 3356 | return -EINVAL; |
| 3357 | } |
| 3358 | #endif |
| 3359 | |
| 3360 | static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) |
| 3361 | { |
| 3362 | struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); |
| 3363 | |
Sheng Yong | 770611e | 2018-02-06 12:31:17 +0800 | [diff] [blame] | 3364 | return blk_queue_discard(q) || f2fs_sb_has_blkzoned(sbi->sb); |
Jaegeuk Kim | 52763a4 | 2016-06-13 09:47:48 -0700 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) |
| 3368 | { |
| 3369 | clear_opt(sbi, ADAPTIVE); |
| 3370 | clear_opt(sbi, LFS); |
| 3371 | |
| 3372 | switch (mt) { |
| 3373 | case F2FS_MOUNT_ADAPTIVE: |
| 3374 | set_opt(sbi, ADAPTIVE); |
| 3375 | break; |
| 3376 | case F2FS_MOUNT_LFS: |
| 3377 | set_opt(sbi, LFS); |
| 3378 | break; |
| 3379 | } |
| 3380 | } |
| 3381 | |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 3382 | static inline bool f2fs_may_encrypt(struct inode *inode) |
| 3383 | { |
| 3384 | #ifdef CONFIG_F2FS_FS_ENCRYPTION |
Al Viro | 886f56f | 2015-12-05 03:56:06 -0500 | [diff] [blame] | 3385 | umode_t mode = inode->i_mode; |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 3386 | |
| 3387 | return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); |
| 3388 | #else |
| 3389 | return 0; |
| 3390 | #endif |
| 3391 | } |
| 3392 | |
Hyunchul Lee | 355d234 | 2018-03-08 19:34:38 +0900 | [diff] [blame] | 3393 | static inline bool f2fs_force_buffered_io(struct inode *inode, int rw) |
| 3394 | { |
Eric Biggers | f69e814 | 2018-04-18 11:09:48 -0700 | [diff] [blame] | 3395 | return (f2fs_post_read_required(inode) || |
Hyunchul Lee | 355d234 | 2018-03-08 19:34:38 +0900 | [diff] [blame] | 3396 | (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) || |
| 3397 | F2FS_I_SB(inode)->s_ndevs); |
| 3398 | } |
| 3399 | |
Jaegeuk Kim | 39a53e0 | 2012-11-28 13:37:31 +0900 | [diff] [blame] | 3400 | #endif |