]>
Commit | Line | Data |
---|---|---|
7c1a000d | 1 | // SPDX-License-Identifier: GPL-2.0 |
0a8165d7 | 2 | /* |
39a53e0c JK |
3 | * fs/f2fs/f2fs.h |
4 | * | |
5 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | |
6 | * http://www.samsung.com/ | |
39a53e0c JK |
7 | */ |
8 | #ifndef _LINUX_F2FS_H | |
9 | #define _LINUX_F2FS_H | |
10 | ||
f847c699 | 11 | #include <linux/uio.h> |
39a53e0c JK |
12 | #include <linux/types.h> |
13 | #include <linux/page-flags.h> | |
14 | #include <linux/buffer_head.h> | |
39a53e0c JK |
15 | #include <linux/slab.h> |
16 | #include <linux/crc32.h> | |
17 | #include <linux/magic.h> | |
c2d715d1 | 18 | #include <linux/kobject.h> |
7bd59381 | 19 | #include <linux/sched.h> |
7c2e5963 | 20 | #include <linux/cred.h> |
39307a8e | 21 | #include <linux/vmalloc.h> |
740432f8 | 22 | #include <linux/bio.h> |
d0239e1b | 23 | #include <linux/blkdev.h> |
0abd675e | 24 | #include <linux/quotaops.h> |
43b6573b | 25 | #include <crypto/hash.h> |
39a53e0c | 26 | |
734f0d24 | 27 | #include <linux/fscrypt.h> |
95ae251f | 28 | #include <linux/fsverity.h> |
734f0d24 | 29 | |
5d56b671 | 30 | #ifdef CONFIG_F2FS_CHECK_FS |
9850cf4a | 31 | #define f2fs_bug_on(sbi, condition) BUG_ON(condition) |
5d56b671 | 32 | #else |
9850cf4a JK |
33 | #define f2fs_bug_on(sbi, condition) \ |
34 | do { \ | |
35 | if (unlikely(condition)) { \ | |
36 | WARN_ON(1); \ | |
caf0047e | 37 | set_sbi_flag(sbi, SBI_NEED_FSCK); \ |
9850cf4a JK |
38 | } \ |
39 | } while (0) | |
5d56b671 JK |
40 | #endif |
41 | ||
2c63fead JK |
42 | enum { |
43 | FAULT_KMALLOC, | |
628b3d14 | 44 | FAULT_KVMALLOC, |
c41f3cc3 | 45 | FAULT_PAGE_ALLOC, |
01eccef7 | 46 | FAULT_PAGE_GET, |
d62fe971 | 47 | FAULT_ALLOC_BIO, |
cb78942b JK |
48 | FAULT_ALLOC_NID, |
49 | FAULT_ORPHAN, | |
50 | FAULT_BLOCK, | |
51 | FAULT_DIR_DEPTH, | |
53aa6bbf | 52 | FAULT_EVICT_INODE, |
14b44d23 | 53 | FAULT_TRUNCATE, |
6f5c2ed0 | 54 | FAULT_READ_IO, |
0f348028 | 55 | FAULT_CHECKPOINT, |
b83dcfe6 | 56 | FAULT_DISCARD, |
6f5c2ed0 | 57 | FAULT_WRITE_IO, |
2c63fead JK |
58 | FAULT_MAX, |
59 | }; | |
60 | ||
7fa750a1 | 61 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
d494500a CY |
62 | #define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1) |
63 | ||
08796897 SY |
64 | struct f2fs_fault_info { |
65 | atomic_t inject_ops; | |
66 | unsigned int inject_rate; | |
67 | unsigned int inject_type; | |
68 | }; | |
69 | ||
19880e6e | 70 | extern const char *f2fs_fault_name[FAULT_MAX]; |
68afcf2d | 71 | #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) |
2c63fead JK |
72 | #endif |
73 | ||
39a53e0c JK |
74 | /* |
75 | * For mount options | |
76 | */ | |
77 | #define F2FS_MOUNT_BG_GC 0x00000001 | |
78 | #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 | |
79 | #define F2FS_MOUNT_DISCARD 0x00000004 | |
80 | #define F2FS_MOUNT_NOHEAP 0x00000008 | |
81 | #define F2FS_MOUNT_XATTR_USER 0x00000010 | |
82 | #define F2FS_MOUNT_POSIX_ACL 0x00000020 | |
83 | #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 | |
444c580f | 84 | #define F2FS_MOUNT_INLINE_XATTR 0x00000080 |
1001b347 | 85 | #define F2FS_MOUNT_INLINE_DATA 0x00000100 |
34d67deb CY |
86 | #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 |
87 | #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 | |
88 | #define F2FS_MOUNT_NOBARRIER 0x00000800 | |
d5053a34 | 89 | #define F2FS_MOUNT_FASTBOOT 0x00001000 |
89672159 | 90 | #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 |
6aefd93b | 91 | #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 |
343f40f0 | 92 | #define F2FS_MOUNT_DATA_FLUSH 0x00008000 |
73faec4d | 93 | #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 |
36abef4e JK |
94 | #define F2FS_MOUNT_ADAPTIVE 0x00020000 |
95 | #define F2FS_MOUNT_LFS 0x00040000 | |
0abd675e CY |
96 | #define F2FS_MOUNT_USRQUOTA 0x00080000 |
97 | #define F2FS_MOUNT_GRPQUOTA 0x00100000 | |
5c57132e | 98 | #define F2FS_MOUNT_PRJQUOTA 0x00200000 |
4b2414d0 | 99 | #define F2FS_MOUNT_QUOTA 0x00400000 |
6afc662e | 100 | #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 |
7e65be49 | 101 | #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 |
4354994f | 102 | #define F2FS_MOUNT_DISABLE_CHECKPOINT 0x02000000 |
efc855c2 | 103 | #define F2FS_MOUNT_NORECOVERY 0x04000000 |
39a53e0c | 104 | |
63189b78 CY |
105 | #define F2FS_OPTION(sbi) ((sbi)->mount_opt) |
106 | #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) | |
107 | #define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option) | |
108 | #define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option) | |
39a53e0c JK |
109 | |
110 | #define ver_after(a, b) (typecheck(unsigned long long, a) && \ | |
111 | typecheck(unsigned long long, b) && \ | |
112 | ((long long)((a) - (b)) > 0)) | |
113 | ||
a9841c4d JK |
114 | typedef u32 block_t; /* |
115 | * should not change u32, since it is the on-disk block | |
116 | * address format, __le32. | |
117 | */ | |
39a53e0c JK |
118 | typedef u32 nid_t; |
119 | ||
120 | struct f2fs_mount_info { | |
63189b78 CY |
121 | unsigned int opt; |
122 | int write_io_size_bits; /* Write IO size bits */ | |
123 | block_t root_reserved_blocks; /* root reserved blocks */ | |
124 | kuid_t s_resuid; /* reserved blocks for uid */ | |
125 | kgid_t s_resgid; /* reserved blocks for gid */ | |
126 | int active_logs; /* # of active logs */ | |
127 | int inline_xattr_size; /* inline xattr size */ | |
128 | #ifdef CONFIG_F2FS_FAULT_INJECTION | |
129 | struct f2fs_fault_info fault_info; /* For fault injection */ | |
130 | #endif | |
131 | #ifdef CONFIG_QUOTA | |
132 | /* Names of quota files with journalled quota */ | |
133 | char *s_qf_names[MAXQUOTAS]; | |
134 | int s_jquota_fmt; /* Format of quota to use */ | |
135 | #endif | |
136 | /* For which write hints are passed down to block layer */ | |
137 | int whint_mode; | |
138 | int alloc_mode; /* segment allocation policy */ | |
139 | int fsync_mode; /* fsync policy */ | |
ff62af20 | 140 | bool test_dummy_encryption; /* test dummy encryption */ |
50eeb3df | 141 | block_t unusable_cap_perc; /* percentage for cap */ |
4d3aed70 DR |
142 | block_t unusable_cap; /* Amount of space allowed to be |
143 | * unusable when disabling checkpoint | |
144 | */ | |
39a53e0c JK |
145 | }; |
146 | ||
7a2af766 CY |
147 | #define F2FS_FEATURE_ENCRYPT 0x0001 |
148 | #define F2FS_FEATURE_BLKZONED 0x0002 | |
149 | #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 | |
150 | #define F2FS_FEATURE_EXTRA_ATTR 0x0008 | |
5c57132e | 151 | #define F2FS_FEATURE_PRJQUOTA 0x0010 |
704956ec | 152 | #define F2FS_FEATURE_INODE_CHKSUM 0x0020 |
6afc662e | 153 | #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 |
234a9689 | 154 | #define F2FS_FEATURE_QUOTA_INO 0x0080 |
1c1d35df | 155 | #define F2FS_FEATURE_INODE_CRTIME 0x0100 |
b7c409de | 156 | #define F2FS_FEATURE_LOST_FOUND 0x0200 |
95ae251f | 157 | #define F2FS_FEATURE_VERITY 0x0400 |
d440c52d | 158 | #define F2FS_FEATURE_SB_CHKSUM 0x0800 |
5aba5430 | 159 | #define F2FS_FEATURE_CASEFOLD 0x1000 |
cde4de12 | 160 | |
7beb01f7 CY |
161 | #define __F2FS_HAS_FEATURE(raw_super, mask) \ |
162 | ((raw_super->feature & cpu_to_le32(mask)) != 0) | |
163 | #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask) | |
164 | #define F2FS_SET_FEATURE(sbi, mask) \ | |
165 | (sbi->raw_super->feature |= cpu_to_le32(mask)) | |
166 | #define F2FS_CLEAR_FEATURE(sbi, mask) \ | |
167 | (sbi->raw_super->feature &= ~cpu_to_le32(mask)) | |
76f105a2 | 168 | |
7c2e5963 JK |
169 | /* |
170 | * Default values for user and/or group using reserved blocks | |
171 | */ | |
172 | #define F2FS_DEF_RESUID 0 | |
173 | #define F2FS_DEF_RESGID 0 | |
174 | ||
39a53e0c JK |
175 | /* |
176 | * For checkpoint manager | |
177 | */ | |
178 | enum { | |
179 | NAT_BITMAP, | |
180 | SIT_BITMAP | |
181 | }; | |
182 | ||
c473f1a9 CY |
183 | #define CP_UMOUNT 0x00000001 |
184 | #define CP_FASTBOOT 0x00000002 | |
185 | #define CP_SYNC 0x00000004 | |
186 | #define CP_RECOVERY 0x00000008 | |
187 | #define CP_DISCARD 0x00000010 | |
1f43e2ad | 188 | #define CP_TRIMMED 0x00000020 |
4354994f | 189 | #define CP_PAUSE 0x00000040 |
75ab4cb8 | 190 | |
4ddb1a4d | 191 | #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) |
ecc9aa00 | 192 | #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ |
969d1b18 | 193 | #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ |
f9d1dced | 194 | #define DEF_MID_DISCARD_ISSUE_TIME 500 /* 500 ms, if device busy */ |
969d1b18 | 195 | #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ |
8bb4f253 | 196 | #define DEF_DISCARD_URGENT_UTIL 80 /* do more discard over 80% */ |
60b99b48 | 197 | #define DEF_CP_INTERVAL 60 /* 60 secs */ |
dcf25fe8 | 198 | #define DEF_IDLE_INTERVAL 5 /* 5 secs */ |
4354994f | 199 | #define DEF_DISABLE_INTERVAL 5 /* 5 secs */ |
db610a64 | 200 | #define DEF_DISABLE_QUICK_INTERVAL 1 /* 1 secs */ |
03f2c02d | 201 | #define DEF_UMOUNT_DISCARD_TIMEOUT 5 /* 5 secs */ |
bba681cb | 202 | |
75ab4cb8 JK |
203 | struct cp_control { |
204 | int reason; | |
4b2fecc8 JK |
205 | __u64 trim_start; |
206 | __u64 trim_end; | |
207 | __u64 trim_minlen; | |
75ab4cb8 JK |
208 | }; |
209 | ||
662befda | 210 | /* |
e1da7872 | 211 | * indicate meta/data type |
662befda CY |
212 | */ |
213 | enum { | |
214 | META_CP, | |
215 | META_NAT, | |
81c1a0f1 | 216 | META_SIT, |
4c521f49 | 217 | META_SSA, |
b63e7be5 | 218 | META_MAX, |
4c521f49 | 219 | META_POR, |
93770ab7 CY |
220 | DATA_GENERIC, /* check range only */ |
221 | DATA_GENERIC_ENHANCE, /* strong check on range and segment bitmap */ | |
222 | DATA_GENERIC_ENHANCE_READ, /* | |
223 | * strong check on range and segment | |
224 | * bitmap but no warning due to race | |
225 | * condition of read on truncated area | |
226 | * by extent_cache | |
227 | */ | |
e1da7872 | 228 | META_GENERIC, |
662befda CY |
229 | }; |
230 | ||
6451e041 JK |
231 | /* for the list of ino */ |
232 | enum { | |
233 | ORPHAN_INO, /* for orphan ino list */ | |
fff04f90 JK |
234 | APPEND_INO, /* for append ino list */ |
235 | UPDATE_INO, /* for update ino list */ | |
0a007b97 | 236 | TRANS_DIR_INO, /* for trasactions dir ino list */ |
39d787be | 237 | FLUSH_INO, /* for multiple device flushing */ |
6451e041 JK |
238 | MAX_INO_ENTRY, /* max. list */ |
239 | }; | |
240 | ||
241 | struct ino_entry { | |
39d787be CY |
242 | struct list_head list; /* list head */ |
243 | nid_t ino; /* inode number */ | |
244 | unsigned int dirty_device; /* dirty device bitmap */ | |
39a53e0c JK |
245 | }; |
246 | ||
2710fd7e | 247 | /* for the list of inodes to be GCed */ |
06292073 | 248 | struct inode_entry { |
39a53e0c JK |
249 | struct list_head list; /* list head */ |
250 | struct inode *inode; /* vfs inode pointer */ | |
251 | }; | |
252 | ||
50fa53ec CY |
253 | struct fsync_node_entry { |
254 | struct list_head list; /* list head */ | |
255 | struct page *page; /* warm node page pointer */ | |
256 | unsigned int seq_id; /* sequence id */ | |
257 | }; | |
258 | ||
a7eeb823 | 259 | /* for the bitmap indicate blocks to be discarded */ |
7fd9e544 JK |
260 | struct discard_entry { |
261 | struct list_head list; /* list head */ | |
a7eeb823 CY |
262 | block_t start_blkaddr; /* start blockaddr of current segment */ |
263 | unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ | |
7fd9e544 JK |
264 | }; |
265 | ||
969d1b18 CY |
266 | /* default discard granularity of inner discard thread, unit: block count */ |
267 | #define DEFAULT_DISCARD_GRANULARITY 16 | |
268 | ||
ba48a33e CY |
269 | /* max discard pend list number */ |
270 | #define MAX_PLIST_NUM 512 | |
271 | #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ | |
2f84babf | 272 | (MAX_PLIST_NUM - 1) : ((blk_num) - 1)) |
ba48a33e | 273 | |
15469963 | 274 | enum { |
35ec7d57 CY |
275 | D_PREP, /* initial */ |
276 | D_PARTIAL, /* partially submitted */ | |
277 | D_SUBMIT, /* all submitted */ | |
278 | D_DONE, /* finished */ | |
15469963 JK |
279 | }; |
280 | ||
004b6862 CY |
281 | struct discard_info { |
282 | block_t lstart; /* logical start address */ | |
283 | block_t len; /* length */ | |
284 | block_t start; /* actual start address in dev */ | |
285 | }; | |
286 | ||
b01a9201 | 287 | struct discard_cmd { |
004b6862 CY |
288 | struct rb_node rb_node; /* rb node located in rb-tree */ |
289 | union { | |
290 | struct { | |
291 | block_t lstart; /* logical start address */ | |
292 | block_t len; /* length */ | |
293 | block_t start; /* actual start address in dev */ | |
294 | }; | |
295 | struct discard_info di; /* discard info */ | |
296 | ||
297 | }; | |
b01a9201 JK |
298 | struct list_head list; /* command list */ |
299 | struct completion wait; /* compleation */ | |
c81abe34 | 300 | struct block_device *bdev; /* bdev */ |
ec9895ad | 301 | unsigned short ref; /* reference count */ |
9a744b92 | 302 | unsigned char state; /* state */ |
72691af6 | 303 | unsigned char queued; /* queued discard */ |
c81abe34 | 304 | int error; /* bio error */ |
35ec7d57 CY |
305 | spinlock_t lock; /* for state/bio_ref updating */ |
306 | unsigned short bio_ref; /* bio reference count */ | |
275b66b0 CY |
307 | }; |
308 | ||
78997b56 CY |
309 | enum { |
310 | DPOLICY_BG, | |
311 | DPOLICY_FORCE, | |
312 | DPOLICY_FSTRIM, | |
313 | DPOLICY_UMOUNT, | |
314 | MAX_DPOLICY, | |
315 | }; | |
316 | ||
ecc9aa00 | 317 | struct discard_policy { |
78997b56 | 318 | int type; /* type of discard */ |
ecc9aa00 | 319 | unsigned int min_interval; /* used for candidates exist */ |
f9d1dced | 320 | unsigned int mid_interval; /* used for device busy */ |
ecc9aa00 CY |
321 | unsigned int max_interval; /* used for candidates not exist */ |
322 | unsigned int max_requests; /* # of discards issued per round */ | |
323 | unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ | |
324 | bool io_aware; /* issue discard in idle time */ | |
325 | bool sync; /* submit discard with REQ_SYNC flag */ | |
20ee4382 | 326 | bool ordered; /* issue discard by lba order */ |
78997b56 | 327 | unsigned int granularity; /* discard granularity */ |
03f2c02d | 328 | int timeout; /* discard timeout for put_super */ |
ecc9aa00 CY |
329 | }; |
330 | ||
0b54fb84 | 331 | struct discard_cmd_control { |
15469963 | 332 | struct task_struct *f2fs_issue_discard; /* discard thread */ |
46f84c2c | 333 | struct list_head entry_list; /* 4KB discard entry list */ |
ba48a33e | 334 | struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ |
46f84c2c | 335 | struct list_head wait_list; /* store on-flushing entries */ |
8412663d | 336 | struct list_head fstrim_list; /* in-flight discard from fstrim */ |
15469963 | 337 | wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ |
969d1b18 | 338 | unsigned int discard_wake; /* to wake up discard thread */ |
15469963 | 339 | struct mutex cmd_lock; |
d618ebaf CY |
340 | unsigned int nr_discards; /* # of discards in the list */ |
341 | unsigned int max_discards; /* max. discards to be issued */ | |
969d1b18 | 342 | unsigned int discard_granularity; /* discard granularity */ |
d84d1cbd | 343 | unsigned int undiscard_blks; /* # of undiscard blocks */ |
20ee4382 | 344 | unsigned int next_pos; /* next discard position */ |
8b8dd65f | 345 | atomic_t issued_discard; /* # of issued discard */ |
72691af6 | 346 | atomic_t queued_discard; /* # of queued discard */ |
5f32366a | 347 | atomic_t discard_cmd_cnt; /* # of cached cmd count */ |
4dada3fd | 348 | struct rb_root_cached root; /* root of discard rb-tree */ |
67fce70b | 349 | bool rbtree_check; /* config for consistence check */ |
275b66b0 CY |
350 | }; |
351 | ||
39a53e0c JK |
352 | /* for the list of fsync inodes, used only during recovery */ |
353 | struct fsync_inode_entry { | |
354 | struct list_head list; /* list head */ | |
355 | struct inode *inode; /* vfs inode pointer */ | |
c52e1b10 JK |
356 | block_t blkaddr; /* block address locating the last fsync */ |
357 | block_t last_dentry; /* block address locating the last dentry */ | |
39a53e0c JK |
358 | }; |
359 | ||
68afcf2d TK |
360 | #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) |
361 | #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) | |
39a53e0c | 362 | |
68afcf2d TK |
363 | #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) |
364 | #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) | |
365 | #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) | |
366 | #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) | |
39a53e0c | 367 | |
dfc08a12 CY |
368 | #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) |
369 | #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) | |
309cc2b6 | 370 | |
dfc08a12 | 371 | static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) |
39a53e0c | 372 | { |
dfc08a12 | 373 | int before = nats_in_cursum(journal); |
cac5a3d8 | 374 | |
dfc08a12 | 375 | journal->n_nats = cpu_to_le16(before + i); |
39a53e0c JK |
376 | return before; |
377 | } | |
378 | ||
dfc08a12 | 379 | static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) |
39a53e0c | 380 | { |
dfc08a12 | 381 | int before = sits_in_cursum(journal); |
cac5a3d8 | 382 | |
dfc08a12 | 383 | journal->n_sits = cpu_to_le16(before + i); |
39a53e0c JK |
384 | return before; |
385 | } | |
386 | ||
dfc08a12 CY |
387 | static inline bool __has_cursum_space(struct f2fs_journal *journal, |
388 | int size, int type) | |
184a5cd2 CY |
389 | { |
390 | if (type == NAT_JOURNAL) | |
dfc08a12 CY |
391 | return size <= MAX_NAT_JENTRIES(journal); |
392 | return size <= MAX_SIT_JENTRIES(journal); | |
184a5cd2 CY |
393 | } |
394 | ||
e9750824 NJ |
395 | /* |
396 | * ioctl commands | |
397 | */ | |
88b88a66 JK |
398 | #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS |
399 | #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS | |
d49f3e89 | 400 | #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION |
88b88a66 JK |
401 | |
402 | #define F2FS_IOCTL_MAGIC 0xf5 | |
403 | #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) | |
404 | #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) | |
02a1335f | 405 | #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) |
1e84371f JK |
406 | #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) |
407 | #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) | |
d07efb50 | 408 | #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32) |
456b88e4 | 409 | #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) |
d07efb50 JK |
410 | #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \ |
411 | struct f2fs_defragment) | |
4dd6f977 JK |
412 | #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ |
413 | struct f2fs_move_range) | |
e066b83c JK |
414 | #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ |
415 | struct f2fs_flush_device) | |
34dc77ad JK |
416 | #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ |
417 | struct f2fs_gc_range) | |
e65ef207 | 418 | #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) |
1ad71a27 JK |
419 | #define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32) |
420 | #define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32) | |
c4020b2d | 421 | #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) |
04f0b2ea | 422 | #define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64) |
e9750824 | 423 | |
4507847c CY |
424 | #define F2FS_IOC_GET_VOLUME_NAME FS_IOC_GETFSLABEL |
425 | #define F2FS_IOC_SET_VOLUME_NAME FS_IOC_SETFSLABEL | |
426 | ||
0b81d077 JK |
427 | #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY |
428 | #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY | |
429 | #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT | |
f424f664 | 430 | |
1abff93d JK |
431 | /* |
432 | * should be same as XFS_IOC_GOINGDOWN. | |
433 | * Flags for going down operation used by FS_IOC_GOINGDOWN | |
434 | */ | |
435 | #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ | |
436 | #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ | |
437 | #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ | |
438 | #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ | |
c912a829 | 439 | #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ |
0cd6d9b0 | 440 | #define F2FS_GOING_DOWN_NEED_FSCK 0x4 /* going down to trigger fsck */ |
1abff93d | 441 | |
e9750824 NJ |
442 | #if defined(__KERNEL__) && defined(CONFIG_COMPAT) |
443 | /* | |
444 | * ioctl commands in 32 bit emulation | |
445 | */ | |
04ef4b62 CY |
446 | #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS |
447 | #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS | |
448 | #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION | |
e9750824 NJ |
449 | #endif |
450 | ||
2c1d0305 CY |
451 | #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR |
452 | #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR | |
453 | ||
34dc77ad JK |
454 | struct f2fs_gc_range { |
455 | u32 sync; | |
456 | u64 start; | |
457 | u64 len; | |
458 | }; | |
459 | ||
d323d005 CY |
460 | struct f2fs_defragment { |
461 | u64 start; | |
462 | u64 len; | |
463 | }; | |
464 | ||
4dd6f977 JK |
465 | struct f2fs_move_range { |
466 | u32 dst_fd; /* destination fd */ | |
467 | u64 pos_in; /* start position in src_fd */ | |
468 | u64 pos_out; /* start position in dst_fd */ | |
469 | u64 len; /* size to move */ | |
470 | }; | |
471 | ||
e066b83c JK |
472 | struct f2fs_flush_device { |
473 | u32 dev_num; /* device number to flush */ | |
474 | u32 segments; /* # of segments to flush */ | |
475 | }; | |
476 | ||
f2470371 CY |
477 | /* for inline stuff */ |
478 | #define DEF_INLINE_RESERVED_SIZE 1 | |
7a2af766 | 479 | static inline int get_extra_isize(struct inode *inode); |
6afc662e | 480 | static inline int get_inline_xattr_addrs(struct inode *inode); |
6afc662e CY |
481 | #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ |
482 | (CUR_ADDRS_PER_INODE(inode) - \ | |
b323fd28 | 483 | get_inline_xattr_addrs(inode) - \ |
6afc662e | 484 | DEF_INLINE_RESERVED_SIZE)) |
f2470371 CY |
485 | |
486 | /* for inline dir */ | |
487 | #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ | |
488 | ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ | |
489 | BITS_PER_BYTE + 1)) | |
f91108b8 GU |
490 | #define INLINE_DENTRY_BITMAP_SIZE(inode) \ |
491 | DIV_ROUND_UP(NR_INLINE_DENTRY(inode), BITS_PER_BYTE) | |
f2470371 CY |
492 | #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ |
493 | ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ | |
494 | NR_INLINE_DENTRY(inode) + \ | |
495 | INLINE_DENTRY_BITMAP_SIZE(inode))) | |
496 | ||
39a53e0c JK |
497 | /* |
498 | * For INODE and NODE manager | |
499 | */ | |
7b3cd7d6 JK |
500 | /* for directory operations */ |
501 | struct f2fs_dentry_ptr { | |
d8c6822a | 502 | struct inode *inode; |
76a9dd85 | 503 | void *bitmap; |
7b3cd7d6 JK |
504 | struct f2fs_dir_entry *dentry; |
505 | __u8 (*filename)[F2FS_SLOT_LEN]; | |
506 | int max; | |
76a9dd85 | 507 | int nr_bitmap; |
7b3cd7d6 JK |
508 | }; |
509 | ||
64c24ecb TK |
510 | static inline void make_dentry_ptr_block(struct inode *inode, |
511 | struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) | |
7b3cd7d6 | 512 | { |
d8c6822a | 513 | d->inode = inode; |
64c24ecb | 514 | d->max = NR_DENTRY_IN_BLOCK; |
76a9dd85 | 515 | d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; |
c79d1520 | 516 | d->bitmap = t->dentry_bitmap; |
64c24ecb TK |
517 | d->dentry = t->dentry; |
518 | d->filename = t->filename; | |
519 | } | |
d8c6822a | 520 | |
64c24ecb | 521 | static inline void make_dentry_ptr_inline(struct inode *inode, |
f2470371 | 522 | struct f2fs_dentry_ptr *d, void *t) |
64c24ecb | 523 | { |
f2470371 CY |
524 | int entry_cnt = NR_INLINE_DENTRY(inode); |
525 | int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); | |
526 | int reserved_size = INLINE_RESERVED_SIZE(inode); | |
527 | ||
64c24ecb | 528 | d->inode = inode; |
f2470371 CY |
529 | d->max = entry_cnt; |
530 | d->nr_bitmap = bitmap_size; | |
531 | d->bitmap = t; | |
532 | d->dentry = t + bitmap_size + reserved_size; | |
533 | d->filename = t + bitmap_size + reserved_size + | |
534 | SIZE_OF_DIR_ENTRY * entry_cnt; | |
7b3cd7d6 JK |
535 | } |
536 | ||
dbe6a5ff JK |
537 | /* |
538 | * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 | |
539 | * as its node offset to distinguish from index node blocks. | |
540 | * But some bits are used to mark the node block. | |
541 | */ | |
542 | #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ | |
543 | >> OFFSET_BIT_SHIFT) | |
266e97a8 JK |
544 | enum { |
545 | ALLOC_NODE, /* allocate a new node page if needed */ | |
546 | LOOKUP_NODE, /* look up a node without readahead */ | |
547 | LOOKUP_NODE_RA, /* | |
548 | * look up a node with readahead called | |
4f4124d0 | 549 | * by get_data_block. |
39a53e0c | 550 | */ |
266e97a8 JK |
551 | }; |
552 | ||
7735730d CY |
553 | #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO count */ |
554 | ||
af033b2a CY |
555 | /* maximum retry quota flush count */ |
556 | #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT 8 | |
557 | ||
a6db67f0 | 558 | #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ |
39a53e0c | 559 | |
817202d9 CY |
560 | #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ |
561 | ||
39a53e0c | 562 | /* for in-memory extent cache entry */ |
13054c54 CY |
563 | #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ |
564 | ||
565 | /* number of extent info in extent cache we try to shrink */ | |
566 | #define EXTENT_CACHE_SHRINK_NUMBER 128 | |
c11abd1a | 567 | |
54c2258c CY |
568 | struct rb_entry { |
569 | struct rb_node rb_node; /* rb node located in rb-tree */ | |
570 | unsigned int ofs; /* start offset of the entry */ | |
571 | unsigned int len; /* length of the entry */ | |
572 | }; | |
573 | ||
39a53e0c | 574 | struct extent_info { |
13054c54 | 575 | unsigned int fofs; /* start offset in a file */ |
13054c54 | 576 | unsigned int len; /* length of the extent */ |
54c2258c | 577 | u32 blk; /* start block address of the extent */ |
13054c54 CY |
578 | }; |
579 | ||
580 | struct extent_node { | |
c0362117 CY |
581 | struct rb_node rb_node; /* rb node located in rb-tree */ |
582 | struct extent_info ei; /* extent info */ | |
13054c54 | 583 | struct list_head list; /* node in global extent list of sbi */ |
201ef5e0 | 584 | struct extent_tree *et; /* extent tree pointer */ |
13054c54 CY |
585 | }; |
586 | ||
587 | struct extent_tree { | |
588 | nid_t ino; /* inode number */ | |
4dada3fd | 589 | struct rb_root_cached root; /* root of extent info rb-tree */ |
62c8af65 | 590 | struct extent_node *cached_en; /* recently accessed extent node */ |
3e72f721 | 591 | struct extent_info largest; /* largested extent info */ |
137d09f0 | 592 | struct list_head list; /* to be used by sbi->zombie_list */ |
13054c54 | 593 | rwlock_t lock; /* protect extent info rb-tree */ |
68e35385 | 594 | atomic_t node_cnt; /* # of extent node in rb-tree*/ |
b430f726 | 595 | bool largest_updated; /* largest extent updated */ |
39a53e0c JK |
596 | }; |
597 | ||
003a3e1d JK |
598 | /* |
599 | * This structure is taken from ext4_map_blocks. | |
600 | * | |
601 | * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). | |
602 | */ | |
603 | #define F2FS_MAP_NEW (1 << BH_New) | |
604 | #define F2FS_MAP_MAPPED (1 << BH_Mapped) | |
7f63eb77 JK |
605 | #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) |
606 | #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ | |
607 | F2FS_MAP_UNWRITTEN) | |
003a3e1d JK |
608 | |
609 | struct f2fs_map_blocks { | |
610 | block_t m_pblk; | |
611 | block_t m_lblk; | |
612 | unsigned int m_len; | |
613 | unsigned int m_flags; | |
da85985c | 614 | pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ |
c4020b2d | 615 | pgoff_t *m_next_extent; /* point to next possible extent */ |
d5097be5 | 616 | int m_seg_type; |
f9d6d059 | 617 | bool m_may_create; /* indicate it is from write path */ |
003a3e1d JK |
618 | }; |
619 | ||
e2b4e2bc | 620 | /* for flag in get_data_block */ |
f2220c7f QS |
621 | enum { |
622 | F2FS_GET_BLOCK_DEFAULT, | |
623 | F2FS_GET_BLOCK_FIEMAP, | |
624 | F2FS_GET_BLOCK_BMAP, | |
0a4daae5 | 625 | F2FS_GET_BLOCK_DIO, |
f2220c7f QS |
626 | F2FS_GET_BLOCK_PRE_DIO, |
627 | F2FS_GET_BLOCK_PRE_AIO, | |
c4020b2d | 628 | F2FS_GET_BLOCK_PRECACHE, |
f2220c7f | 629 | }; |
e2b4e2bc | 630 | |
39a53e0c JK |
631 | /* |
632 | * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. | |
633 | */ | |
634 | #define FADVISE_COLD_BIT 0x01 | |
354a3399 | 635 | #define FADVISE_LOST_PINO_BIT 0x02 |
cde4de12 | 636 | #define FADVISE_ENCRYPT_BIT 0x04 |
e7d55452 | 637 | #define FADVISE_ENC_NAME_BIT 0x08 |
26787236 | 638 | #define FADVISE_KEEP_SIZE_BIT 0x10 |
b6a06cbb | 639 | #define FADVISE_HOT_BIT 0x20 |
95ae251f | 640 | #define FADVISE_VERITY_BIT 0x40 |
39a53e0c | 641 | |
797c1cb5 CY |
642 | #define FADVISE_MODIFIABLE_BITS (FADVISE_COLD_BIT | FADVISE_HOT_BIT) |
643 | ||
b5492af7 JK |
644 | #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) |
645 | #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) | |
646 | #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) | |
647 | #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) | |
648 | #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) | |
649 | #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) | |
cde4de12 JK |
650 | #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) |
651 | #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) | |
652 | #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) | |
e7d55452 JK |
653 | #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) |
654 | #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) | |
26787236 JK |
655 | #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) |
656 | #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) | |
b6a06cbb CY |
657 | #define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT) |
658 | #define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT) | |
659 | #define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT) | |
95ae251f EB |
660 | #define file_is_verity(inode) is_file(inode, FADVISE_VERITY_BIT) |
661 | #define file_set_verity(inode) set_file(inode, FADVISE_VERITY_BIT) | |
cde4de12 | 662 | |
ab9fa662 JK |
663 | #define DEF_DIR_LEVEL 0 |
664 | ||
2ef79ecb CY |
665 | enum { |
666 | GC_FAILURE_PIN, | |
667 | GC_FAILURE_ATOMIC, | |
668 | MAX_GC_FAILURE | |
669 | }; | |
670 | ||
39a53e0c JK |
671 | struct f2fs_inode_info { |
672 | struct inode vfs_inode; /* serve a vfs inode */ | |
673 | unsigned long i_flags; /* keep an inode flags for ioctl */ | |
674 | unsigned char i_advise; /* use to give file attribute hints */ | |
38431545 | 675 | unsigned char i_dir_level; /* use for dentry level for large dir */ |
2ef79ecb CY |
676 | unsigned int i_current_depth; /* only for directory depth */ |
677 | /* for gc failure statistic */ | |
678 | unsigned int i_gc_failures[MAX_GC_FAILURE]; | |
6666e6aa | 679 | unsigned int i_pino; /* parent inode number */ |
39a53e0c JK |
680 | umode_t i_acl_mode; /* keep file acl mode temporarily */ |
681 | ||
682 | /* Use below internally in f2fs*/ | |
683 | unsigned long flags; /* use to pass per-file flags */ | |
d928bfbf | 684 | struct rw_semaphore i_sem; /* protect fi info */ |
204706c7 | 685 | atomic_t dirty_pages; /* # of dirty pages */ |
39a53e0c JK |
686 | f2fs_hash_t chash; /* hash value of given file name */ |
687 | unsigned int clevel; /* maximum level of given file name */ | |
88c5c13a | 688 | struct task_struct *task; /* lookup and create consistency */ |
b0af6d49 | 689 | struct task_struct *cp_task; /* separate cp/wb IO stats*/ |
39a53e0c | 690 | nid_t i_xattr_nid; /* node id that contains xattrs */ |
26de9b11 | 691 | loff_t last_disk_size; /* lastly written file size */ |
88b88a66 | 692 | |
0abd675e CY |
693 | #ifdef CONFIG_QUOTA |
694 | struct dquot *i_dquot[MAXQUOTAS]; | |
695 | ||
696 | /* quota space reservation, managed internally by quota code */ | |
697 | qsize_t i_reserved_quota; | |
698 | #endif | |
0f18b462 JK |
699 | struct list_head dirty_list; /* dirty list for dirs and files */ |
700 | struct list_head gdirty_list; /* linked in global dirty list */ | |
57864ae5 | 701 | struct list_head inmem_ilist; /* list for inmem inodes */ |
88b88a66 | 702 | struct list_head inmem_pages; /* inmemory pages managed by f2fs */ |
7a10f017 | 703 | struct task_struct *inmem_task; /* store inmemory task */ |
88b88a66 | 704 | struct mutex inmem_lock; /* lock for inmemory pages */ |
3e72f721 | 705 | struct extent_tree *extent_tree; /* cached extent_tree entry */ |
b2532c69 CY |
706 | |
707 | /* avoid racing between foreground op and gc */ | |
708 | struct rw_semaphore i_gc_rwsem[2]; | |
5a3a2d83 | 709 | struct rw_semaphore i_mmap_sem; |
27161f13 | 710 | struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ |
f2470371 | 711 | |
7a2af766 | 712 | int i_extra_isize; /* size of extra space located in i_addr */ |
5c57132e | 713 | kprojid_t i_projid; /* id for project quota */ |
6afc662e | 714 | int i_inline_xattr_size; /* inline xattr size */ |
24b81dfc AB |
715 | struct timespec64 i_crtime; /* inode creation time */ |
716 | struct timespec64 i_disk_time[4];/* inode disk times */ | |
39a53e0c JK |
717 | }; |
718 | ||
719 | static inline void get_extent_info(struct extent_info *ext, | |
bd933d4f | 720 | struct f2fs_extent *i_ext) |
39a53e0c | 721 | { |
bd933d4f CY |
722 | ext->fofs = le32_to_cpu(i_ext->fofs); |
723 | ext->blk = le32_to_cpu(i_ext->blk); | |
724 | ext->len = le32_to_cpu(i_ext->len); | |
39a53e0c JK |
725 | } |
726 | ||
727 | static inline void set_raw_extent(struct extent_info *ext, | |
728 | struct f2fs_extent *i_ext) | |
729 | { | |
39a53e0c | 730 | i_ext->fofs = cpu_to_le32(ext->fofs); |
4d0b0bd4 | 731 | i_ext->blk = cpu_to_le32(ext->blk); |
39a53e0c | 732 | i_ext->len = cpu_to_le32(ext->len); |
39a53e0c JK |
733 | } |
734 | ||
429511cd CY |
735 | static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, |
736 | u32 blk, unsigned int len) | |
737 | { | |
738 | ei->fofs = fofs; | |
739 | ei->blk = blk; | |
740 | ei->len = len; | |
741 | } | |
742 | ||
004b6862 | 743 | static inline bool __is_discard_mergeable(struct discard_info *back, |
35ec7d57 | 744 | struct discard_info *front, unsigned int max_len) |
004b6862 | 745 | { |
9a997188 | 746 | return (back->lstart + back->len == front->lstart) && |
35ec7d57 | 747 | (back->len + front->len <= max_len); |
004b6862 CY |
748 | } |
749 | ||
750 | static inline bool __is_discard_back_mergeable(struct discard_info *cur, | |
35ec7d57 | 751 | struct discard_info *back, unsigned int max_len) |
004b6862 | 752 | { |
35ec7d57 | 753 | return __is_discard_mergeable(back, cur, max_len); |
004b6862 CY |
754 | } |
755 | ||
756 | static inline bool __is_discard_front_mergeable(struct discard_info *cur, | |
35ec7d57 | 757 | struct discard_info *front, unsigned int max_len) |
004b6862 | 758 | { |
35ec7d57 | 759 | return __is_discard_mergeable(cur, front, max_len); |
004b6862 CY |
760 | } |
761 | ||
429511cd CY |
762 | static inline bool __is_extent_mergeable(struct extent_info *back, |
763 | struct extent_info *front) | |
764 | { | |
765 | return (back->fofs + back->len == front->fofs && | |
766 | back->blk + back->len == front->blk); | |
767 | } | |
768 | ||
769 | static inline bool __is_back_mergeable(struct extent_info *cur, | |
770 | struct extent_info *back) | |
771 | { | |
772 | return __is_extent_mergeable(back, cur); | |
773 | } | |
774 | ||
775 | static inline bool __is_front_mergeable(struct extent_info *cur, | |
776 | struct extent_info *front) | |
777 | { | |
778 | return __is_extent_mergeable(cur, front); | |
779 | } | |
780 | ||
cac5a3d8 | 781 | extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); |
b430f726 ZZ |
782 | static inline void __try_update_largest_extent(struct extent_tree *et, |
783 | struct extent_node *en) | |
4abd3f5a | 784 | { |
205b9822 | 785 | if (en->ei.len > et->largest.len) { |
4abd3f5a | 786 | et->largest = en->ei; |
b430f726 | 787 | et->largest_updated = true; |
205b9822 | 788 | } |
4abd3f5a CY |
789 | } |
790 | ||
9a4ffdf5 CY |
791 | /* |
792 | * For free nid management | |
793 | */ | |
794 | enum nid_state { | |
795 | FREE_NID, /* newly added to free nid list */ | |
796 | PREALLOC_NID, /* it is preallocated */ | |
797 | MAX_NID_STATE, | |
b8559dc2 CY |
798 | }; |
799 | ||
17c2c8ac JK |
800 | enum nat_state { |
801 | TOTAL_NAT, | |
802 | DIRTY_NAT, | |
803 | RECLAIMABLE_NAT, | |
804 | MAX_NAT_STATE, | |
805 | }; | |
806 | ||
39a53e0c JK |
807 | struct f2fs_nm_info { |
808 | block_t nat_blkaddr; /* base disk address of NAT */ | |
809 | nid_t max_nid; /* maximum possible node ids */ | |
04d47e67 | 810 | nid_t available_nids; /* # of available node ids */ |
39a53e0c | 811 | nid_t next_scan_nid; /* the next nid to be scanned */ |
cdfc41c1 | 812 | unsigned int ram_thresh; /* control the memory footprint */ |
ea1a29a0 | 813 | unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ |
2304cb0c | 814 | unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ |
39a53e0c JK |
815 | |
816 | /* NAT cache management */ | |
817 | struct radix_tree_root nat_root;/* root of the nat entry cache */ | |
309cc2b6 | 818 | struct radix_tree_root nat_set_root;/* root of the nat set cache */ |
b873b798 | 819 | struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ |
39a53e0c | 820 | struct list_head nat_entries; /* cached nat entry list (clean) */ |
22969158 | 821 | spinlock_t nat_list_lock; /* protect clean nat entry list */ |
17c2c8ac | 822 | unsigned int nat_cnt[MAX_NAT_STATE]; /* the # of cached nat entries */ |
22ad0b6a | 823 | unsigned int nat_blocks; /* # of nat blocks */ |
39a53e0c JK |
824 | |
825 | /* free node ids management */ | |
8a7ed66a | 826 | struct radix_tree_root free_nid_root;/* root of the free_nid cache */ |
9a4ffdf5 CY |
827 | struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ |
828 | unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ | |
b8559dc2 | 829 | spinlock_t nid_list_lock; /* protect nid lists ops */ |
39a53e0c | 830 | struct mutex build_lock; /* lock for build free nids */ |
bb1105e4 | 831 | unsigned char **free_nid_bitmap; |
4ac91242 | 832 | unsigned char *nat_block_bitmap; |
586d1492 | 833 | unsigned short *free_nid_count; /* free nid count of NAT block */ |
39a53e0c JK |
834 | |
835 | /* for checkpoint */ | |
836 | char *nat_bitmap; /* NAT bitmap pointer */ | |
22ad0b6a JK |
837 | |
838 | unsigned int nat_bits_blocks; /* # of nat bits blocks */ | |
839 | unsigned char *nat_bits; /* NAT bits blocks */ | |
840 | unsigned char *full_nat_bits; /* full NAT pages */ | |
841 | unsigned char *empty_nat_bits; /* empty NAT pages */ | |
599a09b2 CY |
842 | #ifdef CONFIG_F2FS_CHECK_FS |
843 | char *nat_bitmap_mir; /* NAT bitmap mirror */ | |
844 | #endif | |
39a53e0c JK |
845 | int bitmap_size; /* bitmap size */ |
846 | }; | |
847 | ||
848 | /* | |
849 | * this structure is used as one of function parameters. | |
850 | * all the information are dedicated to a given direct node block determined | |
851 | * by the data offset in a file. | |
852 | */ | |
853 | struct dnode_of_data { | |
854 | struct inode *inode; /* vfs inode pointer */ | |
855 | struct page *inode_page; /* its inode page, NULL is possible */ | |
856 | struct page *node_page; /* cached direct node page */ | |
857 | nid_t nid; /* node id of the direct node block */ | |
858 | unsigned int ofs_in_node; /* data offset in the node page */ | |
859 | bool inode_page_locked; /* inode page is locked or not */ | |
93bae099 | 860 | bool node_changed; /* is node block changed */ |
3cf45747 CY |
861 | char cur_level; /* level of hole node page */ |
862 | char max_level; /* level of current page located */ | |
39a53e0c JK |
863 | block_t data_blkaddr; /* block address of the node block */ |
864 | }; | |
865 | ||
866 | static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, | |
867 | struct page *ipage, struct page *npage, nid_t nid) | |
868 | { | |
d66d1f76 | 869 | memset(dn, 0, sizeof(*dn)); |
39a53e0c JK |
870 | dn->inode = inode; |
871 | dn->inode_page = ipage; | |
872 | dn->node_page = npage; | |
873 | dn->nid = nid; | |
39a53e0c JK |
874 | } |
875 | ||
876 | /* | |
877 | * For SIT manager | |
878 | * | |
879 | * By default, there are 6 active log areas across the whole main area. | |
880 | * When considering hot and cold data separation to reduce cleaning overhead, | |
881 | * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, | |
882 | * respectively. | |
883 | * In the current design, you should not change the numbers intentionally. | |
884 | * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 | |
885 | * logs individually according to the underlying devices. (default: 6) | |
886 | * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for | |
887 | * data and 8 for node logs. | |
888 | */ | |
889 | #define NR_CURSEG_DATA_TYPE (3) | |
890 | #define NR_CURSEG_NODE_TYPE (3) | |
891 | #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) | |
892 | ||
893 | enum { | |
894 | CURSEG_HOT_DATA = 0, /* directory entry blocks */ | |
895 | CURSEG_WARM_DATA, /* data blocks */ | |
896 | CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ | |
897 | CURSEG_HOT_NODE, /* direct node blocks of directory files */ | |
898 | CURSEG_WARM_NODE, /* direct node blocks of normal files */ | |
899 | CURSEG_COLD_NODE, /* indirect node blocks */ | |
38aa0889 | 900 | NO_CHECK_TYPE, |
39a53e0c JK |
901 | }; |
902 | ||
6b4afdd7 | 903 | struct flush_cmd { |
6b4afdd7 | 904 | struct completion wait; |
721bd4d5 | 905 | struct llist_node llnode; |
39d787be | 906 | nid_t ino; |
6b4afdd7 JK |
907 | int ret; |
908 | }; | |
909 | ||
a688b9d9 GZ |
910 | struct flush_cmd_control { |
911 | struct task_struct *f2fs_issue_flush; /* flush thread */ | |
912 | wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ | |
8b8dd65f | 913 | atomic_t issued_flush; /* # of issued flushes */ |
72691af6 | 914 | atomic_t queued_flush; /* # of queued flushes */ |
721bd4d5 GZ |
915 | struct llist_head issue_list; /* list for command issue */ |
916 | struct llist_node *dispatch_list; /* list for command dispatch */ | |
a688b9d9 GZ |
917 | }; |
918 | ||
39a53e0c JK |
919 | struct f2fs_sm_info { |
920 | struct sit_info *sit_info; /* whole segment information */ | |
921 | struct free_segmap_info *free_info; /* free segment information */ | |
922 | struct dirty_seglist_info *dirty_info; /* dirty segment information */ | |
923 | struct curseg_info *curseg_array; /* active segment information */ | |
924 | ||
2b60311d CY |
925 | struct rw_semaphore curseg_lock; /* for preventing curseg change */ |
926 | ||
39a53e0c JK |
927 | block_t seg0_blkaddr; /* block address of 0'th segment */ |
928 | block_t main_blkaddr; /* start block address of main area */ | |
929 | block_t ssa_blkaddr; /* start block address of SSA area */ | |
930 | ||
931 | unsigned int segment_count; /* total # of segments */ | |
932 | unsigned int main_segments; /* # of segments in main area */ | |
933 | unsigned int reserved_segments; /* # of reserved segments */ | |
76fbc725 | 934 | unsigned int additional_reserved_segments;/* reserved segs for IO align feature */ |
39a53e0c | 935 | unsigned int ovp_segments; /* # of overprovision segments */ |
81eb8d6e JK |
936 | |
937 | /* a threshold to reclaim prefree segments */ | |
938 | unsigned int rec_prefree_segments; | |
7fd9e544 | 939 | |
bba681cb JK |
940 | /* for batched trimming */ |
941 | unsigned int trim_sections; /* # of sections to trim */ | |
942 | ||
184a5cd2 CY |
943 | struct list_head sit_entry_set; /* sit entry set list */ |
944 | ||
216fbd64 JK |
945 | unsigned int ipu_policy; /* in-place-update policy */ |
946 | unsigned int min_ipu_util; /* in-place-update threshold */ | |
c1ce1b02 | 947 | unsigned int min_fsync_blocks; /* threshold for fsync */ |
853137ce | 948 | unsigned int min_seq_blocks; /* threshold for sequential blocks */ |
ef095d19 | 949 | unsigned int min_hot_blocks; /* threshold for hot block allocation */ |
a2a12b67 | 950 | unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ |
6b4afdd7 JK |
951 | |
952 | /* for flush command control */ | |
b01a9201 | 953 | struct flush_cmd_control *fcc_info; |
a688b9d9 | 954 | |
0b54fb84 JK |
955 | /* for discard command control */ |
956 | struct discard_cmd_control *dcc_info; | |
39a53e0c JK |
957 | }; |
958 | ||
39a53e0c JK |
959 | /* |
960 | * For superblock | |
961 | */ | |
962 | /* | |
963 | * COUNT_TYPE for monitoring | |
964 | * | |
965 | * f2fs monitors the number of several block types such as on-writeback, | |
966 | * dirty dentry blocks, dirty node blocks, and dirty meta blocks. | |
967 | */ | |
36951b38 | 968 | #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) |
39a53e0c | 969 | enum count_type { |
39a53e0c | 970 | F2FS_DIRTY_DENTS, |
c227f912 | 971 | F2FS_DIRTY_DATA, |
2c8a4a28 | 972 | F2FS_DIRTY_QDATA, |
39a53e0c JK |
973 | F2FS_DIRTY_NODES, |
974 | F2FS_DIRTY_META, | |
8dcf2ff7 | 975 | F2FS_INMEM_PAGES, |
0f18b462 | 976 | F2FS_DIRTY_IMETA, |
36951b38 CY |
977 | F2FS_WB_CP_DATA, |
978 | F2FS_WB_DATA, | |
5f9abab4 JK |
979 | F2FS_RD_DATA, |
980 | F2FS_RD_NODE, | |
981 | F2FS_RD_META, | |
02b16d0a CY |
982 | F2FS_DIO_WRITE, |
983 | F2FS_DIO_READ, | |
39a53e0c JK |
984 | NR_COUNT_TYPE, |
985 | }; | |
986 | ||
39a53e0c | 987 | /* |
e1c42045 | 988 | * The below are the page types of bios used in submit_bio(). |
39a53e0c JK |
989 | * The available types are: |
990 | * DATA User data pages. It operates as async mode. | |
991 | * NODE Node pages. It operates as async mode. | |
992 | * META FS metadata pages such as SIT, NAT, CP. | |
993 | * NR_PAGE_TYPE The number of page types. | |
994 | * META_FLUSH Make sure the previous pages are written | |
995 | * with waiting the bio's completion | |
996 | * ... Only can be used with META. | |
997 | */ | |
7d5e5109 | 998 | #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) |
39a53e0c JK |
999 | enum page_type { |
1000 | DATA, | |
1001 | NODE, | |
1002 | META, | |
1003 | NR_PAGE_TYPE, | |
1004 | META_FLUSH, | |
8ce67cb0 JK |
1005 | INMEM, /* the below types are used by tracepoints only. */ |
1006 | INMEM_DROP, | |
8c242db9 | 1007 | INMEM_INVALIDATE, |
28bc106b | 1008 | INMEM_REVOKE, |
8ce67cb0 JK |
1009 | IPU, |
1010 | OPU, | |
39a53e0c JK |
1011 | }; |
1012 | ||
a912b54d JK |
1013 | enum temp_type { |
1014 | HOT = 0, /* must be zero for meta bio */ | |
1015 | WARM, | |
1016 | COLD, | |
1017 | NR_TEMP_TYPE, | |
1018 | }; | |
1019 | ||
cc15620b JK |
1020 | enum need_lock_type { |
1021 | LOCK_REQ = 0, | |
1022 | LOCK_DONE, | |
1023 | LOCK_RETRY, | |
1024 | }; | |
1025 | ||
a5fd5050 CY |
1026 | enum cp_reason_type { |
1027 | CP_NO_NEEDED, | |
1028 | CP_NON_REGULAR, | |
1029 | CP_HARDLINK, | |
1030 | CP_SB_NEED_CP, | |
1031 | CP_WRONG_PINO, | |
1032 | CP_NO_SPC_ROLL, | |
1033 | CP_NODE_NEED_CP, | |
1034 | CP_FASTBOOT_MODE, | |
1035 | CP_SPEC_LOG_NUM, | |
0a007b97 | 1036 | CP_RECOVER_DIR, |
a5fd5050 CY |
1037 | }; |
1038 | ||
b0af6d49 CY |
1039 | enum iostat_type { |
1040 | APP_DIRECT_IO, /* app direct IOs */ | |
1041 | APP_BUFFERED_IO, /* app buffered IOs */ | |
1042 | APP_WRITE_IO, /* app write IOs */ | |
1043 | APP_MAPPED_IO, /* app mapped IOs */ | |
1044 | FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ | |
1045 | FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ | |
1046 | FS_META_IO, /* meta IOs from kworker/reclaimer */ | |
1047 | FS_GC_DATA_IO, /* data IOs from forground gc */ | |
1048 | FS_GC_NODE_IO, /* node IOs from forground gc */ | |
1049 | FS_CP_DATA_IO, /* data IOs from checkpoint */ | |
1050 | FS_CP_NODE_IO, /* node IOs from checkpoint */ | |
1051 | FS_CP_META_IO, /* meta IOs from checkpoint */ | |
1052 | FS_DISCARD, /* discard */ | |
1053 | NR_IO_TYPE, | |
1054 | }; | |
1055 | ||
458e6197 | 1056 | struct f2fs_io_info { |
05ca3632 | 1057 | struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ |
39d787be | 1058 | nid_t ino; /* inode number */ |
7e8f2308 | 1059 | enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ |
a912b54d | 1060 | enum temp_type temp; /* contains HOT/WARM/COLD */ |
04d328de | 1061 | int op; /* contains REQ_OP_ */ |
ef295ecf | 1062 | int op_flags; /* req_flag_bits */ |
7a9d7548 | 1063 | block_t new_blkaddr; /* new block address to be written */ |
28bc106b | 1064 | block_t old_blkaddr; /* old block address before Cow */ |
05ca3632 | 1065 | struct page *page; /* page to be written */ |
4375a336 | 1066 | struct page *encrypted_page; /* encrypted page */ |
fb830fc5 | 1067 | struct list_head list; /* serialize IOs */ |
d68f735b | 1068 | bool submitted; /* indicate IO submission */ |
cc15620b | 1069 | int need_lock; /* indicate we need to lock cp_rwsem */ |
fb830fc5 | 1070 | bool in_list; /* indicate fio is in io_list */ |
6dc3a126 | 1071 | bool is_por; /* indicate IO is from recovery or not */ |
fe16efe6 | 1072 | bool retry; /* need to reallocate block address */ |
b0af6d49 | 1073 | enum iostat_type io_type; /* io type */ |
578c6478 | 1074 | struct writeback_control *io_wbc; /* writeback control */ |
8648de2c CY |
1075 | struct bio **bio; /* bio for ipu */ |
1076 | sector_t *last_block; /* last block number in bio */ | |
7735730d | 1077 | unsigned char version; /* version of the node */ |
458e6197 JK |
1078 | }; |
1079 | ||
68afcf2d | 1080 | #define is_read_io(rw) ((rw) == READ) |
1ff7bd3b | 1081 | struct f2fs_bio_info { |
458e6197 | 1082 | struct f2fs_sb_info *sbi; /* f2fs superblock */ |
1ff7bd3b JK |
1083 | struct bio *bio; /* bios to merge */ |
1084 | sector_t last_block_in_bio; /* last block number */ | |
458e6197 | 1085 | struct f2fs_io_info fio; /* store buffered io info. */ |
df0f8dc0 | 1086 | struct rw_semaphore io_rwsem; /* blocking op for bio */ |
fb830fc5 CY |
1087 | spinlock_t io_lock; /* serialize DATA/NODE IOs */ |
1088 | struct list_head io_list; /* track fios */ | |
1ff7bd3b JK |
1089 | }; |
1090 | ||
3c62be17 JK |
1091 | #define FDEV(i) (sbi->devs[i]) |
1092 | #define RDEV(i) (raw_super->devs[i]) | |
1093 | struct f2fs_dev_info { | |
1094 | struct block_device *bdev; | |
1095 | char path[MAX_PATH_LEN]; | |
1096 | unsigned int total_segments; | |
1097 | block_t start_blk; | |
1098 | block_t end_blk; | |
1099 | #ifdef CONFIG_BLK_DEV_ZONED | |
95175daf DLM |
1100 | unsigned int nr_blkz; /* Total number of zones */ |
1101 | unsigned long *blkz_seq; /* Bitmap indicating sequential zones */ | |
3c62be17 JK |
1102 | #endif |
1103 | }; | |
1104 | ||
c227f912 CY |
1105 | enum inode_type { |
1106 | DIR_INODE, /* for dirty dir inode */ | |
1107 | FILE_INODE, /* for dirty regular/symlink inode */ | |
0f18b462 | 1108 | DIRTY_META, /* for all dirtied inode metadata */ |
57864ae5 | 1109 | ATOMIC_FILE, /* for all atomic files */ |
c227f912 CY |
1110 | NR_INODE_TYPE, |
1111 | }; | |
1112 | ||
67298804 CY |
1113 | /* for inner inode cache management */ |
1114 | struct inode_management { | |
1115 | struct radix_tree_root ino_root; /* ino entry array */ | |
1116 | spinlock_t ino_lock; /* for ino entry lock */ | |
1117 | struct list_head ino_list; /* inode list head */ | |
1118 | unsigned long ino_num; /* number of entries */ | |
1119 | }; | |
1120 | ||
caf0047e CY |
1121 | /* For s_flag in struct f2fs_sb_info */ |
1122 | enum { | |
1123 | SBI_IS_DIRTY, /* dirty flag for checkpoint */ | |
1124 | SBI_IS_CLOSE, /* specify unmounting */ | |
1125 | SBI_NEED_FSCK, /* need fsck.f2fs to fix */ | |
1126 | SBI_POR_DOING, /* recovery is doing or not */ | |
df728b0f | 1127 | SBI_NEED_SB_WRITE, /* need to recover superblock */ |
bbf156f7 | 1128 | SBI_NEED_CP, /* need to checkpoint */ |
83a3bfdb | 1129 | SBI_IS_SHUTDOWN, /* shutdown by ioctl */ |
1378752b | 1130 | SBI_IS_RECOVERED, /* recovered orphan/data */ |
4354994f | 1131 | SBI_CP_DISABLED, /* CP was disabled last mount */ |
db610a64 | 1132 | SBI_CP_DISABLED_QUICK, /* CP was disabled quickly */ |
af033b2a CY |
1133 | SBI_QUOTA_NEED_FLUSH, /* need to flush quota info in CP */ |
1134 | SBI_QUOTA_SKIP_FLUSH, /* skip flushing quota in current CP */ | |
1135 | SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */ | |
04f0b2ea | 1136 | SBI_IS_RESIZEFS, /* resizefs is in process */ |
caf0047e CY |
1137 | }; |
1138 | ||
6beceb54 JK |
1139 | enum { |
1140 | CP_TIME, | |
d0239e1b | 1141 | REQ_TIME, |
a7d10cf3 ST |
1142 | DISCARD_TIME, |
1143 | GC_TIME, | |
4354994f | 1144 | DISABLE_TIME, |
03f2c02d | 1145 | UMOUNT_DISCARD_TIMEOUT, |
6beceb54 JK |
1146 | MAX_TIME, |
1147 | }; | |
1148 | ||
5b0e9539 JK |
1149 | enum { |
1150 | GC_NORMAL, | |
1151 | GC_IDLE_CB, | |
1152 | GC_IDLE_GREEDY, | |
1153 | GC_URGENT, | |
1154 | }; | |
1155 | ||
0cdd3195 HL |
1156 | enum { |
1157 | WHINT_MODE_OFF, /* not pass down write hints */ | |
1158 | WHINT_MODE_USER, /* try to pass down hints given by users */ | |
f2e703f9 | 1159 | WHINT_MODE_FS, /* pass down hints with F2FS policy */ |
0cdd3195 HL |
1160 | }; |
1161 | ||
07939627 JK |
1162 | enum { |
1163 | ALLOC_MODE_DEFAULT, /* stay default */ | |
1164 | ALLOC_MODE_REUSE, /* reuse segments as much as possible */ | |
1165 | }; | |
1166 | ||
93cf93f1 JZ |
1167 | enum fsync_mode { |
1168 | FSYNC_MODE_POSIX, /* fsync follows posix semantics */ | |
1169 | FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */ | |
d6290814 | 1170 | FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */ |
93cf93f1 JZ |
1171 | }; |
1172 | ||
643fa961 | 1173 | #ifdef CONFIG_FS_ENCRYPTION |
ff62af20 SY |
1174 | #define DUMMY_ENCRYPTION_ENABLED(sbi) \ |
1175 | (unlikely(F2FS_OPTION(sbi).test_dummy_encryption)) | |
1176 | #else | |
1177 | #define DUMMY_ENCRYPTION_ENABLED(sbi) (0) | |
1178 | #endif | |
1179 | ||
39a53e0c JK |
1180 | struct f2fs_sb_info { |
1181 | struct super_block *sb; /* pointer to VFS super block */ | |
5e176d54 | 1182 | struct proc_dir_entry *s_proc; /* proc entry */ |
39a53e0c | 1183 | struct f2fs_super_block *raw_super; /* raw super block pointer */ |
846ae671 | 1184 | struct rw_semaphore sb_lock; /* lock for raw super block */ |
e8240f65 | 1185 | int valid_super_block; /* valid super block no */ |
fadb2fb8 | 1186 | unsigned long s_flag; /* flags for sbi */ |
853137ce | 1187 | struct mutex writepages; /* mutex for writepages() */ |
5aba5430 DR |
1188 | #ifdef CONFIG_UNICODE |
1189 | struct unicode_map *s_encoding; | |
1190 | __u16 s_encoding_flags; | |
1191 | #endif | |
39a53e0c | 1192 | |
178053e2 | 1193 | #ifdef CONFIG_BLK_DEV_ZONED |
178053e2 DLM |
1194 | unsigned int blocks_per_blkz; /* F2FS blocks per zone */ |
1195 | unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ | |
178053e2 DLM |
1196 | #endif |
1197 | ||
39a53e0c JK |
1198 | /* for node-related operations */ |
1199 | struct f2fs_nm_info *nm_info; /* node manager */ | |
1200 | struct inode *node_inode; /* cache node blocks */ | |
1201 | ||
1202 | /* for segment-related operations */ | |
1203 | struct f2fs_sm_info *sm_info; /* segment manager */ | |
1ff7bd3b JK |
1204 | |
1205 | /* for bio operations */ | |
a912b54d | 1206 | struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ |
107a805d CY |
1207 | /* keep migration IO order for LFS mode */ |
1208 | struct rw_semaphore io_order_lock; | |
0a595eba | 1209 | mempool_t *write_io_dummy; /* Dummy pages */ |
39a53e0c JK |
1210 | |
1211 | /* for checkpoint */ | |
1212 | struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ | |
8508e44a | 1213 | int cur_cp_pack; /* remain current cp pack */ |
aaec2b1d | 1214 | spinlock_t cp_lock; /* for flag in ckpt */ |
39a53e0c | 1215 | struct inode *meta_inode; /* cache meta blocks */ |
39936837 | 1216 | struct mutex cp_mutex; /* checkpoint procedure lock */ |
b873b798 | 1217 | struct rw_semaphore cp_rwsem; /* blocking FS operations */ |
b3582c68 | 1218 | struct rw_semaphore node_write; /* locking node writes */ |
59c9081b | 1219 | struct rw_semaphore node_change; /* locking node change */ |
fb51b5ef | 1220 | wait_queue_head_t cp_wait; |
6beceb54 JK |
1221 | unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ |
1222 | long interval_time[MAX_TIME]; /* to store thresholds */ | |
39a53e0c | 1223 | |
67298804 | 1224 | struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ |
6451e041 | 1225 | |
50fa53ec CY |
1226 | spinlock_t fsync_node_lock; /* for node entry lock */ |
1227 | struct list_head fsync_node_list; /* node list head */ | |
1228 | unsigned int fsync_seg_id; /* sequence id */ | |
1229 | unsigned int fsync_node_num; /* number of node entries */ | |
1230 | ||
6451e041 | 1231 | /* for orphan inode, use 0'th array */ |
0d47c1ad | 1232 | unsigned int max_orphans; /* max orphan inodes */ |
39a53e0c | 1233 | |
c227f912 CY |
1234 | /* for inode management */ |
1235 | struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ | |
1236 | spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ | |
040d2bb3 | 1237 | struct mutex flush_lock; /* for flush exclusion */ |
39a53e0c | 1238 | |
13054c54 CY |
1239 | /* for extent tree cache */ |
1240 | struct radix_tree_root extent_tree_root;/* cache extent cache entries */ | |
5e8256ac | 1241 | struct mutex extent_tree_lock; /* locking extent radix tree */ |
13054c54 CY |
1242 | struct list_head extent_list; /* lru list for shrinker */ |
1243 | spinlock_t extent_lock; /* locking extent lru list */ | |
7441ccef | 1244 | atomic_t total_ext_tree; /* extent tree count */ |
137d09f0 | 1245 | struct list_head zombie_list; /* extent zombie tree list */ |
74fd8d99 | 1246 | atomic_t total_zombie_tree; /* extent zombie tree count */ |
13054c54 CY |
1247 | atomic_t total_ext_node; /* extent info count */ |
1248 | ||
e1c42045 | 1249 | /* basic filesystem units */ |
39a53e0c JK |
1250 | unsigned int log_sectors_per_block; /* log2 sectors per block */ |
1251 | unsigned int log_blocksize; /* log2 block size */ | |
1252 | unsigned int blocksize; /* block size */ | |
1253 | unsigned int root_ino_num; /* root inode number*/ | |
1254 | unsigned int node_ino_num; /* node inode number*/ | |
1255 | unsigned int meta_ino_num; /* meta inode number*/ | |
1256 | unsigned int log_blocks_per_seg; /* log2 blocks per segment */ | |
1257 | unsigned int blocks_per_seg; /* blocks per segment */ | |
1258 | unsigned int segs_per_sec; /* segments per section */ | |
1259 | unsigned int secs_per_zone; /* sections per zone */ | |
1260 | unsigned int total_sections; /* total section count */ | |
04f0b2ea | 1261 | struct mutex resize_mutex; /* for resize exclusion */ |
39a53e0c JK |
1262 | unsigned int total_node_count; /* total node block count */ |
1263 | unsigned int total_valid_node_count; /* valid node block count */ | |
e0afc4d6 | 1264 | loff_t max_file_blocks; /* max block index of file */ |
ab9fa662 | 1265 | int dir_level; /* directory level */ |
f6df8f23 | 1266 | int readdir_ra; /* readahead inode in readdir */ |
39a53e0c JK |
1267 | |
1268 | block_t user_block_count; /* # of user blocks */ | |
1269 | block_t total_valid_block_count; /* # of valid blocks */ | |
a66cdd98 | 1270 | block_t discard_blks; /* discard command candidats */ |
39a53e0c | 1271 | block_t last_valid_block_count; /* for recovery */ |
daeb433e | 1272 | block_t reserved_blocks; /* configurable reserved blocks */ |
80d42145 | 1273 | block_t current_reserved_blocks; /* current reserved blocks */ |
daeb433e | 1274 | |
4354994f DR |
1275 | /* Additional tracking for no checkpoint mode */ |
1276 | block_t unusable_block_count; /* # of blocks saved by last cp */ | |
1277 | ||
292c196a | 1278 | unsigned int nquota_files; /* # of quota sysfile */ |
db6ec53b | 1279 | struct rw_semaphore quota_sem; /* blocking cp for flags */ |
292c196a | 1280 | |
523be8a6 | 1281 | /* # of pages, see count_type */ |
35782b23 | 1282 | atomic_t nr_pages[NR_COUNT_TYPE]; |
41382ec4 JK |
1283 | /* # of allocated blocks */ |
1284 | struct percpu_counter alloc_valid_block_count; | |
39a53e0c | 1285 | |
687de7f1 | 1286 | /* writeback control */ |
c29fd0c0 | 1287 | atomic_t wb_sync_req[META]; /* count # of WB_SYNC threads */ |
687de7f1 | 1288 | |
513c5f37 JK |
1289 | /* valid inode count */ |
1290 | struct percpu_counter total_valid_inode_count; | |
1291 | ||
39a53e0c JK |
1292 | struct f2fs_mount_info mount_opt; /* mount options */ |
1293 | ||
1294 | /* for cleaning operations */ | |
1295 | struct mutex gc_mutex; /* mutex for GC */ | |
1296 | struct f2fs_gc_kthread *gc_thread; /* GC thread */ | |
5ec4e49f | 1297 | unsigned int cur_victim_sec; /* current victim section num */ |
5b0e9539 | 1298 | unsigned int gc_mode; /* current GC state */ |
e3080b01 | 1299 | unsigned int next_victim_seg[2]; /* next segment in victim section */ |
2ef79ecb | 1300 | /* for skip statistic */ |
a22852e9 | 1301 | unsigned int atomic_files; /* # of opened atomic file */ |
2ef79ecb | 1302 | unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */ |
6f8d4455 | 1303 | unsigned long long skipped_gc_rwsem; /* FG_GC only */ |
39a53e0c | 1304 | |
1ad71a27 JK |
1305 | /* threshold for gc trials on pinned files */ |
1306 | u64 gc_pin_file_threshold; | |
1307 | ||
b1c57c1c JK |
1308 | /* maximum # of trials to find a victim segment for SSR and GC */ |
1309 | unsigned int max_victim_search; | |
e3080b01 CY |
1310 | /* migration granularity of garbage collection, unit: segment */ |
1311 | unsigned int migration_granularity; | |
b1c57c1c | 1312 | |
39a53e0c JK |
1313 | /* |
1314 | * for stat information. | |
1315 | * one is for the LFS mode, and the other is for the SSR mode. | |
1316 | */ | |
35b09d82 | 1317 | #ifdef CONFIG_F2FS_STAT_FS |
39a53e0c | 1318 | struct f2fs_stat_info *stat_info; /* FS status information */ |
b63e7be5 | 1319 | atomic_t meta_count[META_MAX]; /* # of meta blocks */ |
39a53e0c JK |
1320 | unsigned int segment_count[2]; /* # of allocated segments */ |
1321 | unsigned int block_count[2]; /* # of allocated blocks */ | |
b9a2c252 | 1322 | atomic_t inplace_count; /* # of inplace update */ |
5b7ee374 CY |
1323 | atomic64_t total_hit_ext; /* # of lookup extent cache */ |
1324 | atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ | |
1325 | atomic64_t read_hit_largest; /* # of hit largest extent node */ | |
1326 | atomic64_t read_hit_cached; /* # of hit cached extent node */ | |
d5e8f6c9 | 1327 | atomic_t inline_xattr; /* # of inline_xattr inodes */ |
03e14d52 CY |
1328 | atomic_t inline_inode; /* # of inline_data inodes */ |
1329 | atomic_t inline_dir; /* # of inline_dentry inodes */ | |
26a28a0c | 1330 | atomic_t aw_cnt; /* # of atomic writes */ |
648d50ba | 1331 | atomic_t vw_cnt; /* # of volatile writes */ |
26a28a0c | 1332 | atomic_t max_aw_cnt; /* max # of atomic writes */ |
648d50ba | 1333 | atomic_t max_vw_cnt; /* max # of volatile writes */ |
39a53e0c | 1334 | int bg_gc; /* background gc calls */ |
274bd9ba CY |
1335 | unsigned int io_skip_bggc; /* skip background gc for in-flight IO */ |
1336 | unsigned int other_skip_bggc; /* skip background gc for other reasons */ | |
33fbd510 | 1337 | unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ |
35b09d82 | 1338 | #endif |
39a53e0c | 1339 | spinlock_t stat_lock; /* lock for stat operations */ |
b59d0bae | 1340 | |
b0af6d49 CY |
1341 | /* For app/fs IO statistics */ |
1342 | spinlock_t iostat_lock; | |
1343 | unsigned long long write_iostat[NR_IO_TYPE]; | |
1344 | bool iostat_enable; | |
1345 | ||
b59d0bae NJ |
1346 | /* For sysfs suppport */ |
1347 | struct kobject s_kobj; | |
1348 | struct completion s_kobj_unregister; | |
2658e50d JK |
1349 | |
1350 | /* For shrinker support */ | |
1351 | struct list_head s_list; | |
3c62be17 JK |
1352 | int s_ndevs; /* number of devices */ |
1353 | struct f2fs_dev_info *devs; /* for device list */ | |
1228b482 CY |
1354 | unsigned int dirty_device; /* for checkpoint data flush */ |
1355 | spinlock_t dev_lock; /* protect dirty_device */ | |
2658e50d JK |
1356 | struct mutex umount_mutex; |
1357 | unsigned int shrinker_run_no; | |
8f1dbbbb SL |
1358 | |
1359 | /* For write statistics */ | |
1360 | u64 sectors_written_start; | |
1361 | u64 kbytes_written; | |
43b6573b KM |
1362 | |
1363 | /* Reference to checksum algorithm driver via cryptoapi */ | |
1364 | struct crypto_shash *s_chksum_driver; | |
1ecc0c5c | 1365 | |
704956ec CY |
1366 | /* Precomputed FS UUID checksum for seeding other checksums */ |
1367 | __u32 s_chksum_seed; | |
39a53e0c JK |
1368 | }; |
1369 | ||
02b16d0a CY |
1370 | struct f2fs_private_dio { |
1371 | struct inode *inode; | |
1372 | void *orig_private; | |
1373 | bio_end_io_t *orig_end_io; | |
1374 | bool write; | |
1375 | }; | |
1376 | ||
1ecc0c5c | 1377 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
93fb7d35 CY |
1378 | #define f2fs_show_injection_info(sbi, type) \ |
1379 | printk_ratelimited("%sF2FS-fs (%s) : inject %s in %s of %pS\n", \ | |
1380 | KERN_INFO, sbi->sb->s_id, \ | |
1381 | f2fs_fault_name[type], \ | |
55523519 | 1382 | __func__, __builtin_return_address(0)) |
1ecc0c5c CY |
1383 | static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) |
1384 | { | |
63189b78 | 1385 | struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; |
1ecc0c5c CY |
1386 | |
1387 | if (!ffi->inject_rate) | |
1388 | return false; | |
1389 | ||
1390 | if (!IS_FAULT_SET(ffi, type)) | |
1391 | return false; | |
1392 | ||
1393 | atomic_inc(&ffi->inject_ops); | |
1394 | if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { | |
1395 | atomic_set(&ffi->inject_ops, 0); | |
1ecc0c5c CY |
1396 | return true; |
1397 | } | |
1398 | return false; | |
1399 | } | |
7fa750a1 | 1400 | #else |
93fb7d35 | 1401 | #define f2fs_show_injection_info(sbi, type) do { } while (0) |
7fa750a1 AB |
1402 | static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) |
1403 | { | |
1404 | return false; | |
1405 | } | |
1ecc0c5c CY |
1406 | #endif |
1407 | ||
0916878d DLM |
1408 | /* |
1409 | * Test if the mounted volume is a multi-device volume. | |
1410 | * - For a single regular disk volume, sbi->s_ndevs is 0. | |
1411 | * - For a single zoned disk volume, sbi->s_ndevs is 1. | |
1412 | * - For a multi-device volume, sbi->s_ndevs is always 2 or more. | |
1413 | */ | |
1414 | static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi) | |
1415 | { | |
1416 | return sbi->s_ndevs > 1; | |
1417 | } | |
1418 | ||
8f1dbbbb SL |
1419 | /* For write statistics. Suppose sector size is 512 bytes, |
1420 | * and the return value is in kbytes. s is of struct f2fs_sb_info. | |
1421 | */ | |
1422 | #define BD_PART_WRITTEN(s) \ | |
dbae2c55 | 1423 | (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[STAT_WRITE]) - \ |
68afcf2d | 1424 | (s)->sectors_written_start) >> 1) |
8f1dbbbb | 1425 | |
6beceb54 JK |
1426 | static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) |
1427 | { | |
a7d10cf3 ST |
1428 | unsigned long now = jiffies; |
1429 | ||
1430 | sbi->last_time[type] = now; | |
1431 | ||
1432 | /* DISCARD_TIME and GC_TIME are based on REQ_TIME */ | |
1433 | if (type == REQ_TIME) { | |
1434 | sbi->last_time[DISCARD_TIME] = now; | |
1435 | sbi->last_time[GC_TIME] = now; | |
1436 | } | |
6beceb54 JK |
1437 | } |
1438 | ||
1439 | static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) | |
1440 | { | |
6bccfa19 | 1441 | unsigned long interval = sbi->interval_time[type] * HZ; |
6beceb54 JK |
1442 | |
1443 | return time_after(jiffies, sbi->last_time[type] + interval); | |
1444 | } | |
1445 | ||
a7d10cf3 ST |
1446 | static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi, |
1447 | int type) | |
1448 | { | |
1449 | unsigned long interval = sbi->interval_time[type] * HZ; | |
1450 | unsigned int wait_ms = 0; | |
1451 | long delta; | |
1452 | ||
1453 | delta = (sbi->last_time[type] + interval) - jiffies; | |
1454 | if (delta > 0) | |
1455 | wait_ms = jiffies_to_msecs(delta); | |
1456 | ||
1457 | return wait_ms; | |
1458 | } | |
1459 | ||
39a53e0c JK |
1460 | /* |
1461 | * Inline functions | |
1462 | */ | |
416d2dbb | 1463 | static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc, |
704956ec CY |
1464 | const void *address, unsigned int length) |
1465 | { | |
1466 | struct { | |
1467 | struct shash_desc shash; | |
1468 | char ctx[4]; | |
1469 | } desc; | |
1470 | int err; | |
1471 | ||
1472 | BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); | |
1473 | ||
1474 | desc.shash.tfm = sbi->s_chksum_driver; | |
704956ec CY |
1475 | *(u32 *)desc.ctx = crc; |
1476 | ||
1477 | err = crypto_shash_update(&desc.shash, address, length); | |
1478 | BUG_ON(err); | |
1479 | ||
1480 | return *(u32 *)desc.ctx; | |
1481 | } | |
1482 | ||
416d2dbb CY |
1483 | static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, |
1484 | unsigned int length) | |
1485 | { | |
1486 | return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length); | |
1487 | } | |
1488 | ||
1489 | static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, | |
1490 | void *buf, size_t buf_size) | |
1491 | { | |
1492 | return f2fs_crc32(sbi, buf, buf_size) == blk_crc; | |
1493 | } | |
1494 | ||
1495 | static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, | |
1496 | const void *address, unsigned int length) | |
1497 | { | |
1498 | return __f2fs_crc32(sbi, crc, address, length); | |
1499 | } | |
1500 | ||
39a53e0c JK |
1501 | static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) |
1502 | { | |
1503 | return container_of(inode, struct f2fs_inode_info, vfs_inode); | |
1504 | } | |
1505 | ||
1506 | static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) | |
1507 | { | |
1508 | return sb->s_fs_info; | |
1509 | } | |
1510 | ||
4081363f JK |
1511 | static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) |
1512 | { | |
1513 | return F2FS_SB(inode->i_sb); | |
1514 | } | |
1515 | ||
1516 | static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) | |
1517 | { | |
1518 | return F2FS_I_SB(mapping->host); | |
1519 | } | |
1520 | ||
1521 | static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) | |
1522 | { | |
4969c06a | 1523 | return F2FS_M_SB(page_file_mapping(page)); |
4081363f JK |
1524 | } |
1525 | ||
39a53e0c JK |
1526 | static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) |
1527 | { | |
1528 | return (struct f2fs_super_block *)(sbi->raw_super); | |
1529 | } | |
1530 | ||
1531 | static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) | |
1532 | { | |
1533 | return (struct f2fs_checkpoint *)(sbi->ckpt); | |
1534 | } | |
1535 | ||
45590710 GZ |
1536 | static inline struct f2fs_node *F2FS_NODE(struct page *page) |
1537 | { | |
1538 | return (struct f2fs_node *)page_address(page); | |
1539 | } | |
1540 | ||
58bfaf44 JK |
1541 | static inline struct f2fs_inode *F2FS_INODE(struct page *page) |
1542 | { | |
1543 | return &((struct f2fs_node *)page_address(page))->i; | |
1544 | } | |
1545 | ||
39a53e0c JK |
1546 | static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) |
1547 | { | |
1548 | return (struct f2fs_nm_info *)(sbi->nm_info); | |
1549 | } | |
1550 | ||
1551 | static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) | |
1552 | { | |
1553 | return (struct f2fs_sm_info *)(sbi->sm_info); | |
1554 | } | |
1555 | ||
1556 | static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) | |
1557 | { | |
1558 | return (struct sit_info *)(SM_I(sbi)->sit_info); | |
1559 | } | |
1560 | ||
1561 | static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) | |
1562 | { | |
1563 | return (struct free_segmap_info *)(SM_I(sbi)->free_info); | |
1564 | } | |
1565 | ||
1566 | static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) | |
1567 | { | |
1568 | return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); | |
1569 | } | |
1570 | ||
9df27d98 GZ |
1571 | static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) |
1572 | { | |
1573 | return sbi->meta_inode->i_mapping; | |
1574 | } | |
1575 | ||
4ef51a8f JK |
1576 | static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) |
1577 | { | |
1578 | return sbi->node_inode->i_mapping; | |
1579 | } | |
1580 | ||
caf0047e CY |
1581 | static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) |
1582 | { | |
fadb2fb8 | 1583 | return test_bit(type, &sbi->s_flag); |
caf0047e CY |
1584 | } |
1585 | ||
1586 | static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) | |
39a53e0c | 1587 | { |
fadb2fb8 | 1588 | set_bit(type, &sbi->s_flag); |
39a53e0c JK |
1589 | } |
1590 | ||
caf0047e | 1591 | static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) |
39a53e0c | 1592 | { |
fadb2fb8 | 1593 | clear_bit(type, &sbi->s_flag); |
39a53e0c JK |
1594 | } |
1595 | ||
d71b5564 JK |
1596 | static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) |
1597 | { | |
1598 | return le64_to_cpu(cp->checkpoint_ver); | |
1599 | } | |
1600 | ||
ea676733 JK |
1601 | static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) |
1602 | { | |
1603 | if (type < F2FS_MAX_QUOTAS) | |
1604 | return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); | |
1605 | return 0; | |
1606 | } | |
1607 | ||
ced2c7ea KM |
1608 | static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) |
1609 | { | |
1610 | size_t crc_offset = le32_to_cpu(cp->checksum_offset); | |
1611 | return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); | |
1612 | } | |
1613 | ||
aaec2b1d | 1614 | static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) |
25ca923b JK |
1615 | { |
1616 | unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); | |
aaec2b1d | 1617 | |
25ca923b JK |
1618 | return ckpt_flags & f; |
1619 | } | |
1620 | ||
aaec2b1d | 1621 | static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) |
25ca923b | 1622 | { |
aaec2b1d CY |
1623 | return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); |
1624 | } | |
1625 | ||
1626 | static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) | |
1627 | { | |
1628 | unsigned int ckpt_flags; | |
1629 | ||
1630 | ckpt_flags = le32_to_cpu(cp->ckpt_flags); | |
25ca923b JK |
1631 | ckpt_flags |= f; |
1632 | cp->ckpt_flags = cpu_to_le32(ckpt_flags); | |
1633 | } | |
1634 | ||
aaec2b1d | 1635 | static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) |
25ca923b | 1636 | { |
d1aa2453 CY |
1637 | unsigned long flags; |
1638 | ||
1639 | spin_lock_irqsave(&sbi->cp_lock, flags); | |
aaec2b1d | 1640 | __set_ckpt_flags(F2FS_CKPT(sbi), f); |
d1aa2453 | 1641 | spin_unlock_irqrestore(&sbi->cp_lock, flags); |
aaec2b1d CY |
1642 | } |
1643 | ||
1644 | static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) | |
1645 | { | |
1646 | unsigned int ckpt_flags; | |
1647 | ||
1648 | ckpt_flags = le32_to_cpu(cp->ckpt_flags); | |
25ca923b JK |
1649 | ckpt_flags &= (~f); |
1650 | cp->ckpt_flags = cpu_to_le32(ckpt_flags); | |
1651 | } | |
1652 | ||
aaec2b1d CY |
1653 | static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) |
1654 | { | |
d1aa2453 CY |
1655 | unsigned long flags; |
1656 | ||
1657 | spin_lock_irqsave(&sbi->cp_lock, flags); | |
aaec2b1d | 1658 | __clear_ckpt_flags(F2FS_CKPT(sbi), f); |
d1aa2453 | 1659 | spin_unlock_irqrestore(&sbi->cp_lock, flags); |
aaec2b1d CY |
1660 | } |
1661 | ||
22ad0b6a JK |
1662 | static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) |
1663 | { | |
d1aa2453 | 1664 | unsigned long flags; |
0921835c | 1665 | unsigned char *nat_bits; |
d1aa2453 | 1666 | |
a742fd41 JK |
1667 | /* |
1668 | * In order to re-enable nat_bits we need to call fsck.f2fs by | |
1669 | * set_sbi_flag(sbi, SBI_NEED_FSCK). But it may give huge cost, | |
1670 | * so let's rely on regular fsck or unclean shutdown. | |
1671 | */ | |
22ad0b6a JK |
1672 | |
1673 | if (lock) | |
d1aa2453 | 1674 | spin_lock_irqsave(&sbi->cp_lock, flags); |
22ad0b6a | 1675 | __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); |
0921835c | 1676 | nat_bits = NM_I(sbi)->nat_bits; |
22ad0b6a JK |
1677 | NM_I(sbi)->nat_bits = NULL; |
1678 | if (lock) | |
d1aa2453 | 1679 | spin_unlock_irqrestore(&sbi->cp_lock, flags); |
0921835c CY |
1680 | |
1681 | kvfree(nat_bits); | |
22ad0b6a JK |
1682 | } |
1683 | ||
1684 | static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, | |
1685 | struct cp_control *cpc) | |
1686 | { | |
1687 | bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); | |
1688 | ||
c473f1a9 | 1689 | return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; |
22ad0b6a JK |
1690 | } |
1691 | ||
e479556b | 1692 | static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) |
39936837 | 1693 | { |
b873b798 | 1694 | down_read(&sbi->cp_rwsem); |
39936837 JK |
1695 | } |
1696 | ||
cc15620b JK |
1697 | static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) |
1698 | { | |
1699 | return down_read_trylock(&sbi->cp_rwsem); | |
1700 | } | |
1701 | ||
e479556b | 1702 | static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) |
39a53e0c | 1703 | { |
b873b798 | 1704 | up_read(&sbi->cp_rwsem); |
39a53e0c JK |
1705 | } |
1706 | ||
e479556b | 1707 | static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) |
39a53e0c | 1708 | { |
b873b798 | 1709 | down_write(&sbi->cp_rwsem); |
39936837 JK |
1710 | } |
1711 | ||
e479556b | 1712 | static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) |
39936837 | 1713 | { |
b873b798 | 1714 | up_write(&sbi->cp_rwsem); |
39a53e0c JK |
1715 | } |
1716 | ||
119ee914 JK |
1717 | static inline int __get_cp_reason(struct f2fs_sb_info *sbi) |
1718 | { | |
1719 | int reason = CP_SYNC; | |
1720 | ||
1721 | if (test_opt(sbi, FASTBOOT)) | |
1722 | reason = CP_FASTBOOT; | |
1723 | if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) | |
1724 | reason = CP_UMOUNT; | |
1725 | return reason; | |
1726 | } | |
1727 | ||
1728 | static inline bool __remain_node_summaries(int reason) | |
1729 | { | |
c473f1a9 | 1730 | return (reason & (CP_UMOUNT | CP_FASTBOOT)); |
119ee914 JK |
1731 | } |
1732 | ||
1733 | static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) | |
1734 | { | |
aaec2b1d CY |
1735 | return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || |
1736 | is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); | |
119ee914 JK |
1737 | } |
1738 | ||
39a53e0c JK |
1739 | /* |
1740 | * Check whether the inode has blocks or not | |
1741 | */ | |
1742 | static inline int F2FS_HAS_BLOCKS(struct inode *inode) | |
1743 | { | |
0eb0adad CY |
1744 | block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; |
1745 | ||
000519f2 | 1746 | return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; |
39a53e0c JK |
1747 | } |
1748 | ||
4bc8e9bc CY |
1749 | static inline bool f2fs_has_xattr_block(unsigned int ofs) |
1750 | { | |
1751 | return ofs == XATTR_NODE_OFFSET; | |
1752 | } | |
1753 | ||
d8a9a229 | 1754 | static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, |
a90a0884 | 1755 | struct inode *inode, bool cap) |
7c2e5963 | 1756 | { |
d8a9a229 JK |
1757 | if (!inode) |
1758 | return true; | |
7c2e5963 JK |
1759 | if (!test_opt(sbi, RESERVE_ROOT)) |
1760 | return false; | |
d8a9a229 JK |
1761 | if (IS_NOQUOTA(inode)) |
1762 | return true; | |
63189b78 | 1763 | if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid())) |
7c2e5963 | 1764 | return true; |
63189b78 CY |
1765 | if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) && |
1766 | in_group_p(F2FS_OPTION(sbi).s_resgid)) | |
7c2e5963 | 1767 | return true; |
a90a0884 | 1768 | if (cap && capable(CAP_SYS_RESOURCE)) |
162b27ae | 1769 | return true; |
7c2e5963 JK |
1770 | return false; |
1771 | } | |
1772 | ||
0abd675e CY |
1773 | static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); |
1774 | static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, | |
46008c6d | 1775 | struct inode *inode, blkcnt_t *count) |
39a53e0c | 1776 | { |
0abd675e | 1777 | blkcnt_t diff = 0, release = 0; |
daeb433e | 1778 | block_t avail_user_block_count; |
0abd675e CY |
1779 | int ret; |
1780 | ||
1781 | ret = dquot_reserve_block(inode, *count); | |
1782 | if (ret) | |
1783 | return ret; | |
39a53e0c | 1784 | |
55523519 | 1785 | if (time_to_inject(sbi, FAULT_BLOCK)) { |
93fb7d35 | 1786 | f2fs_show_injection_info(sbi, FAULT_BLOCK); |
0abd675e | 1787 | release = *count; |
9ea2f0be | 1788 | goto release_quota; |
55523519 | 1789 | } |
7fa750a1 | 1790 | |
dd11a5df JK |
1791 | /* |
1792 | * let's increase this in prior to actual block count change in order | |
1793 | * for f2fs_sync_file to avoid data races when deciding checkpoint. | |
1794 | */ | |
1795 | percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); | |
1796 | ||
2555a2d5 JK |
1797 | spin_lock(&sbi->stat_lock); |
1798 | sbi->total_valid_block_count += (block_t)(*count); | |
80d42145 YS |
1799 | avail_user_block_count = sbi->user_block_count - |
1800 | sbi->current_reserved_blocks; | |
7e65be49 | 1801 | |
a90a0884 | 1802 | if (!__allow_reserved_blocks(sbi, inode, true)) |
63189b78 | 1803 | avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; |
76fbc725 CY |
1804 | |
1805 | if (F2FS_IO_ALIGNED(sbi)) | |
1806 | avail_user_block_count -= sbi->blocks_per_seg * | |
1807 | SM_I(sbi)->additional_reserved_segments; | |
1808 | ||
a4c3ecaa DR |
1809 | if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { |
1810 | if (avail_user_block_count > sbi->unusable_block_count) | |
1811 | avail_user_block_count -= sbi->unusable_block_count; | |
1812 | else | |
1813 | avail_user_block_count = 0; | |
1814 | } | |
daeb433e CY |
1815 | if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { |
1816 | diff = sbi->total_valid_block_count - avail_user_block_count; | |
7e65be49 JK |
1817 | if (diff > *count) |
1818 | diff = *count; | |
dd11a5df | 1819 | *count -= diff; |
0abd675e | 1820 | release = diff; |
7e65be49 | 1821 | sbi->total_valid_block_count -= diff; |
46008c6d CY |
1822 | if (!*count) { |
1823 | spin_unlock(&sbi->stat_lock); | |
0abd675e | 1824 | goto enospc; |
46008c6d | 1825 | } |
39a53e0c | 1826 | } |
39a53e0c | 1827 | spin_unlock(&sbi->stat_lock); |
41382ec4 | 1828 | |
36b877af DR |
1829 | if (unlikely(release)) { |
1830 | percpu_counter_sub(&sbi->alloc_valid_block_count, release); | |
0abd675e | 1831 | dquot_release_reservation_block(inode, release); |
36b877af | 1832 | } |
0abd675e CY |
1833 | f2fs_i_blocks_write(inode, *count, true, true); |
1834 | return 0; | |
1835 | ||
1836 | enospc: | |
36b877af | 1837 | percpu_counter_sub(&sbi->alloc_valid_block_count, release); |
9ea2f0be | 1838 | release_quota: |
0abd675e CY |
1839 | dquot_release_reservation_block(inode, release); |
1840 | return -ENOSPC; | |
39a53e0c JK |
1841 | } |
1842 | ||
dcbb4c10 JP |
1843 | __printf(2, 3) |
1844 | void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...); | |
1845 | ||
1846 | #define f2fs_err(sbi, fmt, ...) \ | |
1847 | f2fs_printk(sbi, KERN_ERR fmt, ##__VA_ARGS__) | |
1848 | #define f2fs_warn(sbi, fmt, ...) \ | |
1849 | f2fs_printk(sbi, KERN_WARNING fmt, ##__VA_ARGS__) | |
1850 | #define f2fs_notice(sbi, fmt, ...) \ | |
1851 | f2fs_printk(sbi, KERN_NOTICE fmt, ##__VA_ARGS__) | |
1852 | #define f2fs_info(sbi, fmt, ...) \ | |
1853 | f2fs_printk(sbi, KERN_INFO fmt, ##__VA_ARGS__) | |
1854 | #define f2fs_debug(sbi, fmt, ...) \ | |
1855 | f2fs_printk(sbi, KERN_DEBUG fmt, ##__VA_ARGS__) | |
1856 | ||
da19b0dc | 1857 | static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, |
39a53e0c | 1858 | struct inode *inode, |
0eb0adad | 1859 | block_t count) |
39a53e0c | 1860 | { |
0eb0adad CY |
1861 | blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; |
1862 | ||
39a53e0c | 1863 | spin_lock(&sbi->stat_lock); |
9850cf4a | 1864 | f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); |
39a53e0c | 1865 | sbi->total_valid_block_count -= (block_t)count; |
80d42145 YS |
1866 | if (sbi->reserved_blocks && |
1867 | sbi->current_reserved_blocks < sbi->reserved_blocks) | |
1868 | sbi->current_reserved_blocks = min(sbi->reserved_blocks, | |
1869 | sbi->current_reserved_blocks + count); | |
39a53e0c | 1870 | spin_unlock(&sbi->stat_lock); |
5e159cd3 | 1871 | if (unlikely(inode->i_blocks < sectors)) { |
dcbb4c10 JP |
1872 | f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu", |
1873 | inode->i_ino, | |
1874 | (unsigned long long)inode->i_blocks, | |
1875 | (unsigned long long)sectors); | |
5e159cd3 CY |
1876 | set_sbi_flag(sbi, SBI_NEED_FSCK); |
1877 | return; | |
1878 | } | |
0abd675e | 1879 | f2fs_i_blocks_write(inode, count, false, true); |
39a53e0c JK |
1880 | } |
1881 | ||
1882 | static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) | |
1883 | { | |
35782b23 | 1884 | atomic_inc(&sbi->nr_pages[count_type]); |
7c4abcbe | 1885 | |
20109873 CY |
1886 | if (count_type == F2FS_DIRTY_DENTS || |
1887 | count_type == F2FS_DIRTY_NODES || | |
1888 | count_type == F2FS_DIRTY_META || | |
1889 | count_type == F2FS_DIRTY_QDATA || | |
1890 | count_type == F2FS_DIRTY_IMETA) | |
1891 | set_sbi_flag(sbi, SBI_IS_DIRTY); | |
39a53e0c JK |
1892 | } |
1893 | ||
a7ffdbe2 | 1894 | static inline void inode_inc_dirty_pages(struct inode *inode) |
39a53e0c | 1895 | { |
204706c7 | 1896 | atomic_inc(&F2FS_I(inode)->dirty_pages); |
c227f912 CY |
1897 | inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? |
1898 | F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); | |
2c8a4a28 JK |
1899 | if (IS_NOQUOTA(inode)) |
1900 | inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); | |
39a53e0c JK |
1901 | } |
1902 | ||
1903 | static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) | |
1904 | { | |
35782b23 | 1905 | atomic_dec(&sbi->nr_pages[count_type]); |
39a53e0c JK |
1906 | } |
1907 | ||
a7ffdbe2 | 1908 | static inline void inode_dec_dirty_pages(struct inode *inode) |
39a53e0c | 1909 | { |
5ac9f36f CY |
1910 | if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && |
1911 | !S_ISLNK(inode->i_mode)) | |
1fe54f9d JK |
1912 | return; |
1913 | ||
204706c7 | 1914 | atomic_dec(&F2FS_I(inode)->dirty_pages); |
c227f912 CY |
1915 | dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? |
1916 | F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); | |
2c8a4a28 JK |
1917 | if (IS_NOQUOTA(inode)) |
1918 | dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); | |
39a53e0c JK |
1919 | } |
1920 | ||
523be8a6 | 1921 | static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) |
39a53e0c | 1922 | { |
35782b23 | 1923 | return atomic_read(&sbi->nr_pages[count_type]); |
39a53e0c JK |
1924 | } |
1925 | ||
204706c7 | 1926 | static inline int get_dirty_pages(struct inode *inode) |
f8b2c1f9 | 1927 | { |
204706c7 | 1928 | return atomic_read(&F2FS_I(inode)->dirty_pages); |
f8b2c1f9 JK |
1929 | } |
1930 | ||
5ac206cf NJ |
1931 | static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) |
1932 | { | |
3519e3f9 | 1933 | unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; |
523be8a6 JK |
1934 | unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> |
1935 | sbi->log_blocks_per_seg; | |
1936 | ||
1937 | return segs / sbi->segs_per_sec; | |
5ac206cf NJ |
1938 | } |
1939 | ||
39a53e0c JK |
1940 | static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) |
1941 | { | |
8b8343fa | 1942 | return sbi->total_valid_block_count; |
39a53e0c JK |
1943 | } |
1944 | ||
f83a2584 YH |
1945 | static inline block_t discard_blocks(struct f2fs_sb_info *sbi) |
1946 | { | |
1947 | return sbi->discard_blks; | |
1948 | } | |
1949 | ||
39a53e0c JK |
1950 | static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) |
1951 | { | |
1952 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); | |
1953 | ||
1954 | /* return NAT or SIT bitmap */ | |
1955 | if (flag == NAT_BITMAP) | |
1956 | return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); | |
1957 | else if (flag == SIT_BITMAP) | |
1958 | return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); | |
1959 | ||
1960 | return 0; | |
1961 | } | |
1962 | ||
55141486 WL |
1963 | static inline block_t __cp_payload(struct f2fs_sb_info *sbi) |
1964 | { | |
1965 | return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); | |
1966 | } | |
1967 | ||
39a53e0c JK |
1968 | static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) |
1969 | { | |
1970 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); | |
1dbe4152 CL |
1971 | int offset; |
1972 | ||
199bc3fe CY |
1973 | if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { |
1974 | offset = (flag == SIT_BITMAP) ? | |
1975 | le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; | |
b471eb99 CY |
1976 | /* |
1977 | * if large_nat_bitmap feature is enabled, leave checksum | |
1978 | * protection for all nat/sit bitmaps. | |
1979 | */ | |
1980 | return &ckpt->sit_nat_version_bitmap + offset + sizeof(__le32); | |
199bc3fe CY |
1981 | } |
1982 | ||
55141486 | 1983 | if (__cp_payload(sbi) > 0) { |
1dbe4152 CL |
1984 | if (flag == NAT_BITMAP) |
1985 | return &ckpt->sit_nat_version_bitmap; | |
1986 | else | |
65b85ccc | 1987 | return (unsigned char *)ckpt + F2FS_BLKSIZE; |
1dbe4152 CL |
1988 | } else { |
1989 | offset = (flag == NAT_BITMAP) ? | |
25ca923b | 1990 | le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; |
1dbe4152 CL |
1991 | return &ckpt->sit_nat_version_bitmap + offset; |
1992 | } | |
39a53e0c JK |
1993 | } |
1994 | ||
1995 | static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) | |
1996 | { | |
8508e44a | 1997 | block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); |
39a53e0c | 1998 | |
8508e44a | 1999 | if (sbi->cur_cp_pack == 2) |
39a53e0c | 2000 | start_addr += sbi->blocks_per_seg; |
8508e44a JK |
2001 | return start_addr; |
2002 | } | |
39a53e0c | 2003 | |
8508e44a JK |
2004 | static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) |
2005 | { | |
2006 | block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); | |
39a53e0c | 2007 | |
8508e44a JK |
2008 | if (sbi->cur_cp_pack == 1) |
2009 | start_addr += sbi->blocks_per_seg; | |
39a53e0c JK |
2010 | return start_addr; |
2011 | } | |
2012 | ||
8508e44a JK |
2013 | static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) |
2014 | { | |
2015 | sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; | |
2016 | } | |
2017 | ||
39a53e0c JK |
2018 | static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) |
2019 | { | |
2020 | return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); | |
2021 | } | |
2022 | ||
0abd675e | 2023 | static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, |
000519f2 | 2024 | struct inode *inode, bool is_inode) |
39a53e0c JK |
2025 | { |
2026 | block_t valid_block_count; | |
a4c3ecaa | 2027 | unsigned int valid_node_count, user_block_count; |
af033b2a | 2028 | int err; |
0abd675e | 2029 | |
af033b2a CY |
2030 | if (is_inode) { |
2031 | if (inode) { | |
2032 | err = dquot_alloc_inode(inode); | |
2033 | if (err) | |
2034 | return err; | |
2035 | } | |
2036 | } else { | |
2037 | err = dquot_reserve_block(inode, 1); | |
2038 | if (err) | |
2039 | return err; | |
0abd675e | 2040 | } |
39a53e0c | 2041 | |
812c6056 | 2042 | if (time_to_inject(sbi, FAULT_BLOCK)) { |
93fb7d35 | 2043 | f2fs_show_injection_info(sbi, FAULT_BLOCK); |
812c6056 CY |
2044 | goto enospc; |
2045 | } | |
812c6056 | 2046 | |
39a53e0c JK |
2047 | spin_lock(&sbi->stat_lock); |
2048 | ||
7e65be49 JK |
2049 | valid_block_count = sbi->total_valid_block_count + |
2050 | sbi->current_reserved_blocks + 1; | |
2051 | ||
a90a0884 | 2052 | if (!__allow_reserved_blocks(sbi, inode, false)) |
63189b78 | 2053 | valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; |
76fbc725 CY |
2054 | |
2055 | if (F2FS_IO_ALIGNED(sbi)) | |
2056 | valid_block_count += sbi->blocks_per_seg * | |
2057 | SM_I(sbi)->additional_reserved_segments; | |
2058 | ||
a4c3ecaa | 2059 | user_block_count = sbi->user_block_count; |
4354994f | 2060 | if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) |
a4c3ecaa | 2061 | user_block_count -= sbi->unusable_block_count; |
7e65be49 | 2062 | |
a4c3ecaa | 2063 | if (unlikely(valid_block_count > user_block_count)) { |
39a53e0c | 2064 | spin_unlock(&sbi->stat_lock); |
0abd675e | 2065 | goto enospc; |
39a53e0c JK |
2066 | } |
2067 | ||
ef86d709 | 2068 | valid_node_count = sbi->total_valid_node_count + 1; |
cfb271d4 | 2069 | if (unlikely(valid_node_count > sbi->total_node_count)) { |
39a53e0c | 2070 | spin_unlock(&sbi->stat_lock); |
0abd675e | 2071 | goto enospc; |
39a53e0c JK |
2072 | } |
2073 | ||
ef86d709 GZ |
2074 | sbi->total_valid_node_count++; |
2075 | sbi->total_valid_block_count++; | |
39a53e0c JK |
2076 | spin_unlock(&sbi->stat_lock); |
2077 | ||
000519f2 CY |
2078 | if (inode) { |
2079 | if (is_inode) | |
2080 | f2fs_mark_inode_dirty_sync(inode, true); | |
2081 | else | |
0abd675e | 2082 | f2fs_i_blocks_write(inode, 1, true, true); |
000519f2 | 2083 | } |
ef86d709 | 2084 | |
41382ec4 | 2085 | percpu_counter_inc(&sbi->alloc_valid_block_count); |
0abd675e CY |
2086 | return 0; |
2087 | ||
2088 | enospc: | |
af033b2a CY |
2089 | if (is_inode) { |
2090 | if (inode) | |
2091 | dquot_free_inode(inode); | |
2092 | } else { | |
0abd675e | 2093 | dquot_release_reservation_block(inode, 1); |
af033b2a | 2094 | } |
0abd675e | 2095 | return -ENOSPC; |
39a53e0c JK |
2096 | } |
2097 | ||
2098 | static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, | |
000519f2 | 2099 | struct inode *inode, bool is_inode) |
39a53e0c JK |
2100 | { |
2101 | spin_lock(&sbi->stat_lock); | |
2102 | ||
9850cf4a JK |
2103 | f2fs_bug_on(sbi, !sbi->total_valid_block_count); |
2104 | f2fs_bug_on(sbi, !sbi->total_valid_node_count); | |
39a53e0c | 2105 | |
ef86d709 GZ |
2106 | sbi->total_valid_node_count--; |
2107 | sbi->total_valid_block_count--; | |
80d42145 YS |
2108 | if (sbi->reserved_blocks && |
2109 | sbi->current_reserved_blocks < sbi->reserved_blocks) | |
2110 | sbi->current_reserved_blocks++; | |
39a53e0c JK |
2111 | |
2112 | spin_unlock(&sbi->stat_lock); | |
0abd675e | 2113 | |
ea6d7e72 | 2114 | if (is_inode) { |
af033b2a | 2115 | dquot_free_inode(inode); |
ea6d7e72 CY |
2116 | } else { |
2117 | if (unlikely(inode->i_blocks == 0)) { | |
dcbb4c10 JP |
2118 | f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu", |
2119 | inode->i_ino, | |
2120 | (unsigned long long)inode->i_blocks); | |
ea6d7e72 CY |
2121 | set_sbi_flag(sbi, SBI_NEED_FSCK); |
2122 | return; | |
2123 | } | |
0abd675e | 2124 | f2fs_i_blocks_write(inode, 1, false, true); |
ea6d7e72 | 2125 | } |
39a53e0c JK |
2126 | } |
2127 | ||
2128 | static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) | |
2129 | { | |
8b8343fa | 2130 | return sbi->total_valid_node_count; |
39a53e0c JK |
2131 | } |
2132 | ||
2133 | static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) | |
2134 | { | |
513c5f37 | 2135 | percpu_counter_inc(&sbi->total_valid_inode_count); |
39a53e0c JK |
2136 | } |
2137 | ||
0e80220a | 2138 | static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) |
39a53e0c | 2139 | { |
513c5f37 | 2140 | percpu_counter_dec(&sbi->total_valid_inode_count); |
39a53e0c JK |
2141 | } |
2142 | ||
513c5f37 | 2143 | static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) |
39a53e0c | 2144 | { |
513c5f37 | 2145 | return percpu_counter_sum_positive(&sbi->total_valid_inode_count); |
39a53e0c JK |
2146 | } |
2147 | ||
a56c7c6f JK |
2148 | static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, |
2149 | pgoff_t index, bool for_write) | |
2150 | { | |
82cf4f13 | 2151 | struct page *page; |
cac5a3d8 | 2152 | |
7fa750a1 AB |
2153 | if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) { |
2154 | if (!for_write) | |
2155 | page = find_get_page_flags(mapping, index, | |
2156 | FGP_LOCK | FGP_ACCESSED); | |
2157 | else | |
2158 | page = find_lock_page(mapping, index); | |
2159 | if (page) | |
2160 | return page; | |
c41f3cc3 | 2161 | |
7fa750a1 | 2162 | if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { |
93fb7d35 CY |
2163 | f2fs_show_injection_info(F2FS_M_SB(mapping), |
2164 | FAULT_PAGE_ALLOC); | |
7fa750a1 AB |
2165 | return NULL; |
2166 | } | |
55523519 | 2167 | } |
7fa750a1 | 2168 | |
a56c7c6f JK |
2169 | if (!for_write) |
2170 | return grab_cache_page(mapping, index); | |
2171 | return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); | |
2172 | } | |
2173 | ||
01eccef7 CY |
2174 | static inline struct page *f2fs_pagecache_get_page( |
2175 | struct address_space *mapping, pgoff_t index, | |
2176 | int fgp_flags, gfp_t gfp_mask) | |
2177 | { | |
01eccef7 | 2178 | if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { |
93fb7d35 | 2179 | f2fs_show_injection_info(F2FS_M_SB(mapping), FAULT_PAGE_GET); |
01eccef7 CY |
2180 | return NULL; |
2181 | } | |
7fa750a1 | 2182 | |
01eccef7 CY |
2183 | return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); |
2184 | } | |
2185 | ||
6e2c64ad JK |
2186 | static inline void f2fs_copy_page(struct page *src, struct page *dst) |
2187 | { | |
2188 | char *src_kaddr = kmap(src); | |
2189 | char *dst_kaddr = kmap(dst); | |
2190 | ||
2191 | memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); | |
2192 | kunmap(dst); | |
2193 | kunmap(src); | |
2194 | } | |
2195 | ||
39a53e0c JK |
2196 | static inline void f2fs_put_page(struct page *page, int unlock) |
2197 | { | |
031fa8cc | 2198 | if (!page) |
39a53e0c JK |
2199 | return; |
2200 | ||
2201 | if (unlock) { | |
9850cf4a | 2202 | f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); |
39a53e0c JK |
2203 | unlock_page(page); |
2204 | } | |
09cbfeaf | 2205 | put_page(page); |
39a53e0c JK |
2206 | } |
2207 | ||
2208 | static inline void f2fs_put_dnode(struct dnode_of_data *dn) | |
2209 | { | |
2210 | if (dn->node_page) | |
2211 | f2fs_put_page(dn->node_page, 1); | |
2212 | if (dn->inode_page && dn->node_page != dn->inode_page) | |
2213 | f2fs_put_page(dn->inode_page, 0); | |
2214 | dn->node_page = NULL; | |
2215 | dn->inode_page = NULL; | |
2216 | } | |
2217 | ||
2218 | static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, | |
e8512d2e | 2219 | size_t size) |
39a53e0c | 2220 | { |
e8512d2e | 2221 | return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); |
39a53e0c JK |
2222 | } |
2223 | ||
7bd59381 GZ |
2224 | static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, |
2225 | gfp_t flags) | |
2226 | { | |
2227 | void *entry; | |
7bd59381 | 2228 | |
80c54505 JK |
2229 | entry = kmem_cache_alloc(cachep, flags); |
2230 | if (!entry) | |
2231 | entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); | |
7bd59381 GZ |
2232 | return entry; |
2233 | } | |
2234 | ||
d62fe971 CY |
2235 | static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, |
2236 | int npages, bool no_fail) | |
740432f8 JK |
2237 | { |
2238 | struct bio *bio; | |
2239 | ||
d62fe971 CY |
2240 | if (no_fail) { |
2241 | /* No failure on bio allocation */ | |
2242 | bio = bio_alloc(GFP_NOIO, npages); | |
2243 | if (!bio) | |
2244 | bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); | |
2245 | return bio; | |
2246 | } | |
d62fe971 | 2247 | if (time_to_inject(sbi, FAULT_ALLOC_BIO)) { |
93fb7d35 | 2248 | f2fs_show_injection_info(sbi, FAULT_ALLOC_BIO); |
d62fe971 CY |
2249 | return NULL; |
2250 | } | |
7fa750a1 | 2251 | |
d62fe971 | 2252 | return bio_alloc(GFP_KERNEL, npages); |
740432f8 JK |
2253 | } |
2254 | ||
5f9abab4 JK |
2255 | static inline bool is_idle(struct f2fs_sb_info *sbi, int type) |
2256 | { | |
f7dfd9f3 PJH |
2257 | if (sbi->gc_mode == GC_URGENT) |
2258 | return true; | |
2259 | ||
5f9abab4 JK |
2260 | if (get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_RD_NODE) || |
2261 | get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) || | |
fef4129e CY |
2262 | get_pages(sbi, F2FS_WB_CP_DATA) || |
2263 | get_pages(sbi, F2FS_DIO_READ) || | |
11ac8ef8 | 2264 | get_pages(sbi, F2FS_DIO_WRITE)) |
5f9abab4 | 2265 | return false; |
11ac8ef8 | 2266 | |
56659ce8 | 2267 | if (type != DISCARD_TIME && SM_I(sbi) && SM_I(sbi)->dcc_info && |
11ac8ef8 JK |
2268 | atomic_read(&SM_I(sbi)->dcc_info->queued_discard)) |
2269 | return false; | |
2270 | ||
2271 | if (SM_I(sbi) && SM_I(sbi)->fcc_info && | |
2272 | atomic_read(&SM_I(sbi)->fcc_info->queued_flush)) | |
2273 | return false; | |
2274 | ||
5f9abab4 JK |
2275 | return f2fs_time_over(sbi, type); |
2276 | } | |
2277 | ||
9be32d72 JK |
2278 | static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, |
2279 | unsigned long index, void *item) | |
2280 | { | |
2281 | while (radix_tree_insert(root, index, item)) | |
2282 | cond_resched(); | |
2283 | } | |
2284 | ||
39a53e0c JK |
2285 | #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) |
2286 | ||
2287 | static inline bool IS_INODE(struct page *page) | |
2288 | { | |
45590710 | 2289 | struct f2fs_node *p = F2FS_NODE(page); |
cac5a3d8 | 2290 | |
39a53e0c JK |
2291 | return RAW_IS_INODE(p); |
2292 | } | |
2293 | ||
7a2af766 CY |
2294 | static inline int offset_in_addr(struct f2fs_inode *i) |
2295 | { | |
2296 | return (i->i_inline & F2FS_EXTRA_ATTR) ? | |
2297 | (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; | |
2298 | } | |
2299 | ||
39a53e0c JK |
2300 | static inline __le32 *blkaddr_in_node(struct f2fs_node *node) |
2301 | { | |
2302 | return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; | |
2303 | } | |
2304 | ||
7a2af766 CY |
2305 | static inline int f2fs_has_extra_attr(struct inode *inode); |
2306 | static inline block_t datablock_addr(struct inode *inode, | |
2307 | struct page *node_page, unsigned int offset) | |
39a53e0c JK |
2308 | { |
2309 | struct f2fs_node *raw_node; | |
2310 | __le32 *addr_array; | |
7a2af766 CY |
2311 | int base = 0; |
2312 | bool is_inode = IS_INODE(node_page); | |
cac5a3d8 | 2313 | |
45590710 | 2314 | raw_node = F2FS_NODE(node_page); |
7a2af766 CY |
2315 | |
2316 | /* from GC path only */ | |
979f492f L |
2317 | if (is_inode) { |
2318 | if (!inode) | |
7a2af766 | 2319 | base = offset_in_addr(&raw_node->i); |
979f492f L |
2320 | else if (f2fs_has_extra_attr(inode)) |
2321 | base = get_extra_isize(inode); | |
7a2af766 CY |
2322 | } |
2323 | ||
39a53e0c | 2324 | addr_array = blkaddr_in_node(raw_node); |
7a2af766 | 2325 | return le32_to_cpu(addr_array[base + offset]); |
39a53e0c JK |
2326 | } |
2327 | ||
2328 | static inline int f2fs_test_bit(unsigned int nr, char *addr) | |
2329 | { | |
2330 | int mask; | |
2331 | ||
2332 | addr += (nr >> 3); | |
2333 | mask = 1 << (7 - (nr & 0x07)); | |
2334 | return mask & *addr; | |
2335 | } | |
2336 | ||
a66cdd98 JK |
2337 | static inline void f2fs_set_bit(unsigned int nr, char *addr) |
2338 | { | |
2339 | int mask; | |
2340 | ||
2341 | addr += (nr >> 3); | |
2342 | mask = 1 << (7 - (nr & 0x07)); | |
2343 | *addr |= mask; | |
2344 | } | |
2345 | ||
2346 | static inline void f2fs_clear_bit(unsigned int nr, char *addr) | |
2347 | { | |
2348 | int mask; | |
2349 | ||
2350 | addr += (nr >> 3); | |
2351 | mask = 1 << (7 - (nr & 0x07)); | |
2352 | *addr &= ~mask; | |
2353 | } | |
2354 | ||
52aca074 | 2355 | static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) |
39a53e0c JK |
2356 | { |
2357 | int mask; | |
2358 | int ret; | |
2359 | ||
2360 | addr += (nr >> 3); | |
2361 | mask = 1 << (7 - (nr & 0x07)); | |
2362 | ret = mask & *addr; | |
2363 | *addr |= mask; | |
2364 | return ret; | |
2365 | } | |
2366 | ||
52aca074 | 2367 | static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) |
39a53e0c JK |
2368 | { |
2369 | int mask; | |
2370 | int ret; | |
2371 | ||
2372 | addr += (nr >> 3); | |
2373 | mask = 1 << (7 - (nr & 0x07)); | |
2374 | ret = mask & *addr; | |
2375 | *addr &= ~mask; | |
2376 | return ret; | |
2377 | } | |
2378 | ||
c6ac4c0e GZ |
2379 | static inline void f2fs_change_bit(unsigned int nr, char *addr) |
2380 | { | |
2381 | int mask; | |
2382 | ||
2383 | addr += (nr >> 3); | |
2384 | mask = 1 << (7 - (nr & 0x07)); | |
2385 | *addr ^= mask; | |
2386 | } | |
2387 | ||
59c84408 | 2388 | /* |
36098557 | 2389 | * On-disk inode flags (f2fs_inode::i_flags) |
59c84408 | 2390 | */ |
59c84408 CY |
2391 | #define F2FS_SYNC_FL 0x00000008 /* Synchronous updates */ |
2392 | #define F2FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ | |
2393 | #define F2FS_APPEND_FL 0x00000020 /* writes to file may only append */ | |
2394 | #define F2FS_NODUMP_FL 0x00000040 /* do not dump file */ | |
2395 | #define F2FS_NOATIME_FL 0x00000080 /* do not update atime */ | |
59c84408 | 2396 | #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ |
59c84408 | 2397 | #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ |
59c84408 | 2398 | #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ |
2c2eb7a3 | 2399 | #define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */ |
59c84408 CY |
2400 | |
2401 | /* Flags that should be inherited by new inodes from their parent. */ | |
36098557 | 2402 | #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \ |
2c2eb7a3 DR |
2403 | F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ |
2404 | F2FS_CASEFOLD_FL) | |
59c84408 CY |
2405 | |
2406 | /* Flags that are appropriate for regular files (all but dir-specific ones). */ | |
2c2eb7a3 DR |
2407 | #define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ |
2408 | F2FS_CASEFOLD_FL)) | |
59c84408 CY |
2409 | |
2410 | /* Flags that are appropriate for non-directories/regular files. */ | |
2411 | #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL) | |
5c57132e CY |
2412 | |
2413 | static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) | |
2414 | { | |
2415 | if (S_ISDIR(mode)) | |
2416 | return flags; | |
2417 | else if (S_ISREG(mode)) | |
2418 | return flags & F2FS_REG_FLMASK; | |
2419 | else | |
2420 | return flags & F2FS_OTHER_FLMASK; | |
2421 | } | |
2422 | ||
39a53e0c JK |
2423 | /* used for f2fs_inode_info->flags */ |
2424 | enum { | |
2425 | FI_NEW_INODE, /* indicate newly allocated inode */ | |
b3783873 | 2426 | FI_DIRTY_INODE, /* indicate inode is dirty or not */ |
26de9b11 | 2427 | FI_AUTO_RECOVER, /* indicate inode is recoverable */ |
ed57c27f | 2428 | FI_DIRTY_DIR, /* indicate directory has dirty pages */ |
39a53e0c JK |
2429 | FI_INC_LINK, /* need to increment i_nlink */ |
2430 | FI_ACL_MODE, /* indicate acl mode */ | |
2431 | FI_NO_ALLOC, /* should not allocate any blocks */ | |
c9b63bd0 | 2432 | FI_FREE_NID, /* free allocated nide */ |
c11abd1a | 2433 | FI_NO_EXTENT, /* not to use the extent cache */ |
444c580f | 2434 | FI_INLINE_XATTR, /* used for inline xattr */ |
1001b347 | 2435 | FI_INLINE_DATA, /* used for inline data*/ |
34d67deb | 2436 | FI_INLINE_DENTRY, /* used for inline dentry */ |
fff04f90 JK |
2437 | FI_APPEND_WRITE, /* inode has appended data */ |
2438 | FI_UPDATE_WRITE, /* inode has in-place-update data */ | |
88b88a66 JK |
2439 | FI_NEED_IPU, /* used for ipu per file */ |
2440 | FI_ATOMIC_FILE, /* indicate atomic file */ | |
5fe45743 | 2441 | FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ |
02a1335f | 2442 | FI_VOLATILE_FILE, /* indicate volatile file */ |
3c6c2beb | 2443 | FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ |
1e84371f | 2444 | FI_DROP_CACHE, /* drop dirty page cache */ |
b3d208f9 | 2445 | FI_DATA_EXIST, /* indicate data exists */ |
510022a8 | 2446 | FI_INLINE_DOTS, /* indicate inline dot dentries */ |
d323d005 | 2447 | FI_DO_DEFRAG, /* indicate defragment is running */ |
c227f912 | 2448 | FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ |
dc91de78 | 2449 | FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ |
ef095d19 | 2450 | FI_HOT_DATA, /* indicate file is hot */ |
7a2af766 | 2451 | FI_EXTRA_ATTR, /* indicate file has extra attribute */ |
5c57132e | 2452 | FI_PROJ_INHERIT, /* indicate file inherits projectid */ |
1ad71a27 | 2453 | FI_PIN_FILE, /* indicate file should not be gced */ |
2ef79ecb | 2454 | FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */ |
95ae251f | 2455 | FI_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ |
39a53e0c JK |
2456 | }; |
2457 | ||
205b9822 JK |
2458 | static inline void __mark_inode_dirty_flag(struct inode *inode, |
2459 | int flag, bool set) | |
2460 | { | |
2461 | switch (flag) { | |
2462 | case FI_INLINE_XATTR: | |
2463 | case FI_INLINE_DATA: | |
2464 | case FI_INLINE_DENTRY: | |
9ac1e2d8 | 2465 | case FI_NEW_INODE: |
205b9822 JK |
2466 | if (set) |
2467 | return; | |
f5d5510e | 2468 | /* fall through */ |
205b9822 JK |
2469 | case FI_DATA_EXIST: |
2470 | case FI_INLINE_DOTS: | |
1ad71a27 | 2471 | case FI_PIN_FILE: |
7c45729a | 2472 | f2fs_mark_inode_dirty_sync(inode, true); |
205b9822 JK |
2473 | } |
2474 | } | |
2475 | ||
91942321 | 2476 | static inline void set_inode_flag(struct inode *inode, int flag) |
39a53e0c | 2477 | { |
91942321 JK |
2478 | if (!test_bit(flag, &F2FS_I(inode)->flags)) |
2479 | set_bit(flag, &F2FS_I(inode)->flags); | |
205b9822 | 2480 | __mark_inode_dirty_flag(inode, flag, true); |
39a53e0c JK |
2481 | } |
2482 | ||
91942321 | 2483 | static inline int is_inode_flag_set(struct inode *inode, int flag) |
39a53e0c | 2484 | { |
91942321 | 2485 | return test_bit(flag, &F2FS_I(inode)->flags); |
39a53e0c JK |
2486 | } |
2487 | ||
91942321 | 2488 | static inline void clear_inode_flag(struct inode *inode, int flag) |
39a53e0c | 2489 | { |
91942321 JK |
2490 | if (test_bit(flag, &F2FS_I(inode)->flags)) |
2491 | clear_bit(flag, &F2FS_I(inode)->flags); | |
205b9822 | 2492 | __mark_inode_dirty_flag(inode, flag, false); |
39a53e0c JK |
2493 | } |
2494 | ||
95ae251f EB |
2495 | static inline bool f2fs_verity_in_progress(struct inode *inode) |
2496 | { | |
2497 | return IS_ENABLED(CONFIG_FS_VERITY) && | |
2498 | is_inode_flag_set(inode, FI_VERITY_IN_PROGRESS); | |
2499 | } | |
2500 | ||
91942321 | 2501 | static inline void set_acl_inode(struct inode *inode, umode_t mode) |
39a53e0c | 2502 | { |
91942321 JK |
2503 | F2FS_I(inode)->i_acl_mode = mode; |
2504 | set_inode_flag(inode, FI_ACL_MODE); | |
7c45729a | 2505 | f2fs_mark_inode_dirty_sync(inode, false); |
39a53e0c JK |
2506 | } |
2507 | ||
a1961246 | 2508 | static inline void f2fs_i_links_write(struct inode *inode, bool inc) |
39a53e0c | 2509 | { |
a1961246 JK |
2510 | if (inc) |
2511 | inc_nlink(inode); | |
2512 | else | |
2513 | drop_nlink(inode); | |
7c45729a | 2514 | f2fs_mark_inode_dirty_sync(inode, true); |
a1961246 JK |
2515 | } |
2516 | ||
8edd03c8 | 2517 | static inline void f2fs_i_blocks_write(struct inode *inode, |
0abd675e | 2518 | block_t diff, bool add, bool claim) |
8edd03c8 | 2519 | { |
26de9b11 JK |
2520 | bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); |
2521 | bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); | |
2522 | ||
0abd675e CY |
2523 | /* add = 1, claim = 1 should be dquot_reserve_block in pair */ |
2524 | if (add) { | |
2525 | if (claim) | |
2526 | dquot_claim_block(inode, diff); | |
2527 | else | |
2528 | dquot_alloc_block_nofail(inode, diff); | |
2529 | } else { | |
2530 | dquot_free_block(inode, diff); | |
2531 | } | |
2532 | ||
7c45729a | 2533 | f2fs_mark_inode_dirty_sync(inode, true); |
26de9b11 JK |
2534 | if (clean || recover) |
2535 | set_inode_flag(inode, FI_AUTO_RECOVER); | |
8edd03c8 JK |
2536 | } |
2537 | ||
fc9581c8 JK |
2538 | static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) |
2539 | { | |
26de9b11 JK |
2540 | bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); |
2541 | bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); | |
2542 | ||
fc9581c8 JK |
2543 | if (i_size_read(inode) == i_size) |
2544 | return; | |
2545 | ||
2546 | i_size_write(inode, i_size); | |
7c45729a | 2547 | f2fs_mark_inode_dirty_sync(inode, true); |
26de9b11 JK |
2548 | if (clean || recover) |
2549 | set_inode_flag(inode, FI_AUTO_RECOVER); | |
39a53e0c JK |
2550 | } |
2551 | ||
205b9822 | 2552 | static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) |
39a53e0c | 2553 | { |
205b9822 | 2554 | F2FS_I(inode)->i_current_depth = depth; |
7c45729a | 2555 | f2fs_mark_inode_dirty_sync(inode, true); |
39a53e0c JK |
2556 | } |
2557 | ||
1ad71a27 JK |
2558 | static inline void f2fs_i_gc_failures_write(struct inode *inode, |
2559 | unsigned int count) | |
2560 | { | |
2ef79ecb | 2561 | F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count; |
1ad71a27 JK |
2562 | f2fs_mark_inode_dirty_sync(inode, true); |
2563 | } | |
2564 | ||
205b9822 | 2565 | static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) |
444c580f | 2566 | { |
205b9822 | 2567 | F2FS_I(inode)->i_xattr_nid = xnid; |
7c45729a | 2568 | f2fs_mark_inode_dirty_sync(inode, true); |
205b9822 JK |
2569 | } |
2570 | ||
2571 | static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) | |
2572 | { | |
2573 | F2FS_I(inode)->i_pino = pino; | |
7c45729a | 2574 | f2fs_mark_inode_dirty_sync(inode, true); |
205b9822 JK |
2575 | } |
2576 | ||
91942321 | 2577 | static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) |
444c580f | 2578 | { |
205b9822 JK |
2579 | struct f2fs_inode_info *fi = F2FS_I(inode); |
2580 | ||
444c580f | 2581 | if (ri->i_inline & F2FS_INLINE_XATTR) |
205b9822 | 2582 | set_bit(FI_INLINE_XATTR, &fi->flags); |
1001b347 | 2583 | if (ri->i_inline & F2FS_INLINE_DATA) |
205b9822 | 2584 | set_bit(FI_INLINE_DATA, &fi->flags); |
34d67deb | 2585 | if (ri->i_inline & F2FS_INLINE_DENTRY) |
205b9822 | 2586 | set_bit(FI_INLINE_DENTRY, &fi->flags); |
b3d208f9 | 2587 | if (ri->i_inline & F2FS_DATA_EXIST) |
205b9822 | 2588 | set_bit(FI_DATA_EXIST, &fi->flags); |
510022a8 | 2589 | if (ri->i_inline & F2FS_INLINE_DOTS) |
205b9822 | 2590 | set_bit(FI_INLINE_DOTS, &fi->flags); |
7a2af766 CY |
2591 | if (ri->i_inline & F2FS_EXTRA_ATTR) |
2592 | set_bit(FI_EXTRA_ATTR, &fi->flags); | |
1ad71a27 JK |
2593 | if (ri->i_inline & F2FS_PIN_FILE) |
2594 | set_bit(FI_PIN_FILE, &fi->flags); | |
444c580f JK |
2595 | } |
2596 | ||
91942321 | 2597 | static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) |
444c580f JK |
2598 | { |
2599 | ri->i_inline = 0; | |
2600 | ||
91942321 | 2601 | if (is_inode_flag_set(inode, FI_INLINE_XATTR)) |
444c580f | 2602 | ri->i_inline |= F2FS_INLINE_XATTR; |
91942321 | 2603 | if (is_inode_flag_set(inode, FI_INLINE_DATA)) |
1001b347 | 2604 | ri->i_inline |= F2FS_INLINE_DATA; |
91942321 | 2605 | if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) |
34d67deb | 2606 | ri->i_inline |= F2FS_INLINE_DENTRY; |
91942321 | 2607 | if (is_inode_flag_set(inode, FI_DATA_EXIST)) |
b3d208f9 | 2608 | ri->i_inline |= F2FS_DATA_EXIST; |
91942321 | 2609 | if (is_inode_flag_set(inode, FI_INLINE_DOTS)) |
510022a8 | 2610 | ri->i_inline |= F2FS_INLINE_DOTS; |
7a2af766 CY |
2611 | if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) |
2612 | ri->i_inline |= F2FS_EXTRA_ATTR; | |
1ad71a27 JK |
2613 | if (is_inode_flag_set(inode, FI_PIN_FILE)) |
2614 | ri->i_inline |= F2FS_PIN_FILE; | |
7a2af766 CY |
2615 | } |
2616 | ||
2617 | static inline int f2fs_has_extra_attr(struct inode *inode) | |
2618 | { | |
2619 | return is_inode_flag_set(inode, FI_EXTRA_ATTR); | |
444c580f JK |
2620 | } |
2621 | ||
987c7c31 CY |
2622 | static inline int f2fs_has_inline_xattr(struct inode *inode) |
2623 | { | |
91942321 | 2624 | return is_inode_flag_set(inode, FI_INLINE_XATTR); |
987c7c31 CY |
2625 | } |
2626 | ||
81ca7350 | 2627 | static inline unsigned int addrs_per_inode(struct inode *inode) |
de93653f | 2628 | { |
d02a6e61 CY |
2629 | unsigned int addrs = CUR_ADDRS_PER_INODE(inode) - |
2630 | get_inline_xattr_addrs(inode); | |
2631 | return ALIGN_DOWN(addrs, 1); | |
2632 | } | |
2633 | ||
2634 | static inline unsigned int addrs_per_block(struct inode *inode) | |
2635 | { | |
2636 | return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, 1); | |
de93653f JK |
2637 | } |
2638 | ||
6afc662e | 2639 | static inline void *inline_xattr_addr(struct inode *inode, struct page *page) |
65985d93 | 2640 | { |
695fd1ed | 2641 | struct f2fs_inode *ri = F2FS_INODE(page); |
cac5a3d8 | 2642 | |
65985d93 | 2643 | return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - |
b323fd28 | 2644 | get_inline_xattr_addrs(inode)]); |
65985d93 JK |
2645 | } |
2646 | ||
2647 | static inline int inline_xattr_size(struct inode *inode) | |
2648 | { | |
622927f3 CY |
2649 | if (f2fs_has_inline_xattr(inode)) |
2650 | return get_inline_xattr_addrs(inode) * sizeof(__le32); | |
2651 | return 0; | |
65985d93 JK |
2652 | } |
2653 | ||
0dbdc2ae JK |
2654 | static inline int f2fs_has_inline_data(struct inode *inode) |
2655 | { | |
91942321 | 2656 | return is_inode_flag_set(inode, FI_INLINE_DATA); |
0dbdc2ae JK |
2657 | } |
2658 | ||
b3d208f9 JK |
2659 | static inline int f2fs_exist_data(struct inode *inode) |
2660 | { | |
91942321 | 2661 | return is_inode_flag_set(inode, FI_DATA_EXIST); |
b3d208f9 JK |
2662 | } |
2663 | ||
510022a8 JK |
2664 | static inline int f2fs_has_inline_dots(struct inode *inode) |
2665 | { | |
91942321 | 2666 | return is_inode_flag_set(inode, FI_INLINE_DOTS); |
510022a8 JK |
2667 | } |
2668 | ||
1ad71a27 JK |
2669 | static inline bool f2fs_is_pinned_file(struct inode *inode) |
2670 | { | |
2671 | return is_inode_flag_set(inode, FI_PIN_FILE); | |
2672 | } | |
2673 | ||
88b88a66 JK |
2674 | static inline bool f2fs_is_atomic_file(struct inode *inode) |
2675 | { | |
91942321 | 2676 | return is_inode_flag_set(inode, FI_ATOMIC_FILE); |
88b88a66 JK |
2677 | } |
2678 | ||
5fe45743 CY |
2679 | static inline bool f2fs_is_commit_atomic_write(struct inode *inode) |
2680 | { | |
2681 | return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); | |
2682 | } | |
2683 | ||
02a1335f JK |
2684 | static inline bool f2fs_is_volatile_file(struct inode *inode) |
2685 | { | |
91942321 | 2686 | return is_inode_flag_set(inode, FI_VOLATILE_FILE); |
02a1335f JK |
2687 | } |
2688 | ||
3c6c2beb JK |
2689 | static inline bool f2fs_is_first_block_written(struct inode *inode) |
2690 | { | |
91942321 | 2691 | return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); |
3c6c2beb JK |
2692 | } |
2693 | ||
1e84371f JK |
2694 | static inline bool f2fs_is_drop_cache(struct inode *inode) |
2695 | { | |
91942321 | 2696 | return is_inode_flag_set(inode, FI_DROP_CACHE); |
1e84371f JK |
2697 | } |
2698 | ||
f2470371 | 2699 | static inline void *inline_data_addr(struct inode *inode, struct page *page) |
1001b347 | 2700 | { |
695fd1ed | 2701 | struct f2fs_inode *ri = F2FS_INODE(page); |
7a2af766 | 2702 | int extra_size = get_extra_isize(inode); |
cac5a3d8 | 2703 | |
7a2af766 | 2704 | return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); |
1001b347 HL |
2705 | } |
2706 | ||
34d67deb CY |
2707 | static inline int f2fs_has_inline_dentry(struct inode *inode) |
2708 | { | |
91942321 | 2709 | return is_inode_flag_set(inode, FI_INLINE_DENTRY); |
34d67deb CY |
2710 | } |
2711 | ||
b5492af7 JK |
2712 | static inline int is_file(struct inode *inode, int type) |
2713 | { | |
2714 | return F2FS_I(inode)->i_advise & type; | |
2715 | } | |
2716 | ||
2717 | static inline void set_file(struct inode *inode, int type) | |
2718 | { | |
2719 | F2FS_I(inode)->i_advise |= type; | |
7c45729a | 2720 | f2fs_mark_inode_dirty_sync(inode, true); |
b5492af7 JK |
2721 | } |
2722 | ||
2723 | static inline void clear_file(struct inode *inode, int type) | |
2724 | { | |
2725 | F2FS_I(inode)->i_advise &= ~type; | |
7c45729a | 2726 | f2fs_mark_inode_dirty_sync(inode, true); |
b5492af7 JK |
2727 | } |
2728 | ||
f13395f3 CY |
2729 | static inline bool f2fs_is_time_consistent(struct inode *inode) |
2730 | { | |
2731 | if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime)) | |
2732 | return false; | |
2733 | if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime)) | |
2734 | return false; | |
2735 | if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime)) | |
2736 | return false; | |
2737 | if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3, | |
2738 | &F2FS_I(inode)->i_crtime)) | |
2739 | return false; | |
2740 | return true; | |
2741 | } | |
2742 | ||
26787236 JK |
2743 | static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) |
2744 | { | |
a0d00fad CY |
2745 | bool ret; |
2746 | ||
26787236 JK |
2747 | if (dsync) { |
2748 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | |
26787236 JK |
2749 | |
2750 | spin_lock(&sbi->inode_lock[DIRTY_META]); | |
2751 | ret = list_empty(&F2FS_I(inode)->gdirty_list); | |
2752 | spin_unlock(&sbi->inode_lock[DIRTY_META]); | |
2753 | return ret; | |
2754 | } | |
2755 | if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || | |
2756 | file_keep_isize(inode) || | |
235831d7 | 2757 | i_size_read(inode) & ~PAGE_MASK) |
26787236 | 2758 | return false; |
a0d00fad | 2759 | |
f13395f3 | 2760 | if (!f2fs_is_time_consistent(inode)) |
214c2461 JK |
2761 | return false; |
2762 | ||
a0d00fad CY |
2763 | down_read(&F2FS_I(inode)->i_sem); |
2764 | ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); | |
2765 | up_read(&F2FS_I(inode)->i_sem); | |
2766 | ||
2767 | return ret; | |
b5492af7 JK |
2768 | } |
2769 | ||
deeedd71 | 2770 | static inline bool f2fs_readonly(struct super_block *sb) |
77888c1e | 2771 | { |
deeedd71 | 2772 | return sb_rdonly(sb); |
77888c1e JK |
2773 | } |
2774 | ||
1e968fdf JK |
2775 | static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) |
2776 | { | |
aaec2b1d | 2777 | return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); |
1e968fdf JK |
2778 | } |
2779 | ||
eaa693f4 JK |
2780 | static inline bool is_dot_dotdot(const struct qstr *str) |
2781 | { | |
2782 | if (str->len == 1 && str->name[0] == '.') | |
2783 | return true; | |
2784 | ||
2785 | if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') | |
2786 | return true; | |
2787 | ||
2788 | return false; | |
2789 | } | |
2790 | ||
3e72f721 JK |
2791 | static inline bool f2fs_may_extent_tree(struct inode *inode) |
2792 | { | |
e4589fa5 ST |
2793 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
2794 | ||
2795 | if (!test_opt(sbi, EXTENT_CACHE) || | |
91942321 | 2796 | is_inode_flag_set(inode, FI_NO_EXTENT)) |
3e72f721 JK |
2797 | return false; |
2798 | ||
e4589fa5 ST |
2799 | /* |
2800 | * for recovered files during mount do not create extents | |
2801 | * if shrinker is not registered. | |
2802 | */ | |
2803 | if (list_empty(&sbi->s_list)) | |
2804 | return false; | |
2805 | ||
886f56f9 | 2806 | return S_ISREG(inode->i_mode); |
3e72f721 JK |
2807 | } |
2808 | ||
1ecc0c5c CY |
2809 | static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, |
2810 | size_t size, gfp_t flags) | |
0414b004 | 2811 | { |
55523519 | 2812 | if (time_to_inject(sbi, FAULT_KMALLOC)) { |
93fb7d35 | 2813 | f2fs_show_injection_info(sbi, FAULT_KMALLOC); |
2c63fead | 2814 | return NULL; |
55523519 | 2815 | } |
7fa750a1 | 2816 | |
0f355949 | 2817 | return kmalloc(size, flags); |
0414b004 JK |
2818 | } |
2819 | ||
acbf054d CY |
2820 | static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, |
2821 | size_t size, gfp_t flags) | |
2822 | { | |
2823 | return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); | |
2824 | } | |
2825 | ||
628b3d14 CY |
2826 | static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, |
2827 | size_t size, gfp_t flags) | |
2828 | { | |
628b3d14 | 2829 | if (time_to_inject(sbi, FAULT_KVMALLOC)) { |
93fb7d35 | 2830 | f2fs_show_injection_info(sbi, FAULT_KVMALLOC); |
628b3d14 CY |
2831 | return NULL; |
2832 | } | |
7fa750a1 | 2833 | |
628b3d14 CY |
2834 | return kvmalloc(size, flags); |
2835 | } | |
2836 | ||
2837 | static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi, | |
2838 | size_t size, gfp_t flags) | |
2839 | { | |
2840 | return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO); | |
2841 | } | |
2842 | ||
7a2af766 | 2843 | static inline int get_extra_isize(struct inode *inode) |
f2470371 | 2844 | { |
7a2af766 | 2845 | return F2FS_I(inode)->i_extra_isize / sizeof(__le32); |
f2470371 CY |
2846 | } |
2847 | ||
6afc662e CY |
2848 | static inline int get_inline_xattr_addrs(struct inode *inode) |
2849 | { | |
2850 | return F2FS_I(inode)->i_inline_xattr_size; | |
2851 | } | |
2852 | ||
4d57b86d | 2853 | #define f2fs_get_inode_mode(i) \ |
91942321 | 2854 | ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ |
a6dda0e6 CH |
2855 | (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) |
2856 | ||
7a2af766 CY |
2857 | #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ |
2858 | (offsetof(struct f2fs_inode, i_extra_end) - \ | |
2859 | offsetof(struct f2fs_inode, i_extra_isize)) \ | |
2860 | ||
5c57132e CY |
2861 | #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) |
2862 | #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ | |
2f84babf | 2863 | ((offsetof(typeof(*(f2fs_inode)), field) + \ |
5c57132e | 2864 | sizeof((f2fs_inode)->field)) \ |
2f84babf | 2865 | <= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize))) \ |
5c57132e | 2866 | |
b0af6d49 CY |
2867 | static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) |
2868 | { | |
2869 | int i; | |
2870 | ||
2871 | spin_lock(&sbi->iostat_lock); | |
2872 | for (i = 0; i < NR_IO_TYPE; i++) | |
2873 | sbi->write_iostat[i] = 0; | |
2874 | spin_unlock(&sbi->iostat_lock); | |
2875 | } | |
2876 | ||
2877 | static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, | |
2878 | enum iostat_type type, unsigned long long io_bytes) | |
2879 | { | |
2880 | if (!sbi->iostat_enable) | |
2881 | return; | |
2882 | spin_lock(&sbi->iostat_lock); | |
2883 | sbi->write_iostat[type] += io_bytes; | |
2884 | ||
2885 | if (type == APP_WRITE_IO || type == APP_DIRECT_IO) | |
2886 | sbi->write_iostat[APP_BUFFERED_IO] = | |
2887 | sbi->write_iostat[APP_WRITE_IO] - | |
2888 | sbi->write_iostat[APP_DIRECT_IO]; | |
2889 | spin_unlock(&sbi->iostat_lock); | |
2890 | } | |
2891 | ||
2c70c5e3 CY |
2892 | #define __is_large_section(sbi) ((sbi)->segs_per_sec > 1) |
2893 | ||
6dc3a126 | 2894 | #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META) |
c9b60788 | 2895 | |
e1da7872 CY |
2896 | bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, |
2897 | block_t blkaddr, int type); | |
e1da7872 CY |
2898 | static inline void verify_blkaddr(struct f2fs_sb_info *sbi, |
2899 | block_t blkaddr, int type) | |
2900 | { | |
2901 | if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) { | |
dcbb4c10 JP |
2902 | f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.", |
2903 | blkaddr, type); | |
e1da7872 CY |
2904 | f2fs_bug_on(sbi, 1); |
2905 | } | |
2906 | } | |
2907 | ||
2908 | static inline bool __is_valid_data_blkaddr(block_t blkaddr) | |
7b525dd0 CY |
2909 | { |
2910 | if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) | |
2911 | return false; | |
2912 | return true; | |
2913 | } | |
2914 | ||
240a5915 CY |
2915 | static inline void f2fs_set_page_private(struct page *page, |
2916 | unsigned long data) | |
2917 | { | |
2918 | if (PagePrivate(page)) | |
2919 | return; | |
2920 | ||
2921 | get_page(page); | |
2922 | SetPagePrivate(page); | |
2923 | set_page_private(page, data); | |
2924 | } | |
2925 | ||
2926 | static inline void f2fs_clear_page_private(struct page *page) | |
2927 | { | |
2928 | if (!PagePrivate(page)) | |
2929 | return; | |
2930 | ||
2931 | set_page_private(page, 0); | |
2932 | ClearPagePrivate(page); | |
2933 | f2fs_put_page(page, 0); | |
2934 | } | |
2935 | ||
39a53e0c JK |
2936 | /* |
2937 | * file.c | |
2938 | */ | |
cac5a3d8 | 2939 | int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); |
4d57b86d | 2940 | void f2fs_truncate_data_blocks(struct dnode_of_data *dn); |
c42d28ce | 2941 | int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock); |
cac5a3d8 | 2942 | int f2fs_truncate(struct inode *inode); |
a528d35e DH |
2943 | int f2fs_getattr(const struct path *path, struct kstat *stat, |
2944 | u32 request_mask, unsigned int flags); | |
cac5a3d8 | 2945 | int f2fs_setattr(struct dentry *dentry, struct iattr *attr); |
4d57b86d CY |
2946 | int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); |
2947 | void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); | |
c4020b2d | 2948 | int f2fs_precache_extents(struct inode *inode); |
cac5a3d8 DS |
2949 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); |
2950 | long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | |
78130819 | 2951 | int f2fs_transfer_project_quota(struct inode *inode, kprojid_t kprojid); |
1ad71a27 | 2952 | int f2fs_pin_file_control(struct inode *inode, bool inc); |
39a53e0c JK |
2953 | |
2954 | /* | |
2955 | * inode.c | |
2956 | */ | |
cac5a3d8 | 2957 | void f2fs_set_inode_flags(struct inode *inode); |
704956ec CY |
2958 | bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); |
2959 | void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); | |
cac5a3d8 DS |
2960 | struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); |
2961 | struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); | |
4d57b86d CY |
2962 | int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); |
2963 | void f2fs_update_inode(struct inode *inode, struct page *node_page); | |
2964 | void f2fs_update_inode_page(struct inode *inode); | |
cac5a3d8 DS |
2965 | int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); |
2966 | void f2fs_evict_inode(struct inode *inode); | |
4d57b86d | 2967 | void f2fs_handle_failed_inode(struct inode *inode); |
39a53e0c JK |
2968 | |
2969 | /* | |
2970 | * namei.c | |
2971 | */ | |
4d57b86d | 2972 | int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, |
b6a06cbb | 2973 | bool hot, bool set); |
39a53e0c JK |
2974 | struct dentry *f2fs_get_parent(struct dentry *child); |
2975 | ||
2976 | /* | |
2977 | * dir.c | |
2978 | */ | |
4d57b86d CY |
2979 | unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de); |
2980 | struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, | |
cac5a3d8 DS |
2981 | f2fs_hash_t namehash, int *max_slots, |
2982 | struct f2fs_dentry_ptr *d); | |
2983 | int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, | |
2984 | unsigned int start_pos, struct fscrypt_str *fstr); | |
4d57b86d | 2985 | void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent, |
cac5a3d8 | 2986 | struct f2fs_dentry_ptr *d); |
4d57b86d | 2987 | struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir, |
cac5a3d8 DS |
2988 | const struct qstr *new_name, |
2989 | const struct qstr *orig_name, struct page *dpage); | |
4d57b86d | 2990 | void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode, |
cac5a3d8 | 2991 | unsigned int current_depth); |
4d57b86d | 2992 | int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots); |
cac5a3d8 DS |
2993 | void f2fs_drop_nlink(struct inode *dir, struct inode *inode); |
2994 | struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, | |
2995 | struct fscrypt_name *fname, struct page **res_page); | |
2996 | struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, | |
2997 | const struct qstr *child, struct page **res_page); | |
2998 | struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); | |
2999 | ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, | |
3000 | struct page **page); | |
3001 | void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, | |
3002 | struct page *page, struct inode *inode); | |
cac5a3d8 DS |
3003 | void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, |
3004 | const struct qstr *name, f2fs_hash_t name_hash, | |
3005 | unsigned int bit_pos); | |
3006 | int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, | |
3007 | const struct qstr *orig_name, | |
3008 | struct inode *inode, nid_t ino, umode_t mode); | |
4d57b86d | 3009 | int f2fs_add_dentry(struct inode *dir, struct fscrypt_name *fname, |
cac5a3d8 | 3010 | struct inode *inode, nid_t ino, umode_t mode); |
4d57b86d | 3011 | int f2fs_do_add_link(struct inode *dir, const struct qstr *name, |
cac5a3d8 DS |
3012 | struct inode *inode, nid_t ino, umode_t mode); |
3013 | void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, | |
3014 | struct inode *dir, struct inode *inode); | |
3015 | int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); | |
3016 | bool f2fs_empty_dir(struct inode *dir); | |
39a53e0c | 3017 | |
b7f7a5e0 AV |
3018 | static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) |
3019 | { | |
383dbfbd EB |
3020 | if (fscrypt_is_nokey_name(dentry)) |
3021 | return -ENOKEY; | |
4d57b86d | 3022 | return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name, |
510022a8 | 3023 | inode, inode->i_ino, inode->i_mode); |
b7f7a5e0 AV |
3024 | } |
3025 | ||
39a53e0c JK |
3026 | /* |
3027 | * super.c | |
3028 | */ | |
cac5a3d8 DS |
3029 | int f2fs_inode_dirtied(struct inode *inode, bool sync); |
3030 | void f2fs_inode_synced(struct inode *inode); | |
ea676733 | 3031 | int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); |
af033b2a | 3032 | int f2fs_quota_sync(struct super_block *sb, int type); |
4b2414d0 | 3033 | void f2fs_quota_off_umount(struct super_block *sb); |
cac5a3d8 DS |
3034 | int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); |
3035 | int f2fs_sync_fs(struct super_block *sb, int sync); | |
4d57b86d | 3036 | int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); |
39a53e0c JK |
3037 | |
3038 | /* | |
3039 | * hash.c | |
3040 | */ | |
2c2eb7a3 DR |
3041 | f2fs_hash_t f2fs_dentry_hash(const struct inode *dir, |
3042 | const struct qstr *name_info, struct fscrypt_name *fname); | |
39a53e0c JK |
3043 | |
3044 | /* | |
3045 | * node.c | |
3046 | */ | |
3047 | struct dnode_of_data; | |
3048 | struct node_info; | |
3049 | ||
4d57b86d CY |
3050 | int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid); |
3051 | bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type); | |
50fa53ec CY |
3052 | bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page); |
3053 | void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi); | |
3054 | void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page); | |
3055 | void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi); | |
4d57b86d CY |
3056 | int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); |
3057 | bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); | |
3058 | bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); | |
7735730d | 3059 | int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, |
4d57b86d CY |
3060 | struct node_info *ni); |
3061 | pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); | |
3062 | int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); | |
3063 | int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from); | |
3064 | int f2fs_truncate_xattr_node(struct inode *inode); | |
50fa53ec CY |
3065 | int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, |
3066 | unsigned int seq_id); | |
4d57b86d CY |
3067 | int f2fs_remove_inode_page(struct inode *inode); |
3068 | struct page *f2fs_new_inode_page(struct inode *inode); | |
3069 | struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs); | |
3070 | void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); | |
3071 | struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); | |
3072 | struct page *f2fs_get_node_page_ra(struct page *parent, int start); | |
48018b4c | 3073 | int f2fs_move_node_page(struct page *node_page, int gc_type); |
4d57b86d | 3074 | int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, |
50fa53ec CY |
3075 | struct writeback_control *wbc, bool atomic, |
3076 | unsigned int *seq_id); | |
4d57b86d CY |
3077 | int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, |
3078 | struct writeback_control *wbc, | |
b0af6d49 | 3079 | bool do_balance, enum iostat_type io_type); |
e2374015 | 3080 | int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); |
4d57b86d CY |
3081 | bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); |
3082 | void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); | |
3083 | void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); | |
3084 | int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); | |
bd446469 | 3085 | int f2fs_recover_inline_xattr(struct inode *inode, struct page *page); |
4d57b86d CY |
3086 | int f2fs_recover_xattr_data(struct inode *inode, struct page *page); |
3087 | int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); | |
7735730d | 3088 | int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, |
cac5a3d8 | 3089 | unsigned int segno, struct f2fs_summary_block *sum); |
edc55aaf | 3090 | int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); |
4d57b86d CY |
3091 | int f2fs_build_node_manager(struct f2fs_sb_info *sbi); |
3092 | void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi); | |
3093 | int __init f2fs_create_node_manager_caches(void); | |
3094 | void f2fs_destroy_node_manager_caches(void); | |
39a53e0c JK |
3095 | |
3096 | /* | |
3097 | * segment.c | |
3098 | */ | |
4d57b86d CY |
3099 | bool f2fs_need_SSR(struct f2fs_sb_info *sbi); |
3100 | void f2fs_register_inmem_page(struct inode *inode, struct page *page); | |
3101 | void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure); | |
3102 | void f2fs_drop_inmem_pages(struct inode *inode); | |
3103 | void f2fs_drop_inmem_page(struct inode *inode, struct page *page); | |
3104 | int f2fs_commit_inmem_pages(struct inode *inode); | |
cac5a3d8 DS |
3105 | void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); |
3106 | void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); | |
39d787be | 3107 | int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); |
4d57b86d | 3108 | int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi); |
1228b482 | 3109 | int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); |
4d57b86d CY |
3110 | void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); |
3111 | void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); | |
3112 | bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); | |
3113 | void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi); | |
3114 | void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi); | |
03f2c02d | 3115 | bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi); |
4d57b86d CY |
3116 | void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, |
3117 | struct cp_control *cpc); | |
4354994f | 3118 | void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi); |
4d3aed70 DR |
3119 | block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi); |
3120 | int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable); | |
4d57b86d CY |
3121 | void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi); |
3122 | int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); | |
04f0b2ea QS |
3123 | void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, |
3124 | unsigned int start, unsigned int end); | |
4d57b86d | 3125 | void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi); |
cac5a3d8 | 3126 | int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); |
4d57b86d CY |
3127 | bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, |
3128 | struct cp_control *cpc); | |
3129 | struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); | |
3130 | void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src, | |
3131 | block_t blk_addr); | |
3132 | void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page, | |
b0af6d49 | 3133 | enum iostat_type io_type); |
4d57b86d CY |
3134 | void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio); |
3135 | void f2fs_outplace_write_data(struct dnode_of_data *dn, | |
3136 | struct f2fs_io_info *fio); | |
3137 | int f2fs_inplace_write_data(struct f2fs_io_info *fio); | |
3138 | void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, | |
cac5a3d8 DS |
3139 | block_t old_blkaddr, block_t new_blkaddr, |
3140 | bool recover_curseg, bool recover_newaddr); | |
3141 | void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, | |
3142 | block_t old_addr, block_t new_addr, | |
3143 | unsigned char version, bool recover_curseg, | |
3144 | bool recover_newaddr); | |
4d57b86d | 3145 | void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, |
cac5a3d8 | 3146 | block_t old_blkaddr, block_t *new_blkaddr, |
fb830fc5 CY |
3147 | struct f2fs_summary *sum, int type, |
3148 | struct f2fs_io_info *fio, bool add_list); | |
cac5a3d8 | 3149 | void f2fs_wait_on_page_writeback(struct page *page, |
bae0ee7a | 3150 | enum page_type type, bool ordered, bool locked); |
0ded69f6 | 3151 | void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr); |
1e78e8bd ST |
3152 | void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr, |
3153 | block_t len); | |
4d57b86d CY |
3154 | void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); |
3155 | void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); | |
3156 | int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type, | |
cac5a3d8 | 3157 | unsigned int val, int alloc); |
4d57b86d CY |
3158 | void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); |
3159 | int f2fs_build_segment_manager(struct f2fs_sb_info *sbi); | |
3160 | void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi); | |
3161 | int __init f2fs_create_segment_manager_caches(void); | |
3162 | void f2fs_destroy_segment_manager_caches(void); | |
3163 | int f2fs_rw_hint_to_seg_type(enum rw_hint hint); | |
3164 | enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, | |
3165 | enum page_type type, enum temp_type temp); | |
39a53e0c JK |
3166 | |
3167 | /* | |
3168 | * checkpoint.c | |
3169 | */ | |
cac5a3d8 | 3170 | void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); |
4d57b86d CY |
3171 | struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); |
3172 | struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); | |
1247d9fa | 3173 | struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index); |
4d57b86d | 3174 | struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); |
e1da7872 CY |
3175 | bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, |
3176 | block_t blkaddr, int type); | |
4d57b86d | 3177 | int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, |
cac5a3d8 | 3178 | int type, bool sync); |
4d57b86d CY |
3179 | void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); |
3180 | long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, | |
b0af6d49 | 3181 | long nr_to_write, enum iostat_type io_type); |
4d57b86d CY |
3182 | void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); |
3183 | void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); | |
3184 | void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all); | |
3185 | bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); | |
3186 | void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, | |
39d787be | 3187 | unsigned int devidx, int type); |
4d57b86d | 3188 | bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, |
39d787be | 3189 | unsigned int devidx, int type); |
cac5a3d8 | 3190 | int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); |
4d57b86d CY |
3191 | int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi); |
3192 | void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi); | |
3193 | void f2fs_add_orphan_inode(struct inode *inode); | |
3194 | void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); | |
3195 | int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi); | |
3196 | int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi); | |
3197 | void f2fs_update_dirty_page(struct inode *inode, struct page *page); | |
3198 | void f2fs_remove_dirty_inode(struct inode *inode); | |
3199 | int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); | |
f826b945 | 3200 | void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type); |
4d57b86d CY |
3201 | int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); |
3202 | void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi); | |
3203 | int __init f2fs_create_checkpoint_caches(void); | |
3204 | void f2fs_destroy_checkpoint_caches(void); | |
39a53e0c JK |
3205 | |
3206 | /* | |
3207 | * data.c | |
3208 | */ | |
6dbb1796 EB |
3209 | int f2fs_init_post_read_processing(void); |
3210 | void f2fs_destroy_post_read_processing(void); | |
b9109b0e JK |
3211 | void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); |
3212 | void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, | |
bab475c5 CY |
3213 | struct inode *inode, struct page *page, |
3214 | nid_t ino, enum page_type type); | |
b9109b0e | 3215 | void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); |
cac5a3d8 | 3216 | int f2fs_submit_page_bio(struct f2fs_io_info *fio); |
8648de2c | 3217 | int f2fs_merge_page_bio(struct f2fs_io_info *fio); |
fe16efe6 | 3218 | void f2fs_submit_page_write(struct f2fs_io_info *fio); |
cac5a3d8 DS |
3219 | struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, |
3220 | block_t blk_addr, struct bio *bio); | |
3221 | int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); | |
4d57b86d | 3222 | void f2fs_set_data_blkaddr(struct dnode_of_data *dn); |
cac5a3d8 | 3223 | void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); |
4d57b86d CY |
3224 | int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); |
3225 | int f2fs_reserve_new_block(struct dnode_of_data *dn); | |
cac5a3d8 DS |
3226 | int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); |
3227 | int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); | |
3228 | int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); | |
4d57b86d | 3229 | struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, |
cac5a3d8 | 3230 | int op_flags, bool for_write); |
4d57b86d CY |
3231 | struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index); |
3232 | struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index, | |
cac5a3d8 | 3233 | bool for_write); |
4d57b86d | 3234 | struct page *f2fs_get_new_data_page(struct inode *inode, |
cac5a3d8 | 3235 | struct page *ipage, pgoff_t index, bool new_i_size); |
4d57b86d | 3236 | int f2fs_do_write_data_page(struct f2fs_io_info *fio); |
39a86958 | 3237 | void __do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock); |
cac5a3d8 DS |
3238 | int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, |
3239 | int create, int flag); | |
3240 | int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | |
3241 | u64 start, u64 len); | |
4d57b86d CY |
3242 | bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); |
3243 | bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); | |
cac5a3d8 DS |
3244 | void f2fs_invalidate_page(struct page *page, unsigned int offset, |
3245 | unsigned int length); | |
3246 | int f2fs_release_page(struct page *page, gfp_t wait); | |
5b7a487c | 3247 | #ifdef CONFIG_MIGRATION |
cac5a3d8 DS |
3248 | int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, |
3249 | struct page *page, enum migrate_mode mode); | |
5b7a487c | 3250 | #endif |
b91050a8 | 3251 | bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len); |
5ec2d99d | 3252 | void f2fs_clear_page_cache_dirty_tag(struct page *page); |
39a53e0c JK |
3253 | |
3254 | /* | |
3255 | * gc.c | |
3256 | */ | |
4d57b86d CY |
3257 | int f2fs_start_gc_thread(struct f2fs_sb_info *sbi); |
3258 | void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi); | |
3259 | block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); | |
e066b83c JK |
3260 | int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, |
3261 | unsigned int segno); | |
4d57b86d | 3262 | void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); |
04f0b2ea | 3263 | int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count); |
39a53e0c JK |
3264 | |
3265 | /* | |
3266 | * recovery.c | |
3267 | */ | |
4d57b86d CY |
3268 | int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); |
3269 | bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi); | |
39a53e0c JK |
3270 | |
3271 | /* | |
3272 | * debug.c | |
3273 | */ | |
3274 | #ifdef CONFIG_F2FS_STAT_FS | |
3275 | struct f2fs_stat_info { | |
3276 | struct list_head stat_list; | |
3277 | struct f2fs_sb_info *sbi; | |
39a53e0c JK |
3278 | int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; |
3279 | int main_area_segs, main_area_sections, main_area_zones; | |
5b7ee374 CY |
3280 | unsigned long long hit_largest, hit_cached, hit_rbtree; |
3281 | unsigned long long hit_total, total_ext; | |
c00ba554 | 3282 | int ext_tree, zombie_tree, ext_node; |
2c8a4a28 JK |
3283 | int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; |
3284 | int ndirty_data, ndirty_qdata; | |
35782b23 | 3285 | int inmem_pages; |
2c8a4a28 | 3286 | unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; |
5b0ef73c JK |
3287 | int nats, dirty_nats, sits, dirty_sits; |
3288 | int free_nids, avail_nids, alloc_nids; | |
39a53e0c | 3289 | int total_count, utilization; |
8b8dd65f | 3290 | int bg_gc, nr_wb_cp_data, nr_wb_data; |
5f9abab4 | 3291 | int nr_rd_data, nr_rd_node, nr_rd_meta; |
02b16d0a | 3292 | int nr_dio_read, nr_dio_write; |
274bd9ba | 3293 | unsigned int io_skip_bggc, other_skip_bggc; |
14d8d5f7 CY |
3294 | int nr_flushing, nr_flushed, flush_list_empty; |
3295 | int nr_discarding, nr_discarded; | |
5f32366a | 3296 | int nr_discard_cmd; |
d84d1cbd | 3297 | unsigned int undiscard_blks; |
a00861db | 3298 | int inline_xattr, inline_inode, inline_dir, append, update, orphans; |
648d50ba | 3299 | int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; |
f83a2584 | 3300 | unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; |
39a53e0c JK |
3301 | unsigned int bimodal, avg_vblocks; |
3302 | int util_free, util_valid, util_invalid; | |
3303 | int rsvd_segs, overp_segs; | |
3304 | int dirty_count, node_pages, meta_pages; | |
42190d2a | 3305 | int prefree_count, call_count, cp_count, bg_cp_count; |
39a53e0c | 3306 | int tot_segs, node_segs, data_segs, free_segs, free_secs; |
e1235983 | 3307 | int bg_node_segs, bg_data_segs; |
39a53e0c | 3308 | int tot_blks, data_blks, node_blks; |
e1235983 | 3309 | int bg_data_blks, bg_node_blks; |
2ef79ecb | 3310 | unsigned long long skipped_atomic_files[2]; |
39a53e0c JK |
3311 | int curseg[NR_CURSEG_TYPE]; |
3312 | int cursec[NR_CURSEG_TYPE]; | |
3313 | int curzone[NR_CURSEG_TYPE]; | |
3314 | ||
b63e7be5 | 3315 | unsigned int meta_count[META_MAX]; |
39a53e0c JK |
3316 | unsigned int segment_count[2]; |
3317 | unsigned int block_count[2]; | |
b9a2c252 | 3318 | unsigned int inplace_count; |
9edcdabf | 3319 | unsigned long long base_mem, cache_mem, page_mem; |
39a53e0c JK |
3320 | }; |
3321 | ||
963d4f7d GZ |
3322 | static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) |
3323 | { | |
6c311ec6 | 3324 | return (struct f2fs_stat_info *)sbi->stat_info; |
963d4f7d GZ |
3325 | } |
3326 | ||
942e0be6 | 3327 | #define stat_inc_cp_count(si) ((si)->cp_count++) |
42190d2a | 3328 | #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) |
dcdfff65 JK |
3329 | #define stat_inc_call_count(si) ((si)->call_count++) |
3330 | #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) | |
274bd9ba CY |
3331 | #define stat_io_skip_bggc_count(sbi) ((sbi)->io_skip_bggc++) |
3332 | #define stat_other_skip_bggc_count(sbi) ((sbi)->other_skip_bggc++) | |
33fbd510 CY |
3333 | #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) |
3334 | #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) | |
5b7ee374 CY |
3335 | #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) |
3336 | #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) | |
3337 | #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) | |
3338 | #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) | |
d5e8f6c9 CY |
3339 | #define stat_inc_inline_xattr(inode) \ |
3340 | do { \ | |
3341 | if (f2fs_has_inline_xattr(inode)) \ | |
3342 | (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ | |
3343 | } while (0) | |
3344 | #define stat_dec_inline_xattr(inode) \ | |
3345 | do { \ | |
3346 | if (f2fs_has_inline_xattr(inode)) \ | |
3347 | (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ | |
3348 | } while (0) | |
0dbdc2ae JK |
3349 | #define stat_inc_inline_inode(inode) \ |
3350 | do { \ | |
3351 | if (f2fs_has_inline_data(inode)) \ | |
03e14d52 | 3352 | (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ |
0dbdc2ae JK |
3353 | } while (0) |
3354 | #define stat_dec_inline_inode(inode) \ | |
3355 | do { \ | |
3356 | if (f2fs_has_inline_data(inode)) \ | |
03e14d52 | 3357 | (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ |
0dbdc2ae | 3358 | } while (0) |
3289c061 JK |
3359 | #define stat_inc_inline_dir(inode) \ |
3360 | do { \ | |
3361 | if (f2fs_has_inline_dentry(inode)) \ | |
03e14d52 | 3362 | (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ |
3289c061 JK |
3363 | } while (0) |
3364 | #define stat_dec_inline_dir(inode) \ | |
3365 | do { \ | |
3366 | if (f2fs_has_inline_dentry(inode)) \ | |
03e14d52 | 3367 | (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ |
3289c061 | 3368 | } while (0) |
b63e7be5 CY |
3369 | #define stat_inc_meta_count(sbi, blkaddr) \ |
3370 | do { \ | |
3371 | if (blkaddr < SIT_I(sbi)->sit_base_addr) \ | |
3372 | atomic_inc(&(sbi)->meta_count[META_CP]); \ | |
3373 | else if (blkaddr < NM_I(sbi)->nat_blkaddr) \ | |
3374 | atomic_inc(&(sbi)->meta_count[META_SIT]); \ | |
3375 | else if (blkaddr < SM_I(sbi)->ssa_blkaddr) \ | |
3376 | atomic_inc(&(sbi)->meta_count[META_NAT]); \ | |
3377 | else if (blkaddr < SM_I(sbi)->main_blkaddr) \ | |
3378 | atomic_inc(&(sbi)->meta_count[META_SSA]); \ | |
3379 | } while (0) | |
dcdfff65 JK |
3380 | #define stat_inc_seg_type(sbi, curseg) \ |
3381 | ((sbi)->segment_count[(curseg)->alloc_type]++) | |
3382 | #define stat_inc_block_count(sbi, curseg) \ | |
3383 | ((sbi)->block_count[(curseg)->alloc_type]++) | |
b9a2c252 CL |
3384 | #define stat_inc_inplace_blocks(sbi) \ |
3385 | (atomic_inc(&(sbi)->inplace_count)) | |
26a28a0c | 3386 | #define stat_inc_atomic_write(inode) \ |
cac5a3d8 | 3387 | (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) |
26a28a0c | 3388 | #define stat_dec_atomic_write(inode) \ |
cac5a3d8 | 3389 | (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) |
26a28a0c JK |
3390 | #define stat_update_max_atomic_write(inode) \ |
3391 | do { \ | |
3392 | int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ | |
3393 | int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ | |
3394 | if (cur > max) \ | |
3395 | atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ | |
3396 | } while (0) | |
648d50ba CY |
3397 | #define stat_inc_volatile_write(inode) \ |
3398 | (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) | |
3399 | #define stat_dec_volatile_write(inode) \ | |
3400 | (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) | |
3401 | #define stat_update_max_volatile_write(inode) \ | |
3402 | do { \ | |
3403 | int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ | |
3404 | int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ | |
3405 | if (cur > max) \ | |
3406 | atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ | |
3407 | } while (0) | |
e1235983 | 3408 | #define stat_inc_seg_count(sbi, type, gc_type) \ |
39a53e0c | 3409 | do { \ |
963d4f7d | 3410 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
68afcf2d TK |
3411 | si->tot_segs++; \ |
3412 | if ((type) == SUM_TYPE_DATA) { \ | |
39a53e0c | 3413 | si->data_segs++; \ |
e1235983 CL |
3414 | si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ |
3415 | } else { \ | |
39a53e0c | 3416 | si->node_segs++; \ |
e1235983 CL |
3417 | si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ |
3418 | } \ | |
39a53e0c JK |
3419 | } while (0) |
3420 | ||
3421 | #define stat_inc_tot_blk_count(si, blks) \ | |
68afcf2d | 3422 | ((si)->tot_blks += (blks)) |
39a53e0c | 3423 | |
e1235983 | 3424 | #define stat_inc_data_blk_count(sbi, blks, gc_type) \ |
39a53e0c | 3425 | do { \ |
963d4f7d | 3426 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
39a53e0c JK |
3427 | stat_inc_tot_blk_count(si, blks); \ |
3428 | si->data_blks += (blks); \ | |
68afcf2d | 3429 | si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ |
39a53e0c JK |
3430 | } while (0) |
3431 | ||
e1235983 | 3432 | #define stat_inc_node_blk_count(sbi, blks, gc_type) \ |
39a53e0c | 3433 | do { \ |
963d4f7d | 3434 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
39a53e0c JK |
3435 | stat_inc_tot_blk_count(si, blks); \ |
3436 | si->node_blks += (blks); \ | |
68afcf2d | 3437 | si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ |
39a53e0c JK |
3438 | } while (0) |
3439 | ||
cac5a3d8 DS |
3440 | int f2fs_build_stats(struct f2fs_sb_info *sbi); |
3441 | void f2fs_destroy_stats(struct f2fs_sb_info *sbi); | |
21acc07d | 3442 | void __init f2fs_create_root_stats(void); |
4589d25d | 3443 | void f2fs_destroy_root_stats(void); |
39a53e0c | 3444 | #else |
d66450e7 AB |
3445 | #define stat_inc_cp_count(si) do { } while (0) |
3446 | #define stat_inc_bg_cp_count(si) do { } while (0) | |
3447 | #define stat_inc_call_count(si) do { } while (0) | |
3448 | #define stat_inc_bggc_count(si) do { } while (0) | |
274bd9ba CY |
3449 | #define stat_io_skip_bggc_count(sbi) do { } while (0) |
3450 | #define stat_other_skip_bggc_count(sbi) do { } while (0) | |
d66450e7 AB |
3451 | #define stat_inc_dirty_inode(sbi, type) do { } while (0) |
3452 | #define stat_dec_dirty_inode(sbi, type) do { } while (0) | |
3453 | #define stat_inc_total_hit(sb) do { } while (0) | |
3454 | #define stat_inc_rbtree_node_hit(sb) do { } while (0) | |
3455 | #define stat_inc_largest_node_hit(sbi) do { } while (0) | |
3456 | #define stat_inc_cached_node_hit(sbi) do { } while (0) | |
3457 | #define stat_inc_inline_xattr(inode) do { } while (0) | |
3458 | #define stat_dec_inline_xattr(inode) do { } while (0) | |
3459 | #define stat_inc_inline_inode(inode) do { } while (0) | |
3460 | #define stat_dec_inline_inode(inode) do { } while (0) | |
3461 | #define stat_inc_inline_dir(inode) do { } while (0) | |
3462 | #define stat_dec_inline_dir(inode) do { } while (0) | |
3463 | #define stat_inc_atomic_write(inode) do { } while (0) | |
3464 | #define stat_dec_atomic_write(inode) do { } while (0) | |
3465 | #define stat_update_max_atomic_write(inode) do { } while (0) | |
3466 | #define stat_inc_volatile_write(inode) do { } while (0) | |
3467 | #define stat_dec_volatile_write(inode) do { } while (0) | |
3468 | #define stat_update_max_volatile_write(inode) do { } while (0) | |
b63e7be5 | 3469 | #define stat_inc_meta_count(sbi, blkaddr) do { } while (0) |
d66450e7 AB |
3470 | #define stat_inc_seg_type(sbi, curseg) do { } while (0) |
3471 | #define stat_inc_block_count(sbi, curseg) do { } while (0) | |
3472 | #define stat_inc_inplace_blocks(sbi) do { } while (0) | |
3473 | #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) | |
3474 | #define stat_inc_tot_blk_count(si, blks) do { } while (0) | |
3475 | #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) | |
3476 | #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) | |
39a53e0c JK |
3477 | |
3478 | static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } | |
3479 | static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } | |
21acc07d | 3480 | static inline void __init f2fs_create_root_stats(void) { } |
4589d25d | 3481 | static inline void f2fs_destroy_root_stats(void) { } |
39a53e0c JK |
3482 | #endif |
3483 | ||
3484 | extern const struct file_operations f2fs_dir_operations; | |
2c2eb7a3 DR |
3485 | #ifdef CONFIG_UNICODE |
3486 | extern const struct dentry_operations f2fs_dentry_ops; | |
3487 | #endif | |
39a53e0c JK |
3488 | extern const struct file_operations f2fs_file_operations; |
3489 | extern const struct inode_operations f2fs_file_inode_operations; | |
3490 | extern const struct address_space_operations f2fs_dblock_aops; | |
3491 | extern const struct address_space_operations f2fs_node_aops; | |
3492 | extern const struct address_space_operations f2fs_meta_aops; | |
3493 | extern const struct inode_operations f2fs_dir_inode_operations; | |
3494 | extern const struct inode_operations f2fs_symlink_inode_operations; | |
cbaf042a | 3495 | extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; |
39a53e0c | 3496 | extern const struct inode_operations f2fs_special_inode_operations; |
4d57b86d | 3497 | extern struct kmem_cache *f2fs_inode_entry_slab; |
1001b347 | 3498 | |
e18c65b2 HL |
3499 | /* |
3500 | * inline.c | |
3501 | */ | |
cac5a3d8 DS |
3502 | bool f2fs_may_inline_data(struct inode *inode); |
3503 | bool f2fs_may_inline_dentry(struct inode *inode); | |
4d57b86d CY |
3504 | void f2fs_do_read_inline_data(struct page *page, struct page *ipage); |
3505 | void f2fs_truncate_inline_inode(struct inode *inode, | |
3506 | struct page *ipage, u64 from); | |
cac5a3d8 DS |
3507 | int f2fs_read_inline_data(struct inode *inode, struct page *page); |
3508 | int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); | |
3509 | int f2fs_convert_inline_inode(struct inode *inode); | |
3510 | int f2fs_write_inline_data(struct inode *inode, struct page *page); | |
bd446469 | 3511 | int f2fs_recover_inline_data(struct inode *inode, struct page *npage); |
4d57b86d | 3512 | struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, |
cac5a3d8 | 3513 | struct fscrypt_name *fname, struct page **res_page); |
4d57b86d | 3514 | int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, |
cac5a3d8 DS |
3515 | struct page *ipage); |
3516 | int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, | |
3517 | const struct qstr *orig_name, | |
3518 | struct inode *inode, nid_t ino, umode_t mode); | |
4d57b86d CY |
3519 | void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, |
3520 | struct page *page, struct inode *dir, | |
3521 | struct inode *inode); | |
cac5a3d8 DS |
3522 | bool f2fs_empty_inline_dir(struct inode *dir); |
3523 | int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, | |
3524 | struct fscrypt_str *fstr); | |
3525 | int f2fs_inline_data_fiemap(struct inode *inode, | |
3526 | struct fiemap_extent_info *fieinfo, | |
3527 | __u64 start, __u64 len); | |
cde4de12 | 3528 | |
2658e50d JK |
3529 | /* |
3530 | * shrinker.c | |
3531 | */ | |
cac5a3d8 DS |
3532 | unsigned long f2fs_shrink_count(struct shrinker *shrink, |
3533 | struct shrink_control *sc); | |
3534 | unsigned long f2fs_shrink_scan(struct shrinker *shrink, | |
3535 | struct shrink_control *sc); | |
3536 | void f2fs_join_shrinker(struct f2fs_sb_info *sbi); | |
3537 | void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); | |
2658e50d | 3538 | |
a28ef1f5 CY |
3539 | /* |
3540 | * extent_cache.c | |
3541 | */ | |
4dada3fd | 3542 | struct rb_entry *f2fs_lookup_rb_tree(struct rb_root_cached *root, |
004b6862 | 3543 | struct rb_entry *cached_re, unsigned int ofs); |
4d57b86d | 3544 | struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, |
4dada3fd CY |
3545 | struct rb_root_cached *root, |
3546 | struct rb_node **parent, | |
3547 | unsigned int ofs, bool *leftmost); | |
3548 | struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root, | |
004b6862 CY |
3549 | struct rb_entry *cached_re, unsigned int ofs, |
3550 | struct rb_entry **prev_entry, struct rb_entry **next_entry, | |
3551 | struct rb_node ***insert_p, struct rb_node **insert_parent, | |
4dada3fd | 3552 | bool force, bool *leftmost); |
4d57b86d | 3553 | bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi, |
4dada3fd | 3554 | struct rb_root_cached *root); |
cac5a3d8 DS |
3555 | unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); |
3556 | bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); | |
3557 | void f2fs_drop_extent_tree(struct inode *inode); | |
3558 | unsigned int f2fs_destroy_extent_node(struct inode *inode); | |
3559 | void f2fs_destroy_extent_tree(struct inode *inode); | |
3560 | bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, | |
3561 | struct extent_info *ei); | |
3562 | void f2fs_update_extent_cache(struct dnode_of_data *dn); | |
19b2c30d | 3563 | void f2fs_update_extent_cache_range(struct dnode_of_data *dn, |
cac5a3d8 | 3564 | pgoff_t fofs, block_t blkaddr, unsigned int len); |
4d57b86d CY |
3565 | void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi); |
3566 | int __init f2fs_create_extent_cache(void); | |
3567 | void f2fs_destroy_extent_cache(void); | |
a28ef1f5 | 3568 | |
8ceffcb2 CY |
3569 | /* |
3570 | * sysfs.c | |
3571 | */ | |
dc6b2055 JK |
3572 | int __init f2fs_init_sysfs(void); |
3573 | void f2fs_exit_sysfs(void); | |
3574 | int f2fs_register_sysfs(struct f2fs_sb_info *sbi); | |
3575 | void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); | |
8ceffcb2 | 3576 | |
95ae251f EB |
3577 | /* verity.c */ |
3578 | extern const struct fsverity_operations f2fs_verityops; | |
3579 | ||
cde4de12 JK |
3580 | /* |
3581 | * crypto support | |
3582 | */ | |
1958593e JK |
3583 | static inline bool f2fs_encrypted_file(struct inode *inode) |
3584 | { | |
62230e0d | 3585 | return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); |
1958593e JK |
3586 | } |
3587 | ||
cde4de12 JK |
3588 | static inline void f2fs_set_encrypted_inode(struct inode *inode) |
3589 | { | |
643fa961 | 3590 | #ifdef CONFIG_FS_ENCRYPTION |
cde4de12 | 3591 | file_set_encrypt(inode); |
9149a5eb | 3592 | f2fs_set_inode_flags(inode); |
cde4de12 JK |
3593 | #endif |
3594 | } | |
3595 | ||
6dbb1796 EB |
3596 | /* |
3597 | * Returns true if the reads of the inode's data need to undergo some | |
3598 | * postprocessing step, like decryption or authenticity verification. | |
3599 | */ | |
3600 | static inline bool f2fs_post_read_required(struct inode *inode) | |
cde4de12 | 3601 | { |
95ae251f | 3602 | return f2fs_encrypted_file(inode) || fsverity_active(inode); |
cde4de12 JK |
3603 | } |
3604 | ||
ccd31cb2 | 3605 | #define F2FS_FEATURE_FUNCS(name, flagname) \ |
7beb01f7 | 3606 | static inline int f2fs_sb_has_##name(struct f2fs_sb_info *sbi) \ |
ccd31cb2 | 3607 | { \ |
7beb01f7 | 3608 | return F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_##flagname); \ |
52763a4b JK |
3609 | } |
3610 | ||
ccd31cb2 SY |
3611 | F2FS_FEATURE_FUNCS(encrypt, ENCRYPT); |
3612 | F2FS_FEATURE_FUNCS(blkzoned, BLKZONED); | |
3613 | F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR); | |
3614 | F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA); | |
3615 | F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM); | |
3616 | F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); | |
3617 | F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); | |
3618 | F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); | |
b7c409de | 3619 | F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); |
95ae251f | 3620 | F2FS_FEATURE_FUNCS(verity, VERITY); |
d440c52d | 3621 | F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); |
5aba5430 | 3622 | F2FS_FEATURE_FUNCS(casefold, CASEFOLD); |
1c1d35df | 3623 | |
178053e2 | 3624 | #ifdef CONFIG_BLK_DEV_ZONED |
95175daf DLM |
3625 | static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, |
3626 | block_t blkaddr) | |
178053e2 DLM |
3627 | { |
3628 | unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; | |
3629 | ||
95175daf | 3630 | return test_bit(zno, FDEV(devi).blkz_seq); |
178053e2 DLM |
3631 | } |
3632 | #endif | |
3633 | ||
7d20c8ab | 3634 | static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi) |
52763a4b | 3635 | { |
7beb01f7 | 3636 | return f2fs_sb_has_blkzoned(sbi); |
7d20c8ab | 3637 | } |
96ba2dec | 3638 | |
7f3d7719 DLM |
3639 | static inline bool f2fs_bdev_support_discard(struct block_device *bdev) |
3640 | { | |
3641 | return blk_queue_discard(bdev_get_queue(bdev)) || | |
3642 | bdev_is_zoned(bdev); | |
3643 | } | |
3644 | ||
7d20c8ab CY |
3645 | static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi) |
3646 | { | |
7f3d7719 DLM |
3647 | int i; |
3648 | ||
3649 | if (!f2fs_is_multi_device(sbi)) | |
3650 | return f2fs_bdev_support_discard(sbi->sb->s_bdev); | |
3651 | ||
3652 | for (i = 0; i < sbi->s_ndevs; i++) | |
3653 | if (f2fs_bdev_support_discard(FDEV(i).bdev)) | |
3654 | return true; | |
3655 | return false; | |
7d20c8ab CY |
3656 | } |
3657 | ||
3658 | static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) | |
3659 | { | |
3660 | return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) || | |
3661 | f2fs_hw_should_discard(sbi); | |
52763a4b JK |
3662 | } |
3663 | ||
f824deb5 CY |
3664 | static inline bool f2fs_hw_is_readonly(struct f2fs_sb_info *sbi) |
3665 | { | |
3666 | int i; | |
3667 | ||
3668 | if (!f2fs_is_multi_device(sbi)) | |
3669 | return bdev_read_only(sbi->sb->s_bdev); | |
3670 | ||
3671 | for (i = 0; i < sbi->s_ndevs; i++) | |
3672 | if (bdev_read_only(FDEV(i).bdev)) | |
3673 | return true; | |
3674 | return false; | |
3675 | } | |
3676 | ||
3677 | ||
52763a4b JK |
3678 | static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) |
3679 | { | |
3680 | clear_opt(sbi, ADAPTIVE); | |
3681 | clear_opt(sbi, LFS); | |
3682 | ||
3683 | switch (mt) { | |
3684 | case F2FS_MOUNT_ADAPTIVE: | |
3685 | set_opt(sbi, ADAPTIVE); | |
3686 | break; | |
3687 | case F2FS_MOUNT_LFS: | |
3688 | set_opt(sbi, LFS); | |
3689 | break; | |
3690 | } | |
3691 | } | |
3692 | ||
fcc85a4d JK |
3693 | static inline bool f2fs_may_encrypt(struct inode *inode) |
3694 | { | |
643fa961 | 3695 | #ifdef CONFIG_FS_ENCRYPTION |
886f56f9 | 3696 | umode_t mode = inode->i_mode; |
fcc85a4d JK |
3697 | |
3698 | return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); | |
3699 | #else | |
6e45f2a5 | 3700 | return false; |
fcc85a4d JK |
3701 | #endif |
3702 | } | |
3703 | ||
f847c699 CY |
3704 | static inline int block_unaligned_IO(struct inode *inode, |
3705 | struct kiocb *iocb, struct iov_iter *iter) | |
b91050a8 | 3706 | { |
f847c699 CY |
3707 | unsigned int i_blkbits = READ_ONCE(inode->i_blkbits); |
3708 | unsigned int blocksize_mask = (1 << i_blkbits) - 1; | |
3709 | loff_t offset = iocb->ki_pos; | |
3710 | unsigned long align = offset | iov_iter_alignment(iter); | |
3711 | ||
3712 | return align & blocksize_mask; | |
3713 | } | |
3714 | ||
3715 | static inline int allow_outplace_dio(struct inode *inode, | |
3716 | struct kiocb *iocb, struct iov_iter *iter) | |
3717 | { | |
3718 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | |
3719 | int rw = iov_iter_rw(iter); | |
3720 | ||
3721 | return (test_opt(sbi, LFS) && (rw == WRITE) && | |
3722 | !block_unaligned_IO(inode, iocb, iter)); | |
3723 | } | |
3724 | ||
3725 | static inline bool f2fs_force_buffered_io(struct inode *inode, | |
3726 | struct kiocb *iocb, struct iov_iter *iter) | |
3727 | { | |
3728 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | |
3729 | int rw = iov_iter_rw(iter); | |
3730 | ||
3731 | if (f2fs_post_read_required(inode)) | |
3732 | return true; | |
0916878d | 3733 | if (f2fs_is_multi_device(sbi)) |
f847c699 CY |
3734 | return true; |
3735 | /* | |
3736 | * for blkzoned device, fallback direct IO to buffered IO, so | |
3737 | * all IOs can be serialized by log-structured write. | |
3738 | */ | |
7beb01f7 | 3739 | if (f2fs_sb_has_blkzoned(sbi)) |
f847c699 | 3740 | return true; |
9720ee80 CY |
3741 | if (test_opt(sbi, LFS) && (rw == WRITE)) { |
3742 | if (block_unaligned_IO(inode, iocb, iter)) | |
3743 | return true; | |
3744 | if (F2FS_IO_ALIGNED(sbi)) | |
3745 | return true; | |
3746 | } | |
4969c06a | 3747 | if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED) && |
3ee0c5d3 | 3748 | !IS_SWAPFILE(inode)) |
4354994f DR |
3749 | return true; |
3750 | ||
f847c699 | 3751 | return false; |
b91050a8 HL |
3752 | } |
3753 | ||
83a3bfdb | 3754 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
d494500a CY |
3755 | extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, |
3756 | unsigned int type); | |
83a3bfdb | 3757 | #else |
d494500a | 3758 | #define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) |
83a3bfdb JK |
3759 | #endif |
3760 | ||
af033b2a CY |
3761 | static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) |
3762 | { | |
3763 | #ifdef CONFIG_QUOTA | |
7beb01f7 | 3764 | if (f2fs_sb_has_quota_ino(sbi)) |
af033b2a CY |
3765 | return true; |
3766 | if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || | |
3767 | F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || | |
3768 | F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) | |
3769 | return true; | |
3770 | #endif | |
3771 | return false; | |
3772 | } | |
0af725fc | 3773 | |
10f966bb CY |
3774 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ |
3775 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | |
3776 | ||
e1074d4b | 3777 | #endif /* _LINUX_F2FS_H */ |