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