1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
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 */
45 struct attribute attr;
46 ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *);
47 ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *,
48 const char *, size_t);
54 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
55 struct f2fs_sb_info *sbi, char *buf);
57 static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
59 if (struct_type == GC_THREAD)
60 return (unsigned char *)sbi->gc_thread;
61 else if (struct_type == SM_INFO)
62 return (unsigned char *)SM_I(sbi);
63 else if (struct_type == DCC_INFO)
64 return (unsigned char *)SM_I(sbi)->dcc_info;
65 else if (struct_type == NM_INFO)
66 return (unsigned char *)NM_I(sbi);
67 else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS)
68 return (unsigned char *)sbi;
69 #ifdef CONFIG_F2FS_FAULT_INJECTION
70 else if (struct_type == FAULT_INFO_RATE ||
71 struct_type == FAULT_INFO_TYPE)
72 return (unsigned char *)&F2FS_OPTION(sbi).fault_info;
74 #ifdef CONFIG_F2FS_STAT_FS
75 else if (struct_type == STAT_INFO)
76 return (unsigned char *)F2FS_STAT(sbi);
78 else if (struct_type == CPRC_INFO)
79 return (unsigned char *)&sbi->cprc_info;
80 else if (struct_type == ATGC_INFO)
81 return (unsigned char *)&sbi->am;
85 static ssize_t dirty_segments_show(struct f2fs_attr *a,
86 struct f2fs_sb_info *sbi, char *buf)
88 return sprintf(buf, "%llu\n",
89 (unsigned long long)(dirty_segments(sbi)));
92 static ssize_t free_segments_show(struct f2fs_attr *a,
93 struct f2fs_sb_info *sbi, char *buf)
95 return sprintf(buf, "%llu\n",
96 (unsigned long long)(free_segments(sbi)));
99 static ssize_t ovp_segments_show(struct f2fs_attr *a,
100 struct f2fs_sb_info *sbi, char *buf)
102 return sprintf(buf, "%llu\n",
103 (unsigned long long)(overprovision_segments(sbi)));
106 static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
107 struct f2fs_sb_info *sbi, char *buf)
109 return sprintf(buf, "%llu\n",
110 (unsigned long long)(sbi->kbytes_written +
111 ((f2fs_get_sectors_written(sbi) -
112 sbi->sectors_written_start) >> 1)));
115 static ssize_t sb_status_show(struct f2fs_attr *a,
116 struct f2fs_sb_info *sbi, char *buf)
118 return sprintf(buf, "%lx\n", sbi->s_flag);
121 static ssize_t features_show(struct f2fs_attr *a,
122 struct f2fs_sb_info *sbi, char *buf)
126 if (f2fs_sb_has_encrypt(sbi))
127 len += scnprintf(buf, PAGE_SIZE - len, "%s",
129 if (f2fs_sb_has_blkzoned(sbi))
130 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
131 len ? ", " : "", "blkzoned");
132 if (f2fs_sb_has_extra_attr(sbi))
133 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
134 len ? ", " : "", "extra_attr");
135 if (f2fs_sb_has_project_quota(sbi))
136 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
137 len ? ", " : "", "projquota");
138 if (f2fs_sb_has_inode_chksum(sbi))
139 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
140 len ? ", " : "", "inode_checksum");
141 if (f2fs_sb_has_flexible_inline_xattr(sbi))
142 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
143 len ? ", " : "", "flexible_inline_xattr");
144 if (f2fs_sb_has_quota_ino(sbi))
145 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
146 len ? ", " : "", "quota_ino");
147 if (f2fs_sb_has_inode_crtime(sbi))
148 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
149 len ? ", " : "", "inode_crtime");
150 if (f2fs_sb_has_lost_found(sbi))
151 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
152 len ? ", " : "", "lost_found");
153 if (f2fs_sb_has_verity(sbi))
154 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
155 len ? ", " : "", "verity");
156 if (f2fs_sb_has_sb_chksum(sbi))
157 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
158 len ? ", " : "", "sb_checksum");
159 if (f2fs_sb_has_casefold(sbi))
160 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
161 len ? ", " : "", "casefold");
162 if (f2fs_sb_has_readonly(sbi))
163 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
164 len ? ", " : "", "readonly");
165 if (f2fs_sb_has_compression(sbi))
166 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
167 len ? ", " : "", "compression");
168 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
169 len ? ", " : "", "pin_file");
170 len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
174 static ssize_t current_reserved_blocks_show(struct f2fs_attr *a,
175 struct f2fs_sb_info *sbi, char *buf)
177 return sprintf(buf, "%u\n", sbi->current_reserved_blocks);
180 static ssize_t unusable_show(struct f2fs_attr *a,
181 struct f2fs_sb_info *sbi, char *buf)
185 if (test_opt(sbi, DISABLE_CHECKPOINT))
186 unusable = sbi->unusable_block_count;
188 unusable = f2fs_get_unusable_blocks(sbi);
189 return sprintf(buf, "%llu\n", (unsigned long long)unusable);
192 static ssize_t encoding_show(struct f2fs_attr *a,
193 struct f2fs_sb_info *sbi, char *buf)
195 #ifdef CONFIG_UNICODE
196 struct super_block *sb = sbi->sb;
198 if (f2fs_sb_has_casefold(sbi))
199 return snprintf(buf, PAGE_SIZE, "%s (%d.%d.%d)\n",
200 sb->s_encoding->charset,
201 (sb->s_encoding->version >> 16) & 0xff,
202 (sb->s_encoding->version >> 8) & 0xff,
203 sb->s_encoding->version & 0xff);
205 return sprintf(buf, "(none)");
208 static ssize_t mounted_time_sec_show(struct f2fs_attr *a,
209 struct f2fs_sb_info *sbi, char *buf)
211 return sprintf(buf, "%llu", SIT_I(sbi)->mounted_time);
214 #ifdef CONFIG_F2FS_STAT_FS
215 static ssize_t moved_blocks_foreground_show(struct f2fs_attr *a,
216 struct f2fs_sb_info *sbi, char *buf)
218 struct f2fs_stat_info *si = F2FS_STAT(sbi);
220 return sprintf(buf, "%llu\n",
221 (unsigned long long)(si->tot_blks -
222 (si->bg_data_blks + si->bg_node_blks)));
225 static ssize_t moved_blocks_background_show(struct f2fs_attr *a,
226 struct f2fs_sb_info *sbi, char *buf)
228 struct f2fs_stat_info *si = F2FS_STAT(sbi);
230 return sprintf(buf, "%llu\n",
231 (unsigned long long)(si->bg_data_blks + si->bg_node_blks));
234 static ssize_t avg_vblocks_show(struct f2fs_attr *a,
235 struct f2fs_sb_info *sbi, char *buf)
237 struct f2fs_stat_info *si = F2FS_STAT(sbi);
239 si->dirty_count = dirty_segments(sbi);
240 f2fs_update_sit_info(sbi);
241 return sprintf(buf, "%llu\n", (unsigned long long)(si->avg_vblocks));
245 static ssize_t main_blkaddr_show(struct f2fs_attr *a,
246 struct f2fs_sb_info *sbi, char *buf)
248 return snprintf(buf, PAGE_SIZE, "%llu\n",
249 (unsigned long long)MAIN_BLKADDR(sbi));
252 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
253 struct f2fs_sb_info *sbi, char *buf)
255 unsigned char *ptr = NULL;
258 ptr = __struct_ptr(sbi, a->struct_type);
262 if (!strcmp(a->attr.name, "extension_list")) {
263 __u8 (*extlist)[F2FS_EXTENSION_LEN] =
264 sbi->raw_super->extension_list;
265 int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
266 int hot_count = sbi->raw_super->hot_ext_count;
269 len += scnprintf(buf + len, PAGE_SIZE - len,
270 "cold file extension:\n");
271 for (i = 0; i < cold_count; i++)
272 len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n",
275 len += scnprintf(buf + len, PAGE_SIZE - len,
276 "hot file extension:\n");
277 for (i = cold_count; i < cold_count + hot_count; i++)
278 len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n",
283 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
284 struct ckpt_req_control *cprc = &sbi->cprc_info;
286 int class = IOPRIO_PRIO_CLASS(cprc->ckpt_thread_ioprio);
287 int data = IOPRIO_PRIO_DATA(cprc->ckpt_thread_ioprio);
289 if (class == IOPRIO_CLASS_RT)
290 len += scnprintf(buf + len, PAGE_SIZE - len, "rt,");
291 else if (class == IOPRIO_CLASS_BE)
292 len += scnprintf(buf + len, PAGE_SIZE - len, "be,");
296 len += scnprintf(buf + len, PAGE_SIZE - len, "%d\n", data);
300 #ifdef CONFIG_F2FS_FS_COMPRESSION
301 if (!strcmp(a->attr.name, "compr_written_block"))
302 return sysfs_emit(buf, "%llu\n", sbi->compr_written_block);
304 if (!strcmp(a->attr.name, "compr_saved_block"))
305 return sysfs_emit(buf, "%llu\n", sbi->compr_saved_block);
307 if (!strcmp(a->attr.name, "compr_new_inode"))
308 return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
311 if (!strcmp(a->attr.name, "gc_segment_mode"))
312 return sysfs_emit(buf, "%u\n", sbi->gc_segment_mode);
314 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
315 return sysfs_emit(buf, "%u\n",
316 sbi->gc_reclaimed_segs[sbi->gc_segment_mode]);
319 ui = (unsigned int *)(ptr + a->offset);
321 return sprintf(buf, "%u\n", *ui);
324 static ssize_t __sbi_store(struct f2fs_attr *a,
325 struct f2fs_sb_info *sbi,
326 const char *buf, size_t count)
333 ptr = __struct_ptr(sbi, a->struct_type);
337 if (!strcmp(a->attr.name, "extension_list")) {
338 const char *name = strim((char *)buf);
339 bool set = true, hot;
341 if (!strncmp(name, "[h]", 3))
343 else if (!strncmp(name, "[c]", 3))
355 if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN)
358 down_write(&sbi->sb_lock);
360 ret = f2fs_update_extension_list(sbi, name, hot, set);
364 ret = f2fs_commit_super(sbi, false);
366 f2fs_update_extension_list(sbi, name, hot, !set);
368 up_write(&sbi->sb_lock);
369 return ret ? ret : count;
372 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
373 const char *name = strim((char *)buf);
374 struct ckpt_req_control *cprc = &sbi->cprc_info;
379 if (!strncmp(name, "rt,", 3))
380 class = IOPRIO_CLASS_RT;
381 else if (!strncmp(name, "be,", 3))
382 class = IOPRIO_CLASS_BE;
387 ret = kstrtol(name, 10, &data);
390 if (data >= IOPRIO_NR_LEVELS || data < 0)
393 cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, data);
394 if (test_opt(sbi, MERGE_CHECKPOINT)) {
395 ret = set_task_ioprio(cprc->f2fs_issue_ckpt,
396 cprc->ckpt_thread_ioprio);
404 ui = (unsigned int *)(ptr + a->offset);
406 ret = kstrtoul(skip_spaces(buf), 0, &t);
409 #ifdef CONFIG_F2FS_FAULT_INJECTION
410 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
412 if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX)
415 if (a->struct_type == RESERVED_BLOCKS) {
416 spin_lock(&sbi->stat_lock);
417 if (t > (unsigned long)(sbi->user_block_count -
418 F2FS_OPTION(sbi).root_reserved_blocks)) {
419 spin_unlock(&sbi->stat_lock);
423 sbi->current_reserved_blocks = min(sbi->reserved_blocks,
424 sbi->user_block_count - valid_user_blocks(sbi));
425 spin_unlock(&sbi->stat_lock);
429 if (!strcmp(a->attr.name, "discard_granularity")) {
430 if (t == 0 || t > MAX_PLIST_NUM)
432 if (!f2fs_block_unit_discard(sbi))
440 if (!strcmp(a->attr.name, "migration_granularity")) {
441 if (t == 0 || t > sbi->segs_per_sec)
445 if (!strcmp(a->attr.name, "trim_sections"))
448 if (!strcmp(a->attr.name, "gc_urgent")) {
450 sbi->gc_mode = GC_NORMAL;
452 sbi->gc_mode = GC_URGENT_HIGH;
453 if (sbi->gc_thread) {
454 sbi->gc_thread->gc_wake = 1;
455 wake_up_interruptible_all(
456 &sbi->gc_thread->gc_wait_queue_head);
457 wake_up_discard_thread(sbi, true);
460 sbi->gc_mode = GC_URGENT_LOW;
466 if (!strcmp(a->attr.name, "gc_idle")) {
467 if (t == GC_IDLE_CB) {
468 sbi->gc_mode = GC_IDLE_CB;
469 } else if (t == GC_IDLE_GREEDY) {
470 sbi->gc_mode = GC_IDLE_GREEDY;
471 } else if (t == GC_IDLE_AT) {
472 if (!sbi->am.atgc_enabled)
474 sbi->gc_mode = GC_AT;
476 sbi->gc_mode = GC_NORMAL;
481 #ifdef CONFIG_F2FS_IOSTAT
482 if (!strcmp(a->attr.name, "iostat_enable")) {
483 sbi->iostat_enable = !!t;
484 if (!sbi->iostat_enable)
485 f2fs_reset_iostat(sbi);
489 if (!strcmp(a->attr.name, "iostat_period_ms")) {
490 if (t < MIN_IOSTAT_PERIOD_MS || t > MAX_IOSTAT_PERIOD_MS)
492 spin_lock(&sbi->iostat_lock);
493 sbi->iostat_period_ms = (unsigned int)t;
494 spin_unlock(&sbi->iostat_lock);
499 #ifdef CONFIG_F2FS_FS_COMPRESSION
500 if (!strcmp(a->attr.name, "compr_written_block") ||
501 !strcmp(a->attr.name, "compr_saved_block")) {
504 sbi->compr_written_block = 0;
505 sbi->compr_saved_block = 0;
509 if (!strcmp(a->attr.name, "compr_new_inode")) {
512 sbi->compr_new_inode = 0;
517 if (!strcmp(a->attr.name, "atgc_candidate_ratio")) {
520 sbi->am.candidate_ratio = t;
524 if (!strcmp(a->attr.name, "atgc_age_weight")) {
527 sbi->am.age_weight = t;
531 if (!strcmp(a->attr.name, "gc_segment_mode")) {
533 sbi->gc_segment_mode = t;
539 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
542 sbi->gc_reclaimed_segs[sbi->gc_segment_mode] = 0;
546 if (!strcmp(a->attr.name, "seq_file_ra_mul")) {
547 if (t >= MIN_RA_MUL && t <= MAX_RA_MUL)
548 sbi->seq_file_ra_mul = t;
554 *ui = (unsigned int)t;
559 static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
560 struct f2fs_sb_info *sbi,
561 const char *buf, size_t count)
564 bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") ||
565 a->struct_type == GC_THREAD);
568 if (!down_read_trylock(&sbi->sb->s_umount))
571 ret = __sbi_store(a, sbi, buf, count);
573 up_read(&sbi->sb->s_umount);
578 static ssize_t f2fs_attr_show(struct kobject *kobj,
579 struct attribute *attr, char *buf)
581 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
583 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
585 return a->show ? a->show(a, sbi, buf) : 0;
588 static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
589 const char *buf, size_t len)
591 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
593 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
595 return a->store ? a->store(a, sbi, buf, len) : 0;
598 static void f2fs_sb_release(struct kobject *kobj)
600 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
602 complete(&sbi->s_kobj_unregister);
606 * Note that there are three feature list entries:
607 * 1) /sys/fs/f2fs/features
608 * : shows runtime features supported by in-kernel f2fs along with Kconfig.
609 * - ref. F2FS_FEATURE_RO_ATTR()
611 * 2) /sys/fs/f2fs/$s_id/features <deprecated>
612 * : shows on-disk features enabled by mkfs.f2fs, used for old kernels. This
613 * won't add new feature anymore, and thus, users should check entries in 3)
614 * instead of this 2).
616 * 3) /sys/fs/f2fs/$s_id/feature_list
617 * : shows on-disk features enabled by mkfs.f2fs per instance, which follows
618 * sysfs entry rule where each entry should expose single value.
619 * This list covers old feature list provided by 2) and beyond. Therefore,
620 * please add new on-disk feature in this list only.
621 * - ref. F2FS_SB_FEATURE_RO_ATTR()
623 static ssize_t f2fs_feature_show(struct f2fs_attr *a,
624 struct f2fs_sb_info *sbi, char *buf)
626 return sprintf(buf, "supported\n");
629 #define F2FS_FEATURE_RO_ATTR(_name) \
630 static struct f2fs_attr f2fs_attr_##_name = { \
631 .attr = {.name = __stringify(_name), .mode = 0444 }, \
632 .show = f2fs_feature_show, \
635 static ssize_t f2fs_sb_feature_show(struct f2fs_attr *a,
636 struct f2fs_sb_info *sbi, char *buf)
638 if (F2FS_HAS_FEATURE(sbi, a->id))
639 return sprintf(buf, "supported\n");
640 return sprintf(buf, "unsupported\n");
643 #define F2FS_SB_FEATURE_RO_ATTR(_name, _feat) \
644 static struct f2fs_attr f2fs_attr_sb_##_name = { \
645 .attr = {.name = __stringify(_name), .mode = 0444 }, \
646 .show = f2fs_sb_feature_show, \
647 .id = F2FS_FEATURE_##_feat, \
650 #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
651 static struct f2fs_attr f2fs_attr_##_name = { \
652 .attr = {.name = __stringify(_name), .mode = _mode }, \
655 .struct_type = _struct_type, \
659 #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
660 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
661 f2fs_sbi_show, f2fs_sbi_store, \
662 offsetof(struct struct_name, elname))
664 #define F2FS_GENERAL_RO_ATTR(name) \
665 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
667 #define F2FS_STAT_ATTR(_struct_type, _struct_name, _name, _elname) \
668 static struct f2fs_attr f2fs_attr_##_name = { \
669 .attr = {.name = __stringify(_name), .mode = 0444 }, \
670 .show = f2fs_sbi_show, \
671 .struct_type = _struct_type, \
672 .offset = offsetof(struct _struct_name, _elname), \
675 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time,
677 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
678 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
679 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
680 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode);
681 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode);
682 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
683 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
684 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity);
685 F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
686 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
687 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
688 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
689 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
690 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_seq_blocks, min_seq_blocks);
691 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
692 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections);
693 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
694 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
695 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
696 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
697 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, migration_granularity, migration_granularity);
698 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
699 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
700 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
701 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval,
702 interval_time[DISCARD_TIME]);
703 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]);
704 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info,
705 umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]);
706 #ifdef CONFIG_F2FS_IOSTAT
707 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
708 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_period_ms, iostat_period_ms);
710 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
711 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_io_bytes, max_io_bytes);
712 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
713 F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list);
714 #ifdef CONFIG_F2FS_FAULT_INJECTION
715 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
716 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
718 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, data_io_flag, data_io_flag);
719 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, node_io_flag, node_io_flag);
720 F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, ckpt_thread_ioprio, ckpt_thread_ioprio);
721 F2FS_GENERAL_RO_ATTR(dirty_segments);
722 F2FS_GENERAL_RO_ATTR(free_segments);
723 F2FS_GENERAL_RO_ATTR(ovp_segments);
724 F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
725 F2FS_GENERAL_RO_ATTR(features);
726 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
727 F2FS_GENERAL_RO_ATTR(unusable);
728 F2FS_GENERAL_RO_ATTR(encoding);
729 F2FS_GENERAL_RO_ATTR(mounted_time_sec);
730 F2FS_GENERAL_RO_ATTR(main_blkaddr);
731 #ifdef CONFIG_F2FS_STAT_FS
732 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count);
733 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count);
734 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_foreground_calls, call_count);
735 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_background_calls, bg_gc);
736 F2FS_GENERAL_RO_ATTR(moved_blocks_background);
737 F2FS_GENERAL_RO_ATTR(moved_blocks_foreground);
738 F2FS_GENERAL_RO_ATTR(avg_vblocks);
741 #ifdef CONFIG_FS_ENCRYPTION
742 F2FS_FEATURE_RO_ATTR(encryption);
743 F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2);
744 #ifdef CONFIG_UNICODE
745 F2FS_FEATURE_RO_ATTR(encrypted_casefold);
747 #endif /* CONFIG_FS_ENCRYPTION */
748 #ifdef CONFIG_BLK_DEV_ZONED
749 F2FS_FEATURE_RO_ATTR(block_zoned);
751 F2FS_FEATURE_RO_ATTR(atomic_write);
752 F2FS_FEATURE_RO_ATTR(extra_attr);
753 F2FS_FEATURE_RO_ATTR(project_quota);
754 F2FS_FEATURE_RO_ATTR(inode_checksum);
755 F2FS_FEATURE_RO_ATTR(flexible_inline_xattr);
756 F2FS_FEATURE_RO_ATTR(quota_ino);
757 F2FS_FEATURE_RO_ATTR(inode_crtime);
758 F2FS_FEATURE_RO_ATTR(lost_found);
759 #ifdef CONFIG_FS_VERITY
760 F2FS_FEATURE_RO_ATTR(verity);
762 F2FS_FEATURE_RO_ATTR(sb_checksum);
763 #ifdef CONFIG_UNICODE
764 F2FS_FEATURE_RO_ATTR(casefold);
766 F2FS_FEATURE_RO_ATTR(readonly);
767 #ifdef CONFIG_F2FS_FS_COMPRESSION
768 F2FS_FEATURE_RO_ATTR(compression);
769 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block);
770 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block);
771 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode);
773 F2FS_FEATURE_RO_ATTR(pin_file);
776 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio);
777 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count);
778 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
779 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
781 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, seq_file_ra_mul, seq_file_ra_mul);
782 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_segment_mode, gc_segment_mode);
783 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_reclaimed_segments, gc_reclaimed_segs);
785 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
786 static struct attribute *f2fs_attrs[] = {
787 ATTR_LIST(gc_urgent_sleep_time),
788 ATTR_LIST(gc_min_sleep_time),
789 ATTR_LIST(gc_max_sleep_time),
790 ATTR_LIST(gc_no_gc_sleep_time),
792 ATTR_LIST(gc_urgent),
793 ATTR_LIST(reclaim_segments),
794 ATTR_LIST(main_blkaddr),
795 ATTR_LIST(max_small_discards),
796 ATTR_LIST(discard_granularity),
797 ATTR_LIST(batched_trim_sections),
798 ATTR_LIST(ipu_policy),
799 ATTR_LIST(min_ipu_util),
800 ATTR_LIST(min_fsync_blocks),
801 ATTR_LIST(min_seq_blocks),
802 ATTR_LIST(min_hot_blocks),
803 ATTR_LIST(min_ssr_sections),
804 ATTR_LIST(max_victim_search),
805 ATTR_LIST(migration_granularity),
806 ATTR_LIST(dir_level),
807 ATTR_LIST(ram_thresh),
808 ATTR_LIST(ra_nid_pages),
809 ATTR_LIST(dirty_nats_ratio),
810 ATTR_LIST(cp_interval),
811 ATTR_LIST(idle_interval),
812 ATTR_LIST(discard_idle_interval),
813 ATTR_LIST(gc_idle_interval),
814 ATTR_LIST(umount_discard_timeout),
815 #ifdef CONFIG_F2FS_IOSTAT
816 ATTR_LIST(iostat_enable),
817 ATTR_LIST(iostat_period_ms),
819 ATTR_LIST(readdir_ra),
820 ATTR_LIST(max_io_bytes),
821 ATTR_LIST(gc_pin_file_thresh),
822 ATTR_LIST(extension_list),
823 #ifdef CONFIG_F2FS_FAULT_INJECTION
824 ATTR_LIST(inject_rate),
825 ATTR_LIST(inject_type),
827 ATTR_LIST(data_io_flag),
828 ATTR_LIST(node_io_flag),
829 ATTR_LIST(ckpt_thread_ioprio),
830 ATTR_LIST(dirty_segments),
831 ATTR_LIST(free_segments),
832 ATTR_LIST(ovp_segments),
834 ATTR_LIST(lifetime_write_kbytes),
836 ATTR_LIST(reserved_blocks),
837 ATTR_LIST(current_reserved_blocks),
839 ATTR_LIST(mounted_time_sec),
840 #ifdef CONFIG_F2FS_STAT_FS
841 ATTR_LIST(cp_foreground_calls),
842 ATTR_LIST(cp_background_calls),
843 ATTR_LIST(gc_foreground_calls),
844 ATTR_LIST(gc_background_calls),
845 ATTR_LIST(moved_blocks_foreground),
846 ATTR_LIST(moved_blocks_background),
847 ATTR_LIST(avg_vblocks),
849 #ifdef CONFIG_F2FS_FS_COMPRESSION
850 ATTR_LIST(compr_written_block),
851 ATTR_LIST(compr_saved_block),
852 ATTR_LIST(compr_new_inode),
855 ATTR_LIST(atgc_candidate_ratio),
856 ATTR_LIST(atgc_candidate_count),
857 ATTR_LIST(atgc_age_weight),
858 ATTR_LIST(atgc_age_threshold),
859 ATTR_LIST(seq_file_ra_mul),
860 ATTR_LIST(gc_segment_mode),
861 ATTR_LIST(gc_reclaimed_segments),
864 ATTRIBUTE_GROUPS(f2fs);
866 static struct attribute *f2fs_feat_attrs[] = {
867 #ifdef CONFIG_FS_ENCRYPTION
868 ATTR_LIST(encryption),
869 ATTR_LIST(test_dummy_encryption_v2),
870 #ifdef CONFIG_UNICODE
871 ATTR_LIST(encrypted_casefold),
873 #endif /* CONFIG_FS_ENCRYPTION */
874 #ifdef CONFIG_BLK_DEV_ZONED
875 ATTR_LIST(block_zoned),
877 ATTR_LIST(atomic_write),
878 ATTR_LIST(extra_attr),
879 ATTR_LIST(project_quota),
880 ATTR_LIST(inode_checksum),
881 ATTR_LIST(flexible_inline_xattr),
882 ATTR_LIST(quota_ino),
883 ATTR_LIST(inode_crtime),
884 ATTR_LIST(lost_found),
885 #ifdef CONFIG_FS_VERITY
888 ATTR_LIST(sb_checksum),
889 #ifdef CONFIG_UNICODE
893 #ifdef CONFIG_F2FS_FS_COMPRESSION
894 ATTR_LIST(compression),
899 ATTRIBUTE_GROUPS(f2fs_feat);
901 F2FS_GENERAL_RO_ATTR(sb_status);
902 static struct attribute *f2fs_stat_attrs[] = {
903 ATTR_LIST(sb_status),
906 ATTRIBUTE_GROUPS(f2fs_stat);
908 F2FS_SB_FEATURE_RO_ATTR(encryption, ENCRYPT);
909 F2FS_SB_FEATURE_RO_ATTR(block_zoned, BLKZONED);
910 F2FS_SB_FEATURE_RO_ATTR(extra_attr, EXTRA_ATTR);
911 F2FS_SB_FEATURE_RO_ATTR(project_quota, PRJQUOTA);
912 F2FS_SB_FEATURE_RO_ATTR(inode_checksum, INODE_CHKSUM);
913 F2FS_SB_FEATURE_RO_ATTR(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
914 F2FS_SB_FEATURE_RO_ATTR(quota_ino, QUOTA_INO);
915 F2FS_SB_FEATURE_RO_ATTR(inode_crtime, INODE_CRTIME);
916 F2FS_SB_FEATURE_RO_ATTR(lost_found, LOST_FOUND);
917 F2FS_SB_FEATURE_RO_ATTR(verity, VERITY);
918 F2FS_SB_FEATURE_RO_ATTR(sb_checksum, SB_CHKSUM);
919 F2FS_SB_FEATURE_RO_ATTR(casefold, CASEFOLD);
920 F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION);
921 F2FS_SB_FEATURE_RO_ATTR(readonly, RO);
923 static struct attribute *f2fs_sb_feat_attrs[] = {
924 ATTR_LIST(sb_encryption),
925 ATTR_LIST(sb_block_zoned),
926 ATTR_LIST(sb_extra_attr),
927 ATTR_LIST(sb_project_quota),
928 ATTR_LIST(sb_inode_checksum),
929 ATTR_LIST(sb_flexible_inline_xattr),
930 ATTR_LIST(sb_quota_ino),
931 ATTR_LIST(sb_inode_crtime),
932 ATTR_LIST(sb_lost_found),
933 ATTR_LIST(sb_verity),
934 ATTR_LIST(sb_sb_checksum),
935 ATTR_LIST(sb_casefold),
936 ATTR_LIST(sb_compression),
937 ATTR_LIST(sb_readonly),
940 ATTRIBUTE_GROUPS(f2fs_sb_feat);
942 static const struct sysfs_ops f2fs_attr_ops = {
943 .show = f2fs_attr_show,
944 .store = f2fs_attr_store,
947 static struct kobj_type f2fs_sb_ktype = {
948 .default_groups = f2fs_groups,
949 .sysfs_ops = &f2fs_attr_ops,
950 .release = f2fs_sb_release,
953 static struct kobj_type f2fs_ktype = {
954 .sysfs_ops = &f2fs_attr_ops,
957 static struct kset f2fs_kset = {
958 .kobj = {.ktype = &f2fs_ktype},
961 static struct kobj_type f2fs_feat_ktype = {
962 .default_groups = f2fs_feat_groups,
963 .sysfs_ops = &f2fs_attr_ops,
966 static struct kobject f2fs_feat = {
970 static ssize_t f2fs_stat_attr_show(struct kobject *kobj,
971 struct attribute *attr, char *buf)
973 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
975 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
977 return a->show ? a->show(a, sbi, buf) : 0;
980 static ssize_t f2fs_stat_attr_store(struct kobject *kobj, struct attribute *attr,
981 const char *buf, size_t len)
983 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
985 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
987 return a->store ? a->store(a, sbi, buf, len) : 0;
990 static void f2fs_stat_kobj_release(struct kobject *kobj)
992 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
994 complete(&sbi->s_stat_kobj_unregister);
997 static const struct sysfs_ops f2fs_stat_attr_ops = {
998 .show = f2fs_stat_attr_show,
999 .store = f2fs_stat_attr_store,
1002 static struct kobj_type f2fs_stat_ktype = {
1003 .default_groups = f2fs_stat_groups,
1004 .sysfs_ops = &f2fs_stat_attr_ops,
1005 .release = f2fs_stat_kobj_release,
1008 static ssize_t f2fs_sb_feat_attr_show(struct kobject *kobj,
1009 struct attribute *attr, char *buf)
1011 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1012 s_feature_list_kobj);
1013 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1015 return a->show ? a->show(a, sbi, buf) : 0;
1018 static void f2fs_feature_list_kobj_release(struct kobject *kobj)
1020 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1021 s_feature_list_kobj);
1022 complete(&sbi->s_feature_list_kobj_unregister);
1025 static const struct sysfs_ops f2fs_feature_list_attr_ops = {
1026 .show = f2fs_sb_feat_attr_show,
1029 static struct kobj_type f2fs_feature_list_ktype = {
1030 .default_groups = f2fs_sb_feat_groups,
1031 .sysfs_ops = &f2fs_feature_list_attr_ops,
1032 .release = f2fs_feature_list_kobj_release,
1035 static int __maybe_unused segment_info_seq_show(struct seq_file *seq,
1038 struct super_block *sb = seq->private;
1039 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1040 unsigned int total_segs =
1041 le32_to_cpu(sbi->raw_super->segment_count_main);
1044 seq_puts(seq, "format: segment_type|valid_blocks\n"
1045 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1047 for (i = 0; i < total_segs; i++) {
1048 struct seg_entry *se = get_seg_entry(sbi, i);
1051 seq_printf(seq, "%-10d", i);
1052 seq_printf(seq, "%d|%-3u", se->type, se->valid_blocks);
1053 if ((i % 10) == 9 || i == (total_segs - 1))
1054 seq_putc(seq, '\n');
1062 static int __maybe_unused segment_bits_seq_show(struct seq_file *seq,
1065 struct super_block *sb = seq->private;
1066 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1067 unsigned int total_segs =
1068 le32_to_cpu(sbi->raw_super->segment_count_main);
1071 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
1072 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1074 for (i = 0; i < total_segs; i++) {
1075 struct seg_entry *se = get_seg_entry(sbi, i);
1077 seq_printf(seq, "%-10d", i);
1078 seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks);
1079 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
1080 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
1081 seq_putc(seq, '\n');
1086 static int __maybe_unused victim_bits_seq_show(struct seq_file *seq,
1089 struct super_block *sb = seq->private;
1090 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1091 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
1094 seq_puts(seq, "format: victim_secmap bitmaps\n");
1096 for (i = 0; i < MAIN_SECS(sbi); i++) {
1098 seq_printf(seq, "%-10d", i);
1099 seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0);
1100 if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1))
1101 seq_putc(seq, '\n');
1108 int __init f2fs_init_sysfs(void)
1112 kobject_set_name(&f2fs_kset.kobj, "f2fs");
1113 f2fs_kset.kobj.parent = fs_kobj;
1114 ret = kset_register(&f2fs_kset);
1118 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
1121 kobject_put(&f2fs_feat);
1122 kset_unregister(&f2fs_kset);
1124 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
1129 void f2fs_exit_sysfs(void)
1131 kobject_put(&f2fs_feat);
1132 kset_unregister(&f2fs_kset);
1133 remove_proc_entry("fs/f2fs", NULL);
1134 f2fs_proc_root = NULL;
1137 int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
1139 struct super_block *sb = sbi->sb;
1142 sbi->s_kobj.kset = &f2fs_kset;
1143 init_completion(&sbi->s_kobj_unregister);
1144 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
1149 sbi->s_stat_kobj.kset = &f2fs_kset;
1150 init_completion(&sbi->s_stat_kobj_unregister);
1151 err = kobject_init_and_add(&sbi->s_stat_kobj, &f2fs_stat_ktype,
1152 &sbi->s_kobj, "stat");
1156 sbi->s_feature_list_kobj.kset = &f2fs_kset;
1157 init_completion(&sbi->s_feature_list_kobj_unregister);
1158 err = kobject_init_and_add(&sbi->s_feature_list_kobj,
1159 &f2fs_feature_list_ktype,
1160 &sbi->s_kobj, "feature_list");
1162 goto put_feature_list_kobj;
1165 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
1168 proc_create_single_data("segment_info", 0444, sbi->s_proc,
1169 segment_info_seq_show, sb);
1170 proc_create_single_data("segment_bits", 0444, sbi->s_proc,
1171 segment_bits_seq_show, sb);
1172 #ifdef CONFIG_F2FS_IOSTAT
1173 proc_create_single_data("iostat_info", 0444, sbi->s_proc,
1174 iostat_info_seq_show, sb);
1176 proc_create_single_data("victim_bits", 0444, sbi->s_proc,
1177 victim_bits_seq_show, sb);
1180 put_feature_list_kobj:
1181 kobject_put(&sbi->s_feature_list_kobj);
1182 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1184 kobject_put(&sbi->s_stat_kobj);
1185 wait_for_completion(&sbi->s_stat_kobj_unregister);
1187 kobject_put(&sbi->s_kobj);
1188 wait_for_completion(&sbi->s_kobj_unregister);
1192 void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
1195 #ifdef CONFIG_F2FS_IOSTAT
1196 remove_proc_entry("iostat_info", sbi->s_proc);
1198 remove_proc_entry("segment_info", sbi->s_proc);
1199 remove_proc_entry("segment_bits", sbi->s_proc);
1200 remove_proc_entry("victim_bits", sbi->s_proc);
1201 remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
1204 kobject_del(&sbi->s_stat_kobj);
1205 kobject_put(&sbi->s_stat_kobj);
1206 wait_for_completion(&sbi->s_stat_kobj_unregister);
1207 kobject_del(&sbi->s_feature_list_kobj);
1208 kobject_put(&sbi->s_feature_list_kobj);
1209 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1211 kobject_del(&sbi->s_kobj);
1212 kobject_put(&sbi->s_kobj);
1213 wait_for_completion(&sbi->s_kobj_unregister);