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