1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 * Copyright (c) 2017 Chao Yu <chao@kernel.org>
9 #include <linux/compiler.h>
10 #include <linux/proc_fs.h>
11 #include <linux/f2fs_fs.h>
12 #include <linux/seq_file.h>
13 #include <linux/unicode.h>
14 #include <linux/ioprio.h>
15 #include <linux/sysfs.h>
21 #include <trace/events/f2fs.h>
23 static struct proc_dir_entry
*f2fs_proc_root
;
25 /* Sysfs support for f2fs */
27 GC_THREAD
, /* struct f2fs_gc_thread */
28 SM_INFO
, /* struct f2fs_sm_info */
29 DCC_INFO
, /* struct discard_cmd_control */
30 NM_INFO
, /* struct f2fs_nm_info */
31 F2FS_SBI
, /* struct f2fs_sb_info */
32 #ifdef CONFIG_F2FS_STAT_FS
33 STAT_INFO
, /* struct f2fs_stat_info */
35 #ifdef CONFIG_F2FS_FAULT_INJECTION
36 FAULT_INFO_RATE
, /* struct f2fs_fault_info */
37 FAULT_INFO_TYPE
, /* struct f2fs_fault_info */
39 RESERVED_BLOCKS
, /* struct f2fs_sb_info */
40 CPRC_INFO
, /* struct ckpt_req_control */
41 ATGC_INFO
, /* struct atgc_management */
44 static const char *gc_mode_names
[MAX_GC_MODE
] = {
55 struct attribute attr
;
56 ssize_t (*show
)(struct f2fs_attr
*a
, struct f2fs_sb_info
*sbi
, char *buf
);
57 ssize_t (*store
)(struct f2fs_attr
*a
, struct f2fs_sb_info
*sbi
,
58 const char *buf
, size_t len
);
64 static ssize_t
f2fs_sbi_show(struct f2fs_attr
*a
,
65 struct f2fs_sb_info
*sbi
, char *buf
);
67 static unsigned char *__struct_ptr(struct f2fs_sb_info
*sbi
, int struct_type
)
69 if (struct_type
== GC_THREAD
)
70 return (unsigned char *)sbi
->gc_thread
;
71 else if (struct_type
== SM_INFO
)
72 return (unsigned char *)SM_I(sbi
);
73 else if (struct_type
== DCC_INFO
)
74 return (unsigned char *)SM_I(sbi
)->dcc_info
;
75 else if (struct_type
== NM_INFO
)
76 return (unsigned char *)NM_I(sbi
);
77 else if (struct_type
== F2FS_SBI
|| struct_type
== RESERVED_BLOCKS
)
78 return (unsigned char *)sbi
;
79 #ifdef CONFIG_F2FS_FAULT_INJECTION
80 else if (struct_type
== FAULT_INFO_RATE
||
81 struct_type
== FAULT_INFO_TYPE
)
82 return (unsigned char *)&F2FS_OPTION(sbi
).fault_info
;
84 #ifdef CONFIG_F2FS_STAT_FS
85 else if (struct_type
== STAT_INFO
)
86 return (unsigned char *)F2FS_STAT(sbi
);
88 else if (struct_type
== CPRC_INFO
)
89 return (unsigned char *)&sbi
->cprc_info
;
90 else if (struct_type
== ATGC_INFO
)
91 return (unsigned char *)&sbi
->am
;
95 static ssize_t
dirty_segments_show(struct f2fs_attr
*a
,
96 struct f2fs_sb_info
*sbi
, char *buf
)
98 return sysfs_emit(buf
, "%llu\n",
99 (unsigned long long)(dirty_segments(sbi
)));
102 static ssize_t
free_segments_show(struct f2fs_attr
*a
,
103 struct f2fs_sb_info
*sbi
, char *buf
)
105 return sysfs_emit(buf
, "%llu\n",
106 (unsigned long long)(free_segments(sbi
)));
109 static ssize_t
ovp_segments_show(struct f2fs_attr
*a
,
110 struct f2fs_sb_info
*sbi
, char *buf
)
112 return sysfs_emit(buf
, "%llu\n",
113 (unsigned long long)(overprovision_segments(sbi
)));
116 static ssize_t
lifetime_write_kbytes_show(struct f2fs_attr
*a
,
117 struct f2fs_sb_info
*sbi
, char *buf
)
119 return sysfs_emit(buf
, "%llu\n",
120 (unsigned long long)(sbi
->kbytes_written
+
121 ((f2fs_get_sectors_written(sbi
) -
122 sbi
->sectors_written_start
) >> 1)));
125 static ssize_t
sb_status_show(struct f2fs_attr
*a
,
126 struct f2fs_sb_info
*sbi
, char *buf
)
128 return sysfs_emit(buf
, "%lx\n", sbi
->s_flag
);
131 static ssize_t
cp_status_show(struct f2fs_attr
*a
,
132 struct f2fs_sb_info
*sbi
, char *buf
)
134 return sysfs_emit(buf
, "%x\n", le32_to_cpu(F2FS_CKPT(sbi
)->ckpt_flags
));
137 static ssize_t
pending_discard_show(struct f2fs_attr
*a
,
138 struct f2fs_sb_info
*sbi
, char *buf
)
140 if (!SM_I(sbi
)->dcc_info
)
142 return sysfs_emit(buf
, "%llu\n", (unsigned long long)atomic_read(
143 &SM_I(sbi
)->dcc_info
->discard_cmd_cnt
));
146 static ssize_t
issued_discard_show(struct f2fs_attr
*a
,
147 struct f2fs_sb_info
*sbi
, char *buf
)
149 if (!SM_I(sbi
)->dcc_info
)
151 return sysfs_emit(buf
, "%llu\n", (unsigned long long)atomic_read(
152 &SM_I(sbi
)->dcc_info
->issued_discard
));
155 static ssize_t
queued_discard_show(struct f2fs_attr
*a
,
156 struct f2fs_sb_info
*sbi
, char *buf
)
158 if (!SM_I(sbi
)->dcc_info
)
160 return sysfs_emit(buf
, "%llu\n", (unsigned long long)atomic_read(
161 &SM_I(sbi
)->dcc_info
->queued_discard
));
164 static ssize_t
undiscard_blks_show(struct f2fs_attr
*a
,
165 struct f2fs_sb_info
*sbi
, char *buf
)
167 if (!SM_I(sbi
)->dcc_info
)
169 return sysfs_emit(buf
, "%u\n",
170 SM_I(sbi
)->dcc_info
->undiscard_blks
);
173 static ssize_t
atgc_enabled_show(struct f2fs_attr
*a
,
174 struct f2fs_sb_info
*sbi
, char *buf
)
176 return sysfs_emit(buf
, "%d\n", sbi
->am
.atgc_enabled
? 1 : 0);
179 static ssize_t
gc_mode_show(struct f2fs_attr
*a
,
180 struct f2fs_sb_info
*sbi
, char *buf
)
182 return sysfs_emit(buf
, "%s\n", gc_mode_names
[sbi
->gc_mode
]);
185 static ssize_t
features_show(struct f2fs_attr
*a
,
186 struct f2fs_sb_info
*sbi
, char *buf
)
190 if (f2fs_sb_has_encrypt(sbi
))
191 len
+= sysfs_emit_at(buf
, len
, "%s",
193 if (f2fs_sb_has_blkzoned(sbi
))
194 len
+= sysfs_emit_at(buf
, len
, "%s%s",
195 len
? ", " : "", "blkzoned");
196 if (f2fs_sb_has_extra_attr(sbi
))
197 len
+= sysfs_emit_at(buf
, len
, "%s%s",
198 len
? ", " : "", "extra_attr");
199 if (f2fs_sb_has_project_quota(sbi
))
200 len
+= sysfs_emit_at(buf
, len
, "%s%s",
201 len
? ", " : "", "projquota");
202 if (f2fs_sb_has_inode_chksum(sbi
))
203 len
+= sysfs_emit_at(buf
, len
, "%s%s",
204 len
? ", " : "", "inode_checksum");
205 if (f2fs_sb_has_flexible_inline_xattr(sbi
))
206 len
+= sysfs_emit_at(buf
, len
, "%s%s",
207 len
? ", " : "", "flexible_inline_xattr");
208 if (f2fs_sb_has_quota_ino(sbi
))
209 len
+= sysfs_emit_at(buf
, len
, "%s%s",
210 len
? ", " : "", "quota_ino");
211 if (f2fs_sb_has_inode_crtime(sbi
))
212 len
+= sysfs_emit_at(buf
, len
, "%s%s",
213 len
? ", " : "", "inode_crtime");
214 if (f2fs_sb_has_lost_found(sbi
))
215 len
+= sysfs_emit_at(buf
, len
, "%s%s",
216 len
? ", " : "", "lost_found");
217 if (f2fs_sb_has_verity(sbi
))
218 len
+= sysfs_emit_at(buf
, len
, "%s%s",
219 len
? ", " : "", "verity");
220 if (f2fs_sb_has_sb_chksum(sbi
))
221 len
+= sysfs_emit_at(buf
, len
, "%s%s",
222 len
? ", " : "", "sb_checksum");
223 if (f2fs_sb_has_casefold(sbi
))
224 len
+= sysfs_emit_at(buf
, len
, "%s%s",
225 len
? ", " : "", "casefold");
226 if (f2fs_sb_has_readonly(sbi
))
227 len
+= sysfs_emit_at(buf
, len
, "%s%s",
228 len
? ", " : "", "readonly");
229 if (f2fs_sb_has_compression(sbi
))
230 len
+= sysfs_emit_at(buf
, len
, "%s%s",
231 len
? ", " : "", "compression");
232 len
+= sysfs_emit_at(buf
, len
, "%s%s",
233 len
? ", " : "", "pin_file");
234 len
+= sysfs_emit_at(buf
, len
, "\n");
238 static ssize_t
current_reserved_blocks_show(struct f2fs_attr
*a
,
239 struct f2fs_sb_info
*sbi
, char *buf
)
241 return sysfs_emit(buf
, "%u\n", sbi
->current_reserved_blocks
);
244 static ssize_t
unusable_show(struct f2fs_attr
*a
,
245 struct f2fs_sb_info
*sbi
, char *buf
)
249 if (test_opt(sbi
, DISABLE_CHECKPOINT
))
250 unusable
= sbi
->unusable_block_count
;
252 unusable
= f2fs_get_unusable_blocks(sbi
);
253 return sysfs_emit(buf
, "%llu\n", (unsigned long long)unusable
);
256 static ssize_t
encoding_show(struct f2fs_attr
*a
,
257 struct f2fs_sb_info
*sbi
, char *buf
)
259 #if IS_ENABLED(CONFIG_UNICODE)
260 struct super_block
*sb
= sbi
->sb
;
262 if (f2fs_sb_has_casefold(sbi
))
263 return sysfs_emit(buf
, "UTF-8 (%d.%d.%d)\n",
264 (sb
->s_encoding
->version
>> 16) & 0xff,
265 (sb
->s_encoding
->version
>> 8) & 0xff,
266 sb
->s_encoding
->version
& 0xff);
268 return sysfs_emit(buf
, "(none)\n");
271 static ssize_t
mounted_time_sec_show(struct f2fs_attr
*a
,
272 struct f2fs_sb_info
*sbi
, char *buf
)
274 return sysfs_emit(buf
, "%llu\n", SIT_I(sbi
)->mounted_time
);
277 #ifdef CONFIG_F2FS_STAT_FS
278 static ssize_t
moved_blocks_foreground_show(struct f2fs_attr
*a
,
279 struct f2fs_sb_info
*sbi
, char *buf
)
281 struct f2fs_stat_info
*si
= F2FS_STAT(sbi
);
283 return sysfs_emit(buf
, "%llu\n",
284 (unsigned long long)(si
->tot_blks
-
285 (si
->bg_data_blks
+ si
->bg_node_blks
)));
288 static ssize_t
moved_blocks_background_show(struct f2fs_attr
*a
,
289 struct f2fs_sb_info
*sbi
, char *buf
)
291 struct f2fs_stat_info
*si
= F2FS_STAT(sbi
);
293 return sysfs_emit(buf
, "%llu\n",
294 (unsigned long long)(si
->bg_data_blks
+ si
->bg_node_blks
));
297 static ssize_t
avg_vblocks_show(struct f2fs_attr
*a
,
298 struct f2fs_sb_info
*sbi
, char *buf
)
300 struct f2fs_stat_info
*si
= F2FS_STAT(sbi
);
302 si
->dirty_count
= dirty_segments(sbi
);
303 f2fs_update_sit_info(sbi
);
304 return sysfs_emit(buf
, "%llu\n", (unsigned long long)(si
->avg_vblocks
));
308 static ssize_t
main_blkaddr_show(struct f2fs_attr
*a
,
309 struct f2fs_sb_info
*sbi
, char *buf
)
311 return sysfs_emit(buf
, "%llu\n",
312 (unsigned long long)MAIN_BLKADDR(sbi
));
315 static ssize_t
f2fs_sbi_show(struct f2fs_attr
*a
,
316 struct f2fs_sb_info
*sbi
, char *buf
)
318 unsigned char *ptr
= NULL
;
321 ptr
= __struct_ptr(sbi
, a
->struct_type
);
325 if (!strcmp(a
->attr
.name
, "extension_list")) {
326 __u8 (*extlist
)[F2FS_EXTENSION_LEN
] =
327 sbi
->raw_super
->extension_list
;
328 int cold_count
= le32_to_cpu(sbi
->raw_super
->extension_count
);
329 int hot_count
= sbi
->raw_super
->hot_ext_count
;
332 len
+= sysfs_emit_at(buf
, len
, "cold file extension:\n");
333 for (i
= 0; i
< cold_count
; i
++)
334 len
+= sysfs_emit_at(buf
, len
, "%s\n", extlist
[i
]);
336 len
+= sysfs_emit_at(buf
, len
, "hot file extension:\n");
337 for (i
= cold_count
; i
< cold_count
+ hot_count
; i
++)
338 len
+= sysfs_emit_at(buf
, len
, "%s\n", extlist
[i
]);
343 if (!strcmp(a
->attr
.name
, "ckpt_thread_ioprio")) {
344 struct ckpt_req_control
*cprc
= &sbi
->cprc_info
;
345 int class = IOPRIO_PRIO_CLASS(cprc
->ckpt_thread_ioprio
);
346 int level
= IOPRIO_PRIO_LEVEL(cprc
->ckpt_thread_ioprio
);
348 if (class != IOPRIO_CLASS_RT
&& class != IOPRIO_CLASS_BE
)
351 return sysfs_emit(buf
, "%s,%d\n",
352 class == IOPRIO_CLASS_RT
? "rt" : "be", level
);
355 #ifdef CONFIG_F2FS_FS_COMPRESSION
356 if (!strcmp(a
->attr
.name
, "compr_written_block"))
357 return sysfs_emit(buf
, "%llu\n", sbi
->compr_written_block
);
359 if (!strcmp(a
->attr
.name
, "compr_saved_block"))
360 return sysfs_emit(buf
, "%llu\n", sbi
->compr_saved_block
);
362 if (!strcmp(a
->attr
.name
, "compr_new_inode"))
363 return sysfs_emit(buf
, "%u\n", sbi
->compr_new_inode
);
366 if (!strcmp(a
->attr
.name
, "gc_segment_mode"))
367 return sysfs_emit(buf
, "%u\n", sbi
->gc_segment_mode
);
369 if (!strcmp(a
->attr
.name
, "gc_reclaimed_segments")) {
370 return sysfs_emit(buf
, "%u\n",
371 sbi
->gc_reclaimed_segs
[sbi
->gc_segment_mode
]);
374 if (!strcmp(a
->attr
.name
, "current_atomic_write")) {
375 s64 current_write
= atomic64_read(&sbi
->current_atomic_write
);
377 return sysfs_emit(buf
, "%lld\n", current_write
);
380 if (!strcmp(a
->attr
.name
, "peak_atomic_write"))
381 return sysfs_emit(buf
, "%lld\n", sbi
->peak_atomic_write
);
383 if (!strcmp(a
->attr
.name
, "committed_atomic_block"))
384 return sysfs_emit(buf
, "%llu\n", sbi
->committed_atomic_block
);
386 if (!strcmp(a
->attr
.name
, "revoked_atomic_block"))
387 return sysfs_emit(buf
, "%llu\n", sbi
->revoked_atomic_block
);
389 #ifdef CONFIG_F2FS_STAT_FS
390 if (!strcmp(a
->attr
.name
, "cp_foreground_calls"))
391 return sysfs_emit(buf
, "%d\n",
392 atomic_read(&sbi
->cp_call_count
[TOTAL_CALL
]) -
393 atomic_read(&sbi
->cp_call_count
[BACKGROUND
]));
394 if (!strcmp(a
->attr
.name
, "cp_background_calls"))
395 return sysfs_emit(buf
, "%d\n",
396 atomic_read(&sbi
->cp_call_count
[BACKGROUND
]));
399 ui
= (unsigned int *)(ptr
+ a
->offset
);
401 return sysfs_emit(buf
, "%u\n", *ui
);
404 static ssize_t
__sbi_store(struct f2fs_attr
*a
,
405 struct f2fs_sb_info
*sbi
,
406 const char *buf
, size_t count
)
413 ptr
= __struct_ptr(sbi
, a
->struct_type
);
417 if (!strcmp(a
->attr
.name
, "extension_list")) {
418 const char *name
= strim((char *)buf
);
419 bool set
= true, hot
;
421 if (!strncmp(name
, "[h]", 3))
423 else if (!strncmp(name
, "[c]", 3))
435 if (!strlen(name
) || strlen(name
) >= F2FS_EXTENSION_LEN
)
438 f2fs_down_write(&sbi
->sb_lock
);
440 ret
= f2fs_update_extension_list(sbi
, name
, hot
, set
);
444 ret
= f2fs_commit_super(sbi
, false);
446 f2fs_update_extension_list(sbi
, name
, hot
, !set
);
448 f2fs_up_write(&sbi
->sb_lock
);
449 return ret
? ret
: count
;
452 if (!strcmp(a
->attr
.name
, "ckpt_thread_ioprio")) {
453 const char *name
= strim((char *)buf
);
454 struct ckpt_req_control
*cprc
= &sbi
->cprc_info
;
459 if (!strncmp(name
, "rt,", 3))
460 class = IOPRIO_CLASS_RT
;
461 else if (!strncmp(name
, "be,", 3))
462 class = IOPRIO_CLASS_BE
;
467 ret
= kstrtol(name
, 10, &level
);
470 if (level
>= IOPRIO_NR_LEVELS
|| level
< 0)
473 cprc
->ckpt_thread_ioprio
= IOPRIO_PRIO_VALUE(class, level
);
474 if (test_opt(sbi
, MERGE_CHECKPOINT
)) {
475 ret
= set_task_ioprio(cprc
->f2fs_issue_ckpt
,
476 cprc
->ckpt_thread_ioprio
);
484 ui
= (unsigned int *)(ptr
+ a
->offset
);
486 ret
= kstrtoul(skip_spaces(buf
), 0, &t
);
489 #ifdef CONFIG_F2FS_FAULT_INJECTION
490 if (a
->struct_type
== FAULT_INFO_TYPE
) {
491 if (f2fs_build_fault_attr(sbi
, 0, t
))
495 if (a
->struct_type
== FAULT_INFO_RATE
) {
496 if (f2fs_build_fault_attr(sbi
, t
, 0))
501 if (a
->struct_type
== RESERVED_BLOCKS
) {
502 spin_lock(&sbi
->stat_lock
);
503 if (t
> (unsigned long)(sbi
->user_block_count
-
504 F2FS_OPTION(sbi
).root_reserved_blocks
)) {
505 spin_unlock(&sbi
->stat_lock
);
509 sbi
->current_reserved_blocks
= min(sbi
->reserved_blocks
,
510 sbi
->user_block_count
- valid_user_blocks(sbi
));
511 spin_unlock(&sbi
->stat_lock
);
515 if (!strcmp(a
->attr
.name
, "discard_io_aware_gran")) {
516 if (t
> MAX_PLIST_NUM
)
518 if (!f2fs_block_unit_discard(sbi
))
526 if (!strcmp(a
->attr
.name
, "discard_granularity")) {
527 if (t
== 0 || t
> MAX_PLIST_NUM
)
529 if (!f2fs_block_unit_discard(sbi
))
537 if (!strcmp(a
->attr
.name
, "max_ordered_discard")) {
538 if (t
== 0 || t
> MAX_PLIST_NUM
)
540 if (!f2fs_block_unit_discard(sbi
))
546 if (!strcmp(a
->attr
.name
, "discard_urgent_util")) {
553 if (!strcmp(a
->attr
.name
, "discard_io_aware")) {
554 if (t
>= DPOLICY_IO_AWARE_MAX
)
560 if (!strcmp(a
->attr
.name
, "migration_granularity")) {
561 if (t
== 0 || t
> SEGS_PER_SEC(sbi
))
565 if (!strcmp(a
->attr
.name
, "migration_window_granularity")) {
566 if (t
== 0 || t
> SEGS_PER_SEC(sbi
))
570 if (!strcmp(a
->attr
.name
, "gc_urgent")) {
572 sbi
->gc_mode
= GC_NORMAL
;
574 sbi
->gc_mode
= GC_URGENT_HIGH
;
575 if (sbi
->gc_thread
) {
576 sbi
->gc_thread
->gc_wake
= true;
577 wake_up_interruptible_all(
578 &sbi
->gc_thread
->gc_wait_queue_head
);
579 wake_up_discard_thread(sbi
, true);
582 sbi
->gc_mode
= GC_URGENT_LOW
;
584 sbi
->gc_mode
= GC_URGENT_MID
;
585 if (sbi
->gc_thread
) {
586 sbi
->gc_thread
->gc_wake
= true;
587 wake_up_interruptible_all(
588 &sbi
->gc_thread
->gc_wait_queue_head
);
595 if (!strcmp(a
->attr
.name
, "gc_idle")) {
596 if (t
== GC_IDLE_CB
) {
597 sbi
->gc_mode
= GC_IDLE_CB
;
598 } else if (t
== GC_IDLE_GREEDY
) {
599 sbi
->gc_mode
= GC_IDLE_GREEDY
;
600 } else if (t
== GC_IDLE_AT
) {
601 if (!sbi
->am
.atgc_enabled
)
603 sbi
->gc_mode
= GC_IDLE_AT
;
605 sbi
->gc_mode
= GC_NORMAL
;
610 if (!strcmp(a
->attr
.name
, "gc_remaining_trials")) {
611 spin_lock(&sbi
->gc_remaining_trials_lock
);
612 sbi
->gc_remaining_trials
= t
;
613 spin_unlock(&sbi
->gc_remaining_trials_lock
);
618 #ifdef CONFIG_F2FS_IOSTAT
619 if (!strcmp(a
->attr
.name
, "iostat_enable")) {
620 sbi
->iostat_enable
= !!t
;
621 if (!sbi
->iostat_enable
)
622 f2fs_reset_iostat(sbi
);
626 if (!strcmp(a
->attr
.name
, "iostat_period_ms")) {
627 if (t
< MIN_IOSTAT_PERIOD_MS
|| t
> MAX_IOSTAT_PERIOD_MS
)
629 spin_lock_irq(&sbi
->iostat_lock
);
630 sbi
->iostat_period_ms
= (unsigned int)t
;
631 spin_unlock_irq(&sbi
->iostat_lock
);
636 #ifdef CONFIG_BLK_DEV_ZONED
637 if (!strcmp(a
->attr
.name
, "blkzone_alloc_policy")) {
638 if (t
< BLKZONE_ALLOC_PRIOR_SEQ
|| t
> BLKZONE_ALLOC_PRIOR_CONV
)
640 sbi
->blkzone_alloc_policy
= t
;
645 #ifdef CONFIG_F2FS_FS_COMPRESSION
646 if (!strcmp(a
->attr
.name
, "compr_written_block") ||
647 !strcmp(a
->attr
.name
, "compr_saved_block")) {
650 sbi
->compr_written_block
= 0;
651 sbi
->compr_saved_block
= 0;
655 if (!strcmp(a
->attr
.name
, "compr_new_inode")) {
658 sbi
->compr_new_inode
= 0;
662 if (!strcmp(a
->attr
.name
, "compress_percent")) {
663 if (t
== 0 || t
> 100)
669 if (!strcmp(a
->attr
.name
, "compress_watermark")) {
670 if (t
== 0 || t
> 100)
677 if (!strcmp(a
->attr
.name
, "atgc_candidate_ratio")) {
680 sbi
->am
.candidate_ratio
= t
;
684 if (!strcmp(a
->attr
.name
, "atgc_age_weight")) {
687 sbi
->am
.age_weight
= t
;
691 if (!strcmp(a
->attr
.name
, "gc_segment_mode")) {
693 sbi
->gc_segment_mode
= t
;
699 if (!strcmp(a
->attr
.name
, "gc_pin_file_threshold")) {
700 if (t
> MAX_GC_FAILED_PINNED_FILES
)
702 sbi
->gc_pin_file_threshold
= t
;
706 if (!strcmp(a
->attr
.name
, "gc_reclaimed_segments")) {
709 sbi
->gc_reclaimed_segs
[sbi
->gc_segment_mode
] = 0;
713 if (!strcmp(a
->attr
.name
, "seq_file_ra_mul")) {
714 if (t
>= MIN_RA_MUL
&& t
<= MAX_RA_MUL
)
715 sbi
->seq_file_ra_mul
= t
;
721 if (!strcmp(a
->attr
.name
, "max_fragment_chunk")) {
722 if (t
>= MIN_FRAGMENT_SIZE
&& t
<= MAX_FRAGMENT_SIZE
)
723 sbi
->max_fragment_chunk
= t
;
729 if (!strcmp(a
->attr
.name
, "max_fragment_hole")) {
730 if (t
>= MIN_FRAGMENT_SIZE
&& t
<= MAX_FRAGMENT_SIZE
)
731 sbi
->max_fragment_hole
= t
;
737 if (!strcmp(a
->attr
.name
, "peak_atomic_write")) {
740 sbi
->peak_atomic_write
= 0;
744 if (!strcmp(a
->attr
.name
, "committed_atomic_block")) {
747 sbi
->committed_atomic_block
= 0;
751 if (!strcmp(a
->attr
.name
, "revoked_atomic_block")) {
754 sbi
->revoked_atomic_block
= 0;
758 if (!strcmp(a
->attr
.name
, "readdir_ra")) {
759 sbi
->readdir_ra
= !!t
;
763 if (!strcmp(a
->attr
.name
, "hot_data_age_threshold")) {
764 if (t
== 0 || t
>= sbi
->warm_data_age_threshold
)
768 *ui
= (unsigned int)t
;
772 if (!strcmp(a
->attr
.name
, "warm_data_age_threshold")) {
773 if (t
<= sbi
->hot_data_age_threshold
)
777 *ui
= (unsigned int)t
;
781 if (!strcmp(a
->attr
.name
, "last_age_weight")) {
786 *ui
= (unsigned int)t
;
790 if (!strcmp(a
->attr
.name
, "max_read_extent_count")) {
793 *ui
= (unsigned int)t
;
797 if (!strcmp(a
->attr
.name
, "ipu_policy")) {
798 if (t
>= BIT(F2FS_IPU_MAX
))
800 /* allow F2FS_IPU_NOCACHE only for IPU in the pinned file */
801 if (f2fs_lfs_mode(sbi
) && (t
& ~BIT(F2FS_IPU_NOCACHE
)))
803 SM_I(sbi
)->ipu_policy
= (unsigned int)t
;
807 if (!strcmp(a
->attr
.name
, "dir_level")) {
808 if (t
> MAX_DIR_HASH_DEPTH
)
814 *ui
= (unsigned int)t
;
819 static ssize_t
f2fs_sbi_store(struct f2fs_attr
*a
,
820 struct f2fs_sb_info
*sbi
,
821 const char *buf
, size_t count
)
824 bool gc_entry
= (!strcmp(a
->attr
.name
, "gc_urgent") ||
825 a
->struct_type
== GC_THREAD
);
828 if (!down_read_trylock(&sbi
->sb
->s_umount
))
831 ret
= __sbi_store(a
, sbi
, buf
, count
);
833 up_read(&sbi
->sb
->s_umount
);
838 static ssize_t
f2fs_attr_show(struct kobject
*kobj
,
839 struct attribute
*attr
, char *buf
)
841 struct f2fs_sb_info
*sbi
= container_of(kobj
, struct f2fs_sb_info
,
843 struct f2fs_attr
*a
= container_of(attr
, struct f2fs_attr
, attr
);
845 return a
->show
? a
->show(a
, sbi
, buf
) : 0;
848 static ssize_t
f2fs_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
849 const char *buf
, size_t len
)
851 struct f2fs_sb_info
*sbi
= container_of(kobj
, struct f2fs_sb_info
,
853 struct f2fs_attr
*a
= container_of(attr
, struct f2fs_attr
, attr
);
855 return a
->store
? a
->store(a
, sbi
, buf
, len
) : 0;
858 static void f2fs_sb_release(struct kobject
*kobj
)
860 struct f2fs_sb_info
*sbi
= container_of(kobj
, struct f2fs_sb_info
,
862 complete(&sbi
->s_kobj_unregister
);
866 * Note that there are three feature list entries:
867 * 1) /sys/fs/f2fs/features
868 * : shows runtime features supported by in-kernel f2fs along with Kconfig.
869 * - ref. F2FS_FEATURE_RO_ATTR()
871 * 2) /sys/fs/f2fs/$s_id/features <deprecated>
872 * : shows on-disk features enabled by mkfs.f2fs, used for old kernels. This
873 * won't add new feature anymore, and thus, users should check entries in 3)
874 * instead of this 2).
876 * 3) /sys/fs/f2fs/$s_id/feature_list
877 * : shows on-disk features enabled by mkfs.f2fs per instance, which follows
878 * sysfs entry rule where each entry should expose single value.
879 * This list covers old feature list provided by 2) and beyond. Therefore,
880 * please add new on-disk feature in this list only.
881 * - ref. F2FS_SB_FEATURE_RO_ATTR()
883 static ssize_t
f2fs_feature_show(struct f2fs_attr
*a
,
884 struct f2fs_sb_info
*sbi
, char *buf
)
886 return sysfs_emit(buf
, "supported\n");
889 #define F2FS_FEATURE_RO_ATTR(_name) \
890 static struct f2fs_attr f2fs_attr_##_name = { \
891 .attr = {.name = __stringify(_name), .mode = 0444 }, \
892 .show = f2fs_feature_show, \
895 static ssize_t
f2fs_sb_feature_show(struct f2fs_attr
*a
,
896 struct f2fs_sb_info
*sbi
, char *buf
)
898 if (F2FS_HAS_FEATURE(sbi
, a
->id
))
899 return sysfs_emit(buf
, "supported\n");
900 return sysfs_emit(buf
, "unsupported\n");
903 #define F2FS_SB_FEATURE_RO_ATTR(_name, _feat) \
904 static struct f2fs_attr f2fs_attr_sb_##_name = { \
905 .attr = {.name = __stringify(_name), .mode = 0444 }, \
906 .show = f2fs_sb_feature_show, \
907 .id = F2FS_FEATURE_##_feat, \
910 #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
911 static struct f2fs_attr f2fs_attr_##_name = { \
912 .attr = {.name = __stringify(_name), .mode = _mode }, \
915 .struct_type = _struct_type, \
919 #define F2FS_RO_ATTR(struct_type, struct_name, name, elname) \
920 F2FS_ATTR_OFFSET(struct_type, name, 0444, \
921 f2fs_sbi_show, NULL, \
922 offsetof(struct struct_name, elname))
924 #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
925 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
926 f2fs_sbi_show, f2fs_sbi_store, \
927 offsetof(struct struct_name, elname))
929 #define F2FS_GENERAL_RO_ATTR(name) \
930 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
932 #ifdef CONFIG_F2FS_STAT_FS
933 #define STAT_INFO_RO_ATTR(name, elname) \
934 F2FS_RO_ATTR(STAT_INFO, f2fs_stat_info, name, elname)
937 #define GC_THREAD_RW_ATTR(name, elname) \
938 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, name, elname)
940 #define SM_INFO_RW_ATTR(name, elname) \
941 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, name, elname)
943 #define SM_INFO_GENERAL_RW_ATTR(elname) \
944 SM_INFO_RW_ATTR(elname, elname)
946 #define DCC_INFO_RW_ATTR(name, elname) \
947 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, name, elname)
949 #define DCC_INFO_GENERAL_RW_ATTR(elname) \
950 DCC_INFO_RW_ATTR(elname, elname)
952 #define NM_INFO_RW_ATTR(name, elname) \
953 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, name, elname)
955 #define NM_INFO_GENERAL_RW_ATTR(elname) \
956 NM_INFO_RW_ATTR(elname, elname)
958 #define F2FS_SBI_RW_ATTR(name, elname) \
959 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, name, elname)
961 #define F2FS_SBI_GENERAL_RW_ATTR(elname) \
962 F2FS_SBI_RW_ATTR(elname, elname)
964 #define F2FS_SBI_GENERAL_RO_ATTR(elname) \
965 F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, elname, elname)
967 #ifdef CONFIG_F2FS_FAULT_INJECTION
968 #define FAULT_INFO_GENERAL_RW_ATTR(type, elname) \
969 F2FS_RW_ATTR(type, f2fs_fault_info, elname, elname)
972 #define RESERVED_BLOCKS_GENERAL_RW_ATTR(elname) \
973 F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, elname, elname)
975 #define CPRC_INFO_GENERAL_RW_ATTR(elname) \
976 F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, elname, elname)
978 #define ATGC_INFO_RW_ATTR(name, elname) \
979 F2FS_RW_ATTR(ATGC_INFO, atgc_management, name, elname)
982 GC_THREAD_RW_ATTR(gc_urgent_sleep_time
, urgent_sleep_time
);
983 GC_THREAD_RW_ATTR(gc_min_sleep_time
, min_sleep_time
);
984 GC_THREAD_RW_ATTR(gc_max_sleep_time
, max_sleep_time
);
985 GC_THREAD_RW_ATTR(gc_no_gc_sleep_time
, no_gc_sleep_time
);
986 GC_THREAD_RW_ATTR(gc_no_zoned_gc_percent
, no_zoned_gc_percent
);
987 GC_THREAD_RW_ATTR(gc_boost_zoned_gc_percent
, boost_zoned_gc_percent
);
988 GC_THREAD_RW_ATTR(gc_valid_thresh_ratio
, valid_thresh_ratio
);
991 SM_INFO_RW_ATTR(reclaim_segments
, rec_prefree_segments
);
992 SM_INFO_GENERAL_RW_ATTR(ipu_policy
);
993 SM_INFO_GENERAL_RW_ATTR(min_ipu_util
);
994 SM_INFO_GENERAL_RW_ATTR(min_fsync_blocks
);
995 SM_INFO_GENERAL_RW_ATTR(min_seq_blocks
);
996 SM_INFO_GENERAL_RW_ATTR(min_hot_blocks
);
997 SM_INFO_GENERAL_RW_ATTR(min_ssr_sections
);
998 SM_INFO_GENERAL_RW_ATTR(reserved_segments
);
1001 DCC_INFO_RW_ATTR(max_small_discards
, max_discards
);
1002 DCC_INFO_GENERAL_RW_ATTR(max_discard_request
);
1003 DCC_INFO_GENERAL_RW_ATTR(min_discard_issue_time
);
1004 DCC_INFO_GENERAL_RW_ATTR(mid_discard_issue_time
);
1005 DCC_INFO_GENERAL_RW_ATTR(max_discard_issue_time
);
1006 DCC_INFO_GENERAL_RW_ATTR(discard_io_aware_gran
);
1007 DCC_INFO_GENERAL_RW_ATTR(discard_urgent_util
);
1008 DCC_INFO_GENERAL_RW_ATTR(discard_granularity
);
1009 DCC_INFO_GENERAL_RW_ATTR(max_ordered_discard
);
1010 DCC_INFO_GENERAL_RW_ATTR(discard_io_aware
);
1013 NM_INFO_RW_ATTR(max_roll_forward_node_blocks
, max_rf_node_blocks
);
1014 NM_INFO_GENERAL_RW_ATTR(ram_thresh
);
1015 NM_INFO_GENERAL_RW_ATTR(ra_nid_pages
);
1016 NM_INFO_GENERAL_RW_ATTR(dirty_nats_ratio
);
1019 F2FS_RW_ATTR(F2FS_SBI
, f2fs_super_block
, extension_list
, extension_list
);
1020 F2FS_SBI_RW_ATTR(gc_idle
, gc_mode
);
1021 F2FS_SBI_RW_ATTR(gc_urgent
, gc_mode
);
1022 F2FS_SBI_RW_ATTR(cp_interval
, interval_time
[CP_TIME
]);
1023 F2FS_SBI_RW_ATTR(idle_interval
, interval_time
[REQ_TIME
]);
1024 F2FS_SBI_RW_ATTR(discard_idle_interval
, interval_time
[DISCARD_TIME
]);
1025 F2FS_SBI_RW_ATTR(gc_idle_interval
, interval_time
[GC_TIME
]);
1026 F2FS_SBI_RW_ATTR(umount_discard_timeout
, interval_time
[UMOUNT_DISCARD_TIMEOUT
]);
1027 F2FS_SBI_RW_ATTR(gc_pin_file_thresh
, gc_pin_file_threshold
);
1028 F2FS_SBI_RW_ATTR(gc_reclaimed_segments
, gc_reclaimed_segs
);
1029 F2FS_SBI_GENERAL_RW_ATTR(max_victim_search
);
1030 F2FS_SBI_GENERAL_RW_ATTR(migration_granularity
);
1031 F2FS_SBI_GENERAL_RW_ATTR(migration_window_granularity
);
1032 F2FS_SBI_GENERAL_RW_ATTR(dir_level
);
1033 #ifdef CONFIG_F2FS_IOSTAT
1034 F2FS_SBI_GENERAL_RW_ATTR(iostat_enable
);
1035 F2FS_SBI_GENERAL_RW_ATTR(iostat_period_ms
);
1037 F2FS_SBI_GENERAL_RW_ATTR(readdir_ra
);
1038 F2FS_SBI_GENERAL_RW_ATTR(max_io_bytes
);
1039 F2FS_SBI_GENERAL_RW_ATTR(data_io_flag
);
1040 F2FS_SBI_GENERAL_RW_ATTR(node_io_flag
);
1041 F2FS_SBI_GENERAL_RW_ATTR(gc_remaining_trials
);
1042 F2FS_SBI_GENERAL_RW_ATTR(seq_file_ra_mul
);
1043 F2FS_SBI_GENERAL_RW_ATTR(gc_segment_mode
);
1044 F2FS_SBI_GENERAL_RW_ATTR(max_fragment_chunk
);
1045 F2FS_SBI_GENERAL_RW_ATTR(max_fragment_hole
);
1046 #ifdef CONFIG_F2FS_FS_COMPRESSION
1047 F2FS_SBI_GENERAL_RW_ATTR(compr_written_block
);
1048 F2FS_SBI_GENERAL_RW_ATTR(compr_saved_block
);
1049 F2FS_SBI_GENERAL_RW_ATTR(compr_new_inode
);
1050 F2FS_SBI_GENERAL_RW_ATTR(compress_percent
);
1051 F2FS_SBI_GENERAL_RW_ATTR(compress_watermark
);
1054 F2FS_SBI_GENERAL_RO_ATTR(current_atomic_write
);
1055 F2FS_SBI_GENERAL_RW_ATTR(peak_atomic_write
);
1056 F2FS_SBI_GENERAL_RW_ATTR(committed_atomic_block
);
1057 F2FS_SBI_GENERAL_RW_ATTR(revoked_atomic_block
);
1058 /* block age extent cache */
1059 F2FS_SBI_GENERAL_RW_ATTR(hot_data_age_threshold
);
1060 F2FS_SBI_GENERAL_RW_ATTR(warm_data_age_threshold
);
1061 F2FS_SBI_GENERAL_RW_ATTR(last_age_weight
);
1062 /* read extent cache */
1063 F2FS_SBI_GENERAL_RW_ATTR(max_read_extent_count
);
1064 #ifdef CONFIG_BLK_DEV_ZONED
1065 F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec
);
1066 F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy
);
1069 /* STAT_INFO ATTR */
1070 #ifdef CONFIG_F2FS_STAT_FS
1071 STAT_INFO_RO_ATTR(cp_foreground_calls
, cp_call_count
[FOREGROUND
]);
1072 STAT_INFO_RO_ATTR(cp_background_calls
, cp_call_count
[BACKGROUND
]);
1073 STAT_INFO_RO_ATTR(gc_foreground_calls
, gc_call_count
[FOREGROUND
]);
1074 STAT_INFO_RO_ATTR(gc_background_calls
, gc_call_count
[BACKGROUND
]);
1077 /* FAULT_INFO ATTR */
1078 #ifdef CONFIG_F2FS_FAULT_INJECTION
1079 FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_RATE
, inject_rate
);
1080 FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_TYPE
, inject_type
);
1083 /* RESERVED_BLOCKS ATTR */
1084 RESERVED_BLOCKS_GENERAL_RW_ATTR(reserved_blocks
);
1086 /* CPRC_INFO ATTR */
1087 CPRC_INFO_GENERAL_RW_ATTR(ckpt_thread_ioprio
);
1089 /* ATGC_INFO ATTR */
1090 ATGC_INFO_RW_ATTR(atgc_candidate_ratio
, candidate_ratio
);
1091 ATGC_INFO_RW_ATTR(atgc_candidate_count
, max_candidate_count
);
1092 ATGC_INFO_RW_ATTR(atgc_age_weight
, age_weight
);
1093 ATGC_INFO_RW_ATTR(atgc_age_threshold
, age_threshold
);
1095 F2FS_GENERAL_RO_ATTR(dirty_segments
);
1096 F2FS_GENERAL_RO_ATTR(free_segments
);
1097 F2FS_GENERAL_RO_ATTR(ovp_segments
);
1098 F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes
);
1099 F2FS_GENERAL_RO_ATTR(features
);
1100 F2FS_GENERAL_RO_ATTR(current_reserved_blocks
);
1101 F2FS_GENERAL_RO_ATTR(unusable
);
1102 F2FS_GENERAL_RO_ATTR(encoding
);
1103 F2FS_GENERAL_RO_ATTR(mounted_time_sec
);
1104 F2FS_GENERAL_RO_ATTR(main_blkaddr
);
1105 F2FS_GENERAL_RO_ATTR(pending_discard
);
1106 F2FS_GENERAL_RO_ATTR(atgc_enabled
);
1107 F2FS_GENERAL_RO_ATTR(gc_mode
);
1108 #ifdef CONFIG_F2FS_STAT_FS
1109 F2FS_GENERAL_RO_ATTR(moved_blocks_background
);
1110 F2FS_GENERAL_RO_ATTR(moved_blocks_foreground
);
1111 F2FS_GENERAL_RO_ATTR(avg_vblocks
);
1114 #ifdef CONFIG_FS_ENCRYPTION
1115 F2FS_FEATURE_RO_ATTR(encryption
);
1116 F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2
);
1117 #if IS_ENABLED(CONFIG_UNICODE)
1118 F2FS_FEATURE_RO_ATTR(encrypted_casefold
);
1120 #endif /* CONFIG_FS_ENCRYPTION */
1121 #ifdef CONFIG_BLK_DEV_ZONED
1122 F2FS_FEATURE_RO_ATTR(block_zoned
);
1124 F2FS_FEATURE_RO_ATTR(atomic_write
);
1125 F2FS_FEATURE_RO_ATTR(extra_attr
);
1126 F2FS_FEATURE_RO_ATTR(project_quota
);
1127 F2FS_FEATURE_RO_ATTR(inode_checksum
);
1128 F2FS_FEATURE_RO_ATTR(flexible_inline_xattr
);
1129 F2FS_FEATURE_RO_ATTR(quota_ino
);
1130 F2FS_FEATURE_RO_ATTR(inode_crtime
);
1131 F2FS_FEATURE_RO_ATTR(lost_found
);
1132 #ifdef CONFIG_FS_VERITY
1133 F2FS_FEATURE_RO_ATTR(verity
);
1135 F2FS_FEATURE_RO_ATTR(sb_checksum
);
1136 #if IS_ENABLED(CONFIG_UNICODE)
1137 F2FS_FEATURE_RO_ATTR(casefold
);
1139 F2FS_FEATURE_RO_ATTR(readonly
);
1140 #ifdef CONFIG_F2FS_FS_COMPRESSION
1141 F2FS_FEATURE_RO_ATTR(compression
);
1143 F2FS_FEATURE_RO_ATTR(pin_file
);
1145 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
1146 static struct attribute
*f2fs_attrs
[] = {
1147 ATTR_LIST(gc_urgent_sleep_time
),
1148 ATTR_LIST(gc_min_sleep_time
),
1149 ATTR_LIST(gc_max_sleep_time
),
1150 ATTR_LIST(gc_no_gc_sleep_time
),
1151 ATTR_LIST(gc_no_zoned_gc_percent
),
1152 ATTR_LIST(gc_boost_zoned_gc_percent
),
1153 ATTR_LIST(gc_valid_thresh_ratio
),
1155 ATTR_LIST(gc_urgent
),
1156 ATTR_LIST(reclaim_segments
),
1157 ATTR_LIST(main_blkaddr
),
1158 ATTR_LIST(max_small_discards
),
1159 ATTR_LIST(max_discard_request
),
1160 ATTR_LIST(min_discard_issue_time
),
1161 ATTR_LIST(mid_discard_issue_time
),
1162 ATTR_LIST(max_discard_issue_time
),
1163 ATTR_LIST(discard_io_aware_gran
),
1164 ATTR_LIST(discard_urgent_util
),
1165 ATTR_LIST(discard_granularity
),
1166 ATTR_LIST(max_ordered_discard
),
1167 ATTR_LIST(discard_io_aware
),
1168 ATTR_LIST(pending_discard
),
1170 ATTR_LIST(ipu_policy
),
1171 ATTR_LIST(min_ipu_util
),
1172 ATTR_LIST(min_fsync_blocks
),
1173 ATTR_LIST(min_seq_blocks
),
1174 ATTR_LIST(min_hot_blocks
),
1175 ATTR_LIST(min_ssr_sections
),
1176 ATTR_LIST(reserved_segments
),
1177 ATTR_LIST(max_victim_search
),
1178 ATTR_LIST(migration_granularity
),
1179 ATTR_LIST(migration_window_granularity
),
1180 ATTR_LIST(dir_level
),
1181 ATTR_LIST(ram_thresh
),
1182 ATTR_LIST(ra_nid_pages
),
1183 ATTR_LIST(dirty_nats_ratio
),
1184 ATTR_LIST(max_roll_forward_node_blocks
),
1185 ATTR_LIST(cp_interval
),
1186 ATTR_LIST(idle_interval
),
1187 ATTR_LIST(discard_idle_interval
),
1188 ATTR_LIST(gc_idle_interval
),
1189 ATTR_LIST(umount_discard_timeout
),
1190 #ifdef CONFIG_F2FS_IOSTAT
1191 ATTR_LIST(iostat_enable
),
1192 ATTR_LIST(iostat_period_ms
),
1194 ATTR_LIST(readdir_ra
),
1195 ATTR_LIST(max_io_bytes
),
1196 ATTR_LIST(gc_pin_file_thresh
),
1197 ATTR_LIST(extension_list
),
1198 #ifdef CONFIG_F2FS_FAULT_INJECTION
1199 ATTR_LIST(inject_rate
),
1200 ATTR_LIST(inject_type
),
1202 ATTR_LIST(data_io_flag
),
1203 ATTR_LIST(node_io_flag
),
1204 ATTR_LIST(gc_remaining_trials
),
1205 ATTR_LIST(ckpt_thread_ioprio
),
1206 ATTR_LIST(dirty_segments
),
1207 ATTR_LIST(free_segments
),
1208 ATTR_LIST(ovp_segments
),
1209 ATTR_LIST(unusable
),
1210 ATTR_LIST(lifetime_write_kbytes
),
1211 ATTR_LIST(features
),
1212 ATTR_LIST(reserved_blocks
),
1213 ATTR_LIST(current_reserved_blocks
),
1214 ATTR_LIST(encoding
),
1215 ATTR_LIST(mounted_time_sec
),
1216 #ifdef CONFIG_F2FS_STAT_FS
1217 ATTR_LIST(cp_foreground_calls
),
1218 ATTR_LIST(cp_background_calls
),
1219 ATTR_LIST(gc_foreground_calls
),
1220 ATTR_LIST(gc_background_calls
),
1221 ATTR_LIST(moved_blocks_foreground
),
1222 ATTR_LIST(moved_blocks_background
),
1223 ATTR_LIST(avg_vblocks
),
1225 #ifdef CONFIG_BLK_DEV_ZONED
1226 ATTR_LIST(unusable_blocks_per_sec
),
1227 ATTR_LIST(blkzone_alloc_policy
),
1229 #ifdef CONFIG_F2FS_FS_COMPRESSION
1230 ATTR_LIST(compr_written_block
),
1231 ATTR_LIST(compr_saved_block
),
1232 ATTR_LIST(compr_new_inode
),
1233 ATTR_LIST(compress_percent
),
1234 ATTR_LIST(compress_watermark
),
1237 ATTR_LIST(atgc_candidate_ratio
),
1238 ATTR_LIST(atgc_candidate_count
),
1239 ATTR_LIST(atgc_age_weight
),
1240 ATTR_LIST(atgc_age_threshold
),
1241 ATTR_LIST(atgc_enabled
),
1242 ATTR_LIST(seq_file_ra_mul
),
1243 ATTR_LIST(gc_segment_mode
),
1244 ATTR_LIST(gc_reclaimed_segments
),
1245 ATTR_LIST(max_fragment_chunk
),
1246 ATTR_LIST(max_fragment_hole
),
1247 ATTR_LIST(current_atomic_write
),
1248 ATTR_LIST(peak_atomic_write
),
1249 ATTR_LIST(committed_atomic_block
),
1250 ATTR_LIST(revoked_atomic_block
),
1251 ATTR_LIST(hot_data_age_threshold
),
1252 ATTR_LIST(warm_data_age_threshold
),
1253 ATTR_LIST(last_age_weight
),
1254 ATTR_LIST(max_read_extent_count
),
1257 ATTRIBUTE_GROUPS(f2fs
);
1259 static struct attribute
*f2fs_feat_attrs
[] = {
1260 #ifdef CONFIG_FS_ENCRYPTION
1261 ATTR_LIST(encryption
),
1262 ATTR_LIST(test_dummy_encryption_v2
),
1263 #if IS_ENABLED(CONFIG_UNICODE)
1264 ATTR_LIST(encrypted_casefold
),
1266 #endif /* CONFIG_FS_ENCRYPTION */
1267 #ifdef CONFIG_BLK_DEV_ZONED
1268 ATTR_LIST(block_zoned
),
1270 ATTR_LIST(atomic_write
),
1271 ATTR_LIST(extra_attr
),
1272 ATTR_LIST(project_quota
),
1273 ATTR_LIST(inode_checksum
),
1274 ATTR_LIST(flexible_inline_xattr
),
1275 ATTR_LIST(quota_ino
),
1276 ATTR_LIST(inode_crtime
),
1277 ATTR_LIST(lost_found
),
1278 #ifdef CONFIG_FS_VERITY
1281 ATTR_LIST(sb_checksum
),
1282 #if IS_ENABLED(CONFIG_UNICODE)
1283 ATTR_LIST(casefold
),
1285 ATTR_LIST(readonly
),
1286 #ifdef CONFIG_F2FS_FS_COMPRESSION
1287 ATTR_LIST(compression
),
1289 ATTR_LIST(pin_file
),
1292 ATTRIBUTE_GROUPS(f2fs_feat
);
1294 F2FS_GENERAL_RO_ATTR(sb_status
);
1295 F2FS_GENERAL_RO_ATTR(cp_status
);
1296 F2FS_GENERAL_RO_ATTR(issued_discard
);
1297 F2FS_GENERAL_RO_ATTR(queued_discard
);
1298 F2FS_GENERAL_RO_ATTR(undiscard_blks
);
1300 static struct attribute
*f2fs_stat_attrs
[] = {
1301 ATTR_LIST(sb_status
),
1302 ATTR_LIST(cp_status
),
1303 ATTR_LIST(issued_discard
),
1304 ATTR_LIST(queued_discard
),
1305 ATTR_LIST(undiscard_blks
),
1308 ATTRIBUTE_GROUPS(f2fs_stat
);
1310 F2FS_SB_FEATURE_RO_ATTR(encryption
, ENCRYPT
);
1311 F2FS_SB_FEATURE_RO_ATTR(block_zoned
, BLKZONED
);
1312 F2FS_SB_FEATURE_RO_ATTR(extra_attr
, EXTRA_ATTR
);
1313 F2FS_SB_FEATURE_RO_ATTR(project_quota
, PRJQUOTA
);
1314 F2FS_SB_FEATURE_RO_ATTR(inode_checksum
, INODE_CHKSUM
);
1315 F2FS_SB_FEATURE_RO_ATTR(flexible_inline_xattr
, FLEXIBLE_INLINE_XATTR
);
1316 F2FS_SB_FEATURE_RO_ATTR(quota_ino
, QUOTA_INO
);
1317 F2FS_SB_FEATURE_RO_ATTR(inode_crtime
, INODE_CRTIME
);
1318 F2FS_SB_FEATURE_RO_ATTR(lost_found
, LOST_FOUND
);
1319 F2FS_SB_FEATURE_RO_ATTR(verity
, VERITY
);
1320 F2FS_SB_FEATURE_RO_ATTR(sb_checksum
, SB_CHKSUM
);
1321 F2FS_SB_FEATURE_RO_ATTR(casefold
, CASEFOLD
);
1322 F2FS_SB_FEATURE_RO_ATTR(compression
, COMPRESSION
);
1323 F2FS_SB_FEATURE_RO_ATTR(readonly
, RO
);
1324 F2FS_SB_FEATURE_RO_ATTR(device_alias
, DEVICE_ALIAS
);
1326 static struct attribute
*f2fs_sb_feat_attrs
[] = {
1327 ATTR_LIST(sb_encryption
),
1328 ATTR_LIST(sb_block_zoned
),
1329 ATTR_LIST(sb_extra_attr
),
1330 ATTR_LIST(sb_project_quota
),
1331 ATTR_LIST(sb_inode_checksum
),
1332 ATTR_LIST(sb_flexible_inline_xattr
),
1333 ATTR_LIST(sb_quota_ino
),
1334 ATTR_LIST(sb_inode_crtime
),
1335 ATTR_LIST(sb_lost_found
),
1336 ATTR_LIST(sb_verity
),
1337 ATTR_LIST(sb_sb_checksum
),
1338 ATTR_LIST(sb_casefold
),
1339 ATTR_LIST(sb_compression
),
1340 ATTR_LIST(sb_readonly
),
1341 ATTR_LIST(sb_device_alias
),
1344 ATTRIBUTE_GROUPS(f2fs_sb_feat
);
1346 static const struct sysfs_ops f2fs_attr_ops
= {
1347 .show
= f2fs_attr_show
,
1348 .store
= f2fs_attr_store
,
1351 static const struct kobj_type f2fs_sb_ktype
= {
1352 .default_groups
= f2fs_groups
,
1353 .sysfs_ops
= &f2fs_attr_ops
,
1354 .release
= f2fs_sb_release
,
1357 static const struct kobj_type f2fs_ktype
= {
1358 .sysfs_ops
= &f2fs_attr_ops
,
1361 static struct kset f2fs_kset
= {
1362 .kobj
= {.ktype
= &f2fs_ktype
},
1365 static const struct kobj_type f2fs_feat_ktype
= {
1366 .default_groups
= f2fs_feat_groups
,
1367 .sysfs_ops
= &f2fs_attr_ops
,
1370 static struct kobject f2fs_feat
= {
1374 static ssize_t
f2fs_stat_attr_show(struct kobject
*kobj
,
1375 struct attribute
*attr
, char *buf
)
1377 struct f2fs_sb_info
*sbi
= container_of(kobj
, struct f2fs_sb_info
,
1379 struct f2fs_attr
*a
= container_of(attr
, struct f2fs_attr
, attr
);
1381 return a
->show
? a
->show(a
, sbi
, buf
) : 0;
1384 static ssize_t
f2fs_stat_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
1385 const char *buf
, size_t len
)
1387 struct f2fs_sb_info
*sbi
= container_of(kobj
, struct f2fs_sb_info
,
1389 struct f2fs_attr
*a
= container_of(attr
, struct f2fs_attr
, attr
);
1391 return a
->store
? a
->store(a
, sbi
, buf
, len
) : 0;
1394 static void f2fs_stat_kobj_release(struct kobject
*kobj
)
1396 struct f2fs_sb_info
*sbi
= container_of(kobj
, struct f2fs_sb_info
,
1398 complete(&sbi
->s_stat_kobj_unregister
);
1401 static const struct sysfs_ops f2fs_stat_attr_ops
= {
1402 .show
= f2fs_stat_attr_show
,
1403 .store
= f2fs_stat_attr_store
,
1406 static const struct kobj_type f2fs_stat_ktype
= {
1407 .default_groups
= f2fs_stat_groups
,
1408 .sysfs_ops
= &f2fs_stat_attr_ops
,
1409 .release
= f2fs_stat_kobj_release
,
1412 static ssize_t
f2fs_sb_feat_attr_show(struct kobject
*kobj
,
1413 struct attribute
*attr
, char *buf
)
1415 struct f2fs_sb_info
*sbi
= container_of(kobj
, struct f2fs_sb_info
,
1416 s_feature_list_kobj
);
1417 struct f2fs_attr
*a
= container_of(attr
, struct f2fs_attr
, attr
);
1419 return a
->show
? a
->show(a
, sbi
, buf
) : 0;
1422 static void f2fs_feature_list_kobj_release(struct kobject
*kobj
)
1424 struct f2fs_sb_info
*sbi
= container_of(kobj
, struct f2fs_sb_info
,
1425 s_feature_list_kobj
);
1426 complete(&sbi
->s_feature_list_kobj_unregister
);
1429 static const struct sysfs_ops f2fs_feature_list_attr_ops
= {
1430 .show
= f2fs_sb_feat_attr_show
,
1433 static const struct kobj_type f2fs_feature_list_ktype
= {
1434 .default_groups
= f2fs_sb_feat_groups
,
1435 .sysfs_ops
= &f2fs_feature_list_attr_ops
,
1436 .release
= f2fs_feature_list_kobj_release
,
1439 static int __maybe_unused
segment_info_seq_show(struct seq_file
*seq
,
1442 struct super_block
*sb
= seq
->private;
1443 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
1444 unsigned int total_segs
=
1445 le32_to_cpu(sbi
->raw_super
->segment_count_main
);
1448 seq_puts(seq
, "format: segment_type|valid_blocks\n"
1449 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1451 for (i
= 0; i
< total_segs
; i
++) {
1452 struct seg_entry
*se
= get_seg_entry(sbi
, i
);
1455 seq_printf(seq
, "%-10d", i
);
1456 seq_printf(seq
, "%d|%-3u", se
->type
, se
->valid_blocks
);
1457 if ((i
% 10) == 9 || i
== (total_segs
- 1))
1458 seq_putc(seq
, '\n');
1466 static int __maybe_unused
segment_bits_seq_show(struct seq_file
*seq
,
1469 struct super_block
*sb
= seq
->private;
1470 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
1471 unsigned int total_segs
=
1472 le32_to_cpu(sbi
->raw_super
->segment_count_main
);
1475 seq_puts(seq
, "format: segment_type|valid_blocks|bitmaps\n"
1476 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1478 for (i
= 0; i
< total_segs
; i
++) {
1479 struct seg_entry
*se
= get_seg_entry(sbi
, i
);
1481 seq_printf(seq
, "%-10d", i
);
1482 seq_printf(seq
, "%d|%-3u|", se
->type
, se
->valid_blocks
);
1483 for (j
= 0; j
< SIT_VBLOCK_MAP_SIZE
; j
++)
1484 seq_printf(seq
, " %.2x", se
->cur_valid_map
[j
]);
1485 seq_putc(seq
, '\n');
1490 static int __maybe_unused
victim_bits_seq_show(struct seq_file
*seq
,
1493 struct super_block
*sb
= seq
->private;
1494 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
1495 struct dirty_seglist_info
*dirty_i
= DIRTY_I(sbi
);
1498 seq_puts(seq
, "format: victim_secmap bitmaps\n");
1500 for (i
= 0; i
< MAIN_SECS(sbi
); i
++) {
1502 seq_printf(seq
, "%-10d", i
);
1503 seq_printf(seq
, "%d", test_bit(i
, dirty_i
->victim_secmap
) ? 1 : 0);
1504 if ((i
% 10) == 9 || i
== (MAIN_SECS(sbi
) - 1))
1505 seq_putc(seq
, '\n');
1512 static int __maybe_unused
discard_plist_seq_show(struct seq_file
*seq
,
1515 struct super_block
*sb
= seq
->private;
1516 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
1517 struct discard_cmd_control
*dcc
= SM_I(sbi
)->dcc_info
;
1520 seq_puts(seq
, "Discard pend list(Show diacrd_cmd count on each entry, .:not exist):\n");
1521 if (!f2fs_realtime_discard_enable(sbi
))
1525 mutex_lock(&dcc
->cmd_lock
);
1526 for (i
= 0; i
< MAX_PLIST_NUM
; i
++) {
1527 struct list_head
*pend_list
;
1528 struct discard_cmd
*dc
, *tmp
;
1531 seq_printf(seq
, " %-3d", i
);
1533 pend_list
= &dcc
->pend_list
[i
];
1534 list_for_each_entry_safe(dc
, tmp
, pend_list
, list
)
1537 seq_printf(seq
, " %7d", count
);
1539 seq_puts(seq
, " .");
1541 seq_putc(seq
, '\n');
1543 seq_putc(seq
, '\n');
1544 mutex_unlock(&dcc
->cmd_lock
);
1550 static int __maybe_unused
disk_map_seq_show(struct seq_file
*seq
,
1553 struct super_block
*sb
= seq
->private;
1554 struct f2fs_sb_info
*sbi
= F2FS_SB(sb
);
1557 seq_printf(seq
, "Address Layout : %5luB Block address (# of Segments)\n",
1559 seq_printf(seq
, " SB : %12s\n", "0/1024B");
1560 seq_printf(seq
, " seg0_blkaddr : 0x%010x\n", SEG0_BLKADDR(sbi
));
1561 seq_printf(seq
, " Checkpoint : 0x%010x (%10d)\n",
1562 le32_to_cpu(F2FS_RAW_SUPER(sbi
)->cp_blkaddr
), 2);
1563 seq_printf(seq
, " SIT : 0x%010x (%10d)\n",
1564 SIT_I(sbi
)->sit_base_addr
,
1565 le32_to_cpu(F2FS_RAW_SUPER(sbi
)->segment_count_sit
));
1566 seq_printf(seq
, " NAT : 0x%010x (%10d)\n",
1567 NM_I(sbi
)->nat_blkaddr
,
1568 le32_to_cpu(F2FS_RAW_SUPER(sbi
)->segment_count_nat
));
1569 seq_printf(seq
, " SSA : 0x%010x (%10d)\n",
1570 SM_I(sbi
)->ssa_blkaddr
,
1571 le32_to_cpu(F2FS_RAW_SUPER(sbi
)->segment_count_ssa
));
1572 seq_printf(seq
, " Main : 0x%010x (%10d)\n",
1573 SM_I(sbi
)->main_blkaddr
,
1574 le32_to_cpu(F2FS_RAW_SUPER(sbi
)->segment_count_main
));
1575 seq_printf(seq
, " # of Sections : %12d\n",
1576 le32_to_cpu(F2FS_RAW_SUPER(sbi
)->section_count
));
1577 seq_printf(seq
, " Segs/Sections : %12d\n",
1579 seq_printf(seq
, " Section size : %12d MB\n",
1580 SEGS_PER_SEC(sbi
) << 1);
1582 if (!f2fs_is_multi_device(sbi
))
1585 seq_puts(seq
, "\nDisk Map for multi devices:\n");
1586 for (i
= 0; i
< sbi
->s_ndevs
; i
++)
1587 seq_printf(seq
, "Disk:%2d (zoned=%d): 0x%010x - 0x%010x on %s\n",
1588 i
, bdev_is_zoned(FDEV(i
).bdev
),
1589 FDEV(i
).start_blk
, FDEV(i
).end_blk
,
1594 int __init
f2fs_init_sysfs(void)
1598 kobject_set_name(&f2fs_kset
.kobj
, "f2fs");
1599 f2fs_kset
.kobj
.parent
= fs_kobj
;
1600 ret
= kset_register(&f2fs_kset
);
1604 ret
= kobject_init_and_add(&f2fs_feat
, &f2fs_feat_ktype
,
1609 f2fs_proc_root
= proc_mkdir("fs/f2fs", NULL
);
1610 if (!f2fs_proc_root
) {
1617 kobject_put(&f2fs_feat
);
1618 kset_unregister(&f2fs_kset
);
1622 void f2fs_exit_sysfs(void)
1624 kobject_put(&f2fs_feat
);
1625 kset_unregister(&f2fs_kset
);
1626 remove_proc_entry("fs/f2fs", NULL
);
1627 f2fs_proc_root
= NULL
;
1630 int f2fs_register_sysfs(struct f2fs_sb_info
*sbi
)
1632 struct super_block
*sb
= sbi
->sb
;
1635 sbi
->s_kobj
.kset
= &f2fs_kset
;
1636 init_completion(&sbi
->s_kobj_unregister
);
1637 err
= kobject_init_and_add(&sbi
->s_kobj
, &f2fs_sb_ktype
, NULL
,
1642 sbi
->s_stat_kobj
.kset
= &f2fs_kset
;
1643 init_completion(&sbi
->s_stat_kobj_unregister
);
1644 err
= kobject_init_and_add(&sbi
->s_stat_kobj
, &f2fs_stat_ktype
,
1645 &sbi
->s_kobj
, "stat");
1649 sbi
->s_feature_list_kobj
.kset
= &f2fs_kset
;
1650 init_completion(&sbi
->s_feature_list_kobj_unregister
);
1651 err
= kobject_init_and_add(&sbi
->s_feature_list_kobj
,
1652 &f2fs_feature_list_ktype
,
1653 &sbi
->s_kobj
, "feature_list");
1655 goto put_feature_list_kobj
;
1657 sbi
->s_proc
= proc_mkdir(sb
->s_id
, f2fs_proc_root
);
1660 goto put_feature_list_kobj
;
1663 proc_create_single_data("segment_info", 0444, sbi
->s_proc
,
1664 segment_info_seq_show
, sb
);
1665 proc_create_single_data("segment_bits", 0444, sbi
->s_proc
,
1666 segment_bits_seq_show
, sb
);
1667 #ifdef CONFIG_F2FS_IOSTAT
1668 proc_create_single_data("iostat_info", 0444, sbi
->s_proc
,
1669 iostat_info_seq_show
, sb
);
1671 proc_create_single_data("victim_bits", 0444, sbi
->s_proc
,
1672 victim_bits_seq_show
, sb
);
1673 proc_create_single_data("discard_plist_info", 0444, sbi
->s_proc
,
1674 discard_plist_seq_show
, sb
);
1675 proc_create_single_data("disk_map", 0444, sbi
->s_proc
,
1676 disk_map_seq_show
, sb
);
1678 put_feature_list_kobj
:
1679 kobject_put(&sbi
->s_feature_list_kobj
);
1680 wait_for_completion(&sbi
->s_feature_list_kobj_unregister
);
1682 kobject_put(&sbi
->s_stat_kobj
);
1683 wait_for_completion(&sbi
->s_stat_kobj_unregister
);
1685 kobject_put(&sbi
->s_kobj
);
1686 wait_for_completion(&sbi
->s_kobj_unregister
);
1690 void f2fs_unregister_sysfs(struct f2fs_sb_info
*sbi
)
1692 remove_proc_subtree(sbi
->sb
->s_id
, f2fs_proc_root
);
1694 kobject_put(&sbi
->s_stat_kobj
);
1695 wait_for_completion(&sbi
->s_stat_kobj_unregister
);
1696 kobject_put(&sbi
->s_feature_list_kobj
);
1697 wait_for_completion(&sbi
->s_feature_list_kobj_unregister
);
1699 kobject_put(&sbi
->s_kobj
);
1700 wait_for_completion(&sbi
->s_kobj_unregister
);