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 */
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 gc_mode_show(struct f2fs_attr *a,
147 struct f2fs_sb_info *sbi, char *buf)
149 return sysfs_emit(buf, "%s\n", gc_mode_names[sbi->gc_mode]);
152 static ssize_t features_show(struct f2fs_attr *a,
153 struct f2fs_sb_info *sbi, char *buf)
157 if (f2fs_sb_has_encrypt(sbi))
158 len += scnprintf(buf, PAGE_SIZE - len, "%s",
160 if (f2fs_sb_has_blkzoned(sbi))
161 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
162 len ? ", " : "", "blkzoned");
163 if (f2fs_sb_has_extra_attr(sbi))
164 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
165 len ? ", " : "", "extra_attr");
166 if (f2fs_sb_has_project_quota(sbi))
167 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
168 len ? ", " : "", "projquota");
169 if (f2fs_sb_has_inode_chksum(sbi))
170 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
171 len ? ", " : "", "inode_checksum");
172 if (f2fs_sb_has_flexible_inline_xattr(sbi))
173 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
174 len ? ", " : "", "flexible_inline_xattr");
175 if (f2fs_sb_has_quota_ino(sbi))
176 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
177 len ? ", " : "", "quota_ino");
178 if (f2fs_sb_has_inode_crtime(sbi))
179 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
180 len ? ", " : "", "inode_crtime");
181 if (f2fs_sb_has_lost_found(sbi))
182 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
183 len ? ", " : "", "lost_found");
184 if (f2fs_sb_has_verity(sbi))
185 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
186 len ? ", " : "", "verity");
187 if (f2fs_sb_has_sb_chksum(sbi))
188 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
189 len ? ", " : "", "sb_checksum");
190 if (f2fs_sb_has_casefold(sbi))
191 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
192 len ? ", " : "", "casefold");
193 if (f2fs_sb_has_readonly(sbi))
194 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
195 len ? ", " : "", "readonly");
196 if (f2fs_sb_has_compression(sbi))
197 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
198 len ? ", " : "", "compression");
199 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
200 len ? ", " : "", "pin_file");
201 len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
205 static ssize_t current_reserved_blocks_show(struct f2fs_attr *a,
206 struct f2fs_sb_info *sbi, char *buf)
208 return sysfs_emit(buf, "%u\n", sbi->current_reserved_blocks);
211 static ssize_t unusable_show(struct f2fs_attr *a,
212 struct f2fs_sb_info *sbi, char *buf)
216 if (test_opt(sbi, DISABLE_CHECKPOINT))
217 unusable = sbi->unusable_block_count;
219 unusable = f2fs_get_unusable_blocks(sbi);
220 return sysfs_emit(buf, "%llu\n", (unsigned long long)unusable);
223 static ssize_t encoding_show(struct f2fs_attr *a,
224 struct f2fs_sb_info *sbi, char *buf)
226 #if IS_ENABLED(CONFIG_UNICODE)
227 struct super_block *sb = sbi->sb;
229 if (f2fs_sb_has_casefold(sbi))
230 return sysfs_emit(buf, "UTF-8 (%d.%d.%d)\n",
231 (sb->s_encoding->version >> 16) & 0xff,
232 (sb->s_encoding->version >> 8) & 0xff,
233 sb->s_encoding->version & 0xff);
235 return sysfs_emit(buf, "(none)\n");
238 static ssize_t mounted_time_sec_show(struct f2fs_attr *a,
239 struct f2fs_sb_info *sbi, char *buf)
241 return sysfs_emit(buf, "%llu\n", SIT_I(sbi)->mounted_time);
244 #ifdef CONFIG_F2FS_STAT_FS
245 static ssize_t moved_blocks_foreground_show(struct f2fs_attr *a,
246 struct f2fs_sb_info *sbi, char *buf)
248 struct f2fs_stat_info *si = F2FS_STAT(sbi);
250 return sysfs_emit(buf, "%llu\n",
251 (unsigned long long)(si->tot_blks -
252 (si->bg_data_blks + si->bg_node_blks)));
255 static ssize_t moved_blocks_background_show(struct f2fs_attr *a,
256 struct f2fs_sb_info *sbi, char *buf)
258 struct f2fs_stat_info *si = F2FS_STAT(sbi);
260 return sysfs_emit(buf, "%llu\n",
261 (unsigned long long)(si->bg_data_blks + si->bg_node_blks));
264 static ssize_t avg_vblocks_show(struct f2fs_attr *a,
265 struct f2fs_sb_info *sbi, char *buf)
267 struct f2fs_stat_info *si = F2FS_STAT(sbi);
269 si->dirty_count = dirty_segments(sbi);
270 f2fs_update_sit_info(sbi);
271 return sysfs_emit(buf, "%llu\n", (unsigned long long)(si->avg_vblocks));
275 static ssize_t main_blkaddr_show(struct f2fs_attr *a,
276 struct f2fs_sb_info *sbi, char *buf)
278 return sysfs_emit(buf, "%llu\n",
279 (unsigned long long)MAIN_BLKADDR(sbi));
282 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
283 struct f2fs_sb_info *sbi, char *buf)
285 unsigned char *ptr = NULL;
288 ptr = __struct_ptr(sbi, a->struct_type);
292 if (!strcmp(a->attr.name, "extension_list")) {
293 __u8 (*extlist)[F2FS_EXTENSION_LEN] =
294 sbi->raw_super->extension_list;
295 int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
296 int hot_count = sbi->raw_super->hot_ext_count;
299 len += scnprintf(buf + len, PAGE_SIZE - len,
300 "cold file extension:\n");
301 for (i = 0; i < cold_count; i++)
302 len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n",
305 len += scnprintf(buf + len, PAGE_SIZE - len,
306 "hot file extension:\n");
307 for (i = cold_count; i < cold_count + hot_count; i++)
308 len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n",
313 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
314 struct ckpt_req_control *cprc = &sbi->cprc_info;
316 int class = IOPRIO_PRIO_CLASS(cprc->ckpt_thread_ioprio);
317 int data = IOPRIO_PRIO_DATA(cprc->ckpt_thread_ioprio);
319 if (class == IOPRIO_CLASS_RT)
320 len += scnprintf(buf + len, PAGE_SIZE - len, "rt,");
321 else if (class == IOPRIO_CLASS_BE)
322 len += scnprintf(buf + len, PAGE_SIZE - len, "be,");
326 len += scnprintf(buf + len, PAGE_SIZE - len, "%d\n", data);
330 #ifdef CONFIG_F2FS_FS_COMPRESSION
331 if (!strcmp(a->attr.name, "compr_written_block"))
332 return sysfs_emit(buf, "%llu\n", sbi->compr_written_block);
334 if (!strcmp(a->attr.name, "compr_saved_block"))
335 return sysfs_emit(buf, "%llu\n", sbi->compr_saved_block);
337 if (!strcmp(a->attr.name, "compr_new_inode"))
338 return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
341 if (!strcmp(a->attr.name, "gc_segment_mode"))
342 return sysfs_emit(buf, "%u\n", sbi->gc_segment_mode);
344 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
345 return sysfs_emit(buf, "%u\n",
346 sbi->gc_reclaimed_segs[sbi->gc_segment_mode]);
349 if (!strcmp(a->attr.name, "current_atomic_write")) {
350 s64 current_write = atomic64_read(&sbi->current_atomic_write);
352 return sysfs_emit(buf, "%lld\n", current_write);
355 if (!strcmp(a->attr.name, "peak_atomic_write"))
356 return sysfs_emit(buf, "%lld\n", sbi->peak_atomic_write);
358 if (!strcmp(a->attr.name, "committed_atomic_block"))
359 return sysfs_emit(buf, "%llu\n", sbi->committed_atomic_block);
361 if (!strcmp(a->attr.name, "revoked_atomic_block"))
362 return sysfs_emit(buf, "%llu\n", sbi->revoked_atomic_block);
364 ui = (unsigned int *)(ptr + a->offset);
366 return sysfs_emit(buf, "%u\n", *ui);
369 static ssize_t __sbi_store(struct f2fs_attr *a,
370 struct f2fs_sb_info *sbi,
371 const char *buf, size_t count)
378 ptr = __struct_ptr(sbi, a->struct_type);
382 if (!strcmp(a->attr.name, "extension_list")) {
383 const char *name = strim((char *)buf);
384 bool set = true, hot;
386 if (!strncmp(name, "[h]", 3))
388 else if (!strncmp(name, "[c]", 3))
400 if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN)
403 f2fs_down_write(&sbi->sb_lock);
405 ret = f2fs_update_extension_list(sbi, name, hot, set);
409 ret = f2fs_commit_super(sbi, false);
411 f2fs_update_extension_list(sbi, name, hot, !set);
413 f2fs_up_write(&sbi->sb_lock);
414 return ret ? ret : count;
417 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
418 const char *name = strim((char *)buf);
419 struct ckpt_req_control *cprc = &sbi->cprc_info;
424 if (!strncmp(name, "rt,", 3))
425 class = IOPRIO_CLASS_RT;
426 else if (!strncmp(name, "be,", 3))
427 class = IOPRIO_CLASS_BE;
432 ret = kstrtol(name, 10, &data);
435 if (data >= IOPRIO_NR_LEVELS || data < 0)
438 cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, data);
439 if (test_opt(sbi, MERGE_CHECKPOINT)) {
440 ret = set_task_ioprio(cprc->f2fs_issue_ckpt,
441 cprc->ckpt_thread_ioprio);
449 ui = (unsigned int *)(ptr + a->offset);
451 ret = kstrtoul(skip_spaces(buf), 0, &t);
454 #ifdef CONFIG_F2FS_FAULT_INJECTION
455 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
457 if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX)
460 if (a->struct_type == RESERVED_BLOCKS) {
461 spin_lock(&sbi->stat_lock);
462 if (t > (unsigned long)(sbi->user_block_count -
463 F2FS_OPTION(sbi).root_reserved_blocks -
464 sbi->blocks_per_seg *
465 SM_I(sbi)->additional_reserved_segments)) {
466 spin_unlock(&sbi->stat_lock);
470 sbi->current_reserved_blocks = min(sbi->reserved_blocks,
471 sbi->user_block_count - valid_user_blocks(sbi));
472 spin_unlock(&sbi->stat_lock);
476 if (!strcmp(a->attr.name, "discard_granularity")) {
477 if (t == 0 || t > MAX_PLIST_NUM)
479 if (!f2fs_block_unit_discard(sbi))
487 if (!strcmp(a->attr.name, "max_ordered_discard")) {
488 if (t == 0 || t > MAX_PLIST_NUM)
490 if (!f2fs_block_unit_discard(sbi))
496 if (!strcmp(a->attr.name, "discard_urgent_util")) {
503 if (!strcmp(a->attr.name, "migration_granularity")) {
504 if (t == 0 || t > sbi->segs_per_sec)
508 if (!strcmp(a->attr.name, "gc_urgent")) {
510 sbi->gc_mode = GC_NORMAL;
512 sbi->gc_mode = GC_URGENT_HIGH;
513 if (sbi->gc_thread) {
514 sbi->gc_thread->gc_wake = 1;
515 wake_up_interruptible_all(
516 &sbi->gc_thread->gc_wait_queue_head);
517 wake_up_discard_thread(sbi, true);
520 sbi->gc_mode = GC_URGENT_LOW;
522 sbi->gc_mode = GC_URGENT_MID;
523 if (sbi->gc_thread) {
524 sbi->gc_thread->gc_wake = 1;
525 wake_up_interruptible_all(
526 &sbi->gc_thread->gc_wait_queue_head);
533 if (!strcmp(a->attr.name, "gc_idle")) {
534 if (t == GC_IDLE_CB) {
535 sbi->gc_mode = GC_IDLE_CB;
536 } else if (t == GC_IDLE_GREEDY) {
537 sbi->gc_mode = GC_IDLE_GREEDY;
538 } else if (t == GC_IDLE_AT) {
539 if (!sbi->am.atgc_enabled)
541 sbi->gc_mode = GC_IDLE_AT;
543 sbi->gc_mode = GC_NORMAL;
548 if (!strcmp(a->attr.name, "gc_remaining_trials")) {
549 spin_lock(&sbi->gc_remaining_trials_lock);
550 sbi->gc_remaining_trials = t;
551 spin_unlock(&sbi->gc_remaining_trials_lock);
556 #ifdef CONFIG_F2FS_IOSTAT
557 if (!strcmp(a->attr.name, "iostat_enable")) {
558 sbi->iostat_enable = !!t;
559 if (!sbi->iostat_enable)
560 f2fs_reset_iostat(sbi);
564 if (!strcmp(a->attr.name, "iostat_period_ms")) {
565 if (t < MIN_IOSTAT_PERIOD_MS || t > MAX_IOSTAT_PERIOD_MS)
567 spin_lock(&sbi->iostat_lock);
568 sbi->iostat_period_ms = (unsigned int)t;
569 spin_unlock(&sbi->iostat_lock);
574 #ifdef CONFIG_F2FS_FS_COMPRESSION
575 if (!strcmp(a->attr.name, "compr_written_block") ||
576 !strcmp(a->attr.name, "compr_saved_block")) {
579 sbi->compr_written_block = 0;
580 sbi->compr_saved_block = 0;
584 if (!strcmp(a->attr.name, "compr_new_inode")) {
587 sbi->compr_new_inode = 0;
592 if (!strcmp(a->attr.name, "atgc_candidate_ratio")) {
595 sbi->am.candidate_ratio = t;
599 if (!strcmp(a->attr.name, "atgc_age_weight")) {
602 sbi->am.age_weight = t;
606 if (!strcmp(a->attr.name, "gc_segment_mode")) {
608 sbi->gc_segment_mode = t;
614 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
617 sbi->gc_reclaimed_segs[sbi->gc_segment_mode] = 0;
621 if (!strcmp(a->attr.name, "seq_file_ra_mul")) {
622 if (t >= MIN_RA_MUL && t <= MAX_RA_MUL)
623 sbi->seq_file_ra_mul = t;
629 if (!strcmp(a->attr.name, "max_fragment_chunk")) {
630 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE)
631 sbi->max_fragment_chunk = t;
637 if (!strcmp(a->attr.name, "max_fragment_hole")) {
638 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE)
639 sbi->max_fragment_hole = t;
645 if (!strcmp(a->attr.name, "peak_atomic_write")) {
648 sbi->peak_atomic_write = 0;
652 if (!strcmp(a->attr.name, "committed_atomic_block")) {
655 sbi->committed_atomic_block = 0;
659 if (!strcmp(a->attr.name, "revoked_atomic_block")) {
662 sbi->revoked_atomic_block = 0;
666 if (!strcmp(a->attr.name, "readdir_ra")) {
667 sbi->readdir_ra = !!t;
671 if (!strcmp(a->attr.name, "hot_data_age_threshold")) {
672 if (t == 0 || t >= sbi->warm_data_age_threshold)
676 *ui = (unsigned int)t;
680 if (!strcmp(a->attr.name, "warm_data_age_threshold")) {
681 if (t == 0 || t <= sbi->hot_data_age_threshold)
685 *ui = (unsigned int)t;
689 *ui = (unsigned int)t;
694 static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
695 struct f2fs_sb_info *sbi,
696 const char *buf, size_t count)
699 bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") ||
700 a->struct_type == GC_THREAD);
703 if (!down_read_trylock(&sbi->sb->s_umount))
706 ret = __sbi_store(a, sbi, buf, count);
708 up_read(&sbi->sb->s_umount);
713 static ssize_t f2fs_attr_show(struct kobject *kobj,
714 struct attribute *attr, char *buf)
716 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
718 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
720 return a->show ? a->show(a, sbi, buf) : 0;
723 static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
724 const char *buf, size_t len)
726 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
728 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
730 return a->store ? a->store(a, sbi, buf, len) : 0;
733 static void f2fs_sb_release(struct kobject *kobj)
735 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
737 complete(&sbi->s_kobj_unregister);
741 * Note that there are three feature list entries:
742 * 1) /sys/fs/f2fs/features
743 * : shows runtime features supported by in-kernel f2fs along with Kconfig.
744 * - ref. F2FS_FEATURE_RO_ATTR()
746 * 2) /sys/fs/f2fs/$s_id/features <deprecated>
747 * : shows on-disk features enabled by mkfs.f2fs, used for old kernels. This
748 * won't add new feature anymore, and thus, users should check entries in 3)
749 * instead of this 2).
751 * 3) /sys/fs/f2fs/$s_id/feature_list
752 * : shows on-disk features enabled by mkfs.f2fs per instance, which follows
753 * sysfs entry rule where each entry should expose single value.
754 * This list covers old feature list provided by 2) and beyond. Therefore,
755 * please add new on-disk feature in this list only.
756 * - ref. F2FS_SB_FEATURE_RO_ATTR()
758 static ssize_t f2fs_feature_show(struct f2fs_attr *a,
759 struct f2fs_sb_info *sbi, char *buf)
761 return sysfs_emit(buf, "supported\n");
764 #define F2FS_FEATURE_RO_ATTR(_name) \
765 static struct f2fs_attr f2fs_attr_##_name = { \
766 .attr = {.name = __stringify(_name), .mode = 0444 }, \
767 .show = f2fs_feature_show, \
770 static ssize_t f2fs_sb_feature_show(struct f2fs_attr *a,
771 struct f2fs_sb_info *sbi, char *buf)
773 if (F2FS_HAS_FEATURE(sbi, a->id))
774 return sysfs_emit(buf, "supported\n");
775 return sysfs_emit(buf, "unsupported\n");
778 #define F2FS_SB_FEATURE_RO_ATTR(_name, _feat) \
779 static struct f2fs_attr f2fs_attr_sb_##_name = { \
780 .attr = {.name = __stringify(_name), .mode = 0444 }, \
781 .show = f2fs_sb_feature_show, \
782 .id = F2FS_FEATURE_##_feat, \
785 #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
786 static struct f2fs_attr f2fs_attr_##_name = { \
787 .attr = {.name = __stringify(_name), .mode = _mode }, \
790 .struct_type = _struct_type, \
794 #define F2FS_RO_ATTR(struct_type, struct_name, name, elname) \
795 F2FS_ATTR_OFFSET(struct_type, name, 0444, \
796 f2fs_sbi_show, NULL, \
797 offsetof(struct struct_name, elname))
799 #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
800 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
801 f2fs_sbi_show, f2fs_sbi_store, \
802 offsetof(struct struct_name, elname))
804 #define F2FS_GENERAL_RO_ATTR(name) \
805 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
807 #define F2FS_STAT_ATTR(_struct_type, _struct_name, _name, _elname) \
808 static struct f2fs_attr f2fs_attr_##_name = { \
809 .attr = {.name = __stringify(_name), .mode = 0444 }, \
810 .show = f2fs_sbi_show, \
811 .struct_type = _struct_type, \
812 .offset = offsetof(struct _struct_name, _elname), \
815 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time,
817 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
818 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
819 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
820 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode);
821 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode);
822 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
823 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
824 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_request, max_discard_request);
825 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, min_discard_issue_time, min_discard_issue_time);
826 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, mid_discard_issue_time, mid_discard_issue_time);
827 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_issue_time, max_discard_issue_time);
828 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_urgent_util, discard_urgent_util);
829 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity);
830 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_ordered_discard, max_ordered_discard);
831 F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
832 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
833 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
834 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
835 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_seq_blocks, min_seq_blocks);
836 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
837 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections);
838 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
839 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
840 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
841 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, max_roll_forward_node_blocks, max_rf_node_blocks);
842 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
843 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, migration_granularity, migration_granularity);
844 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
845 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
846 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
847 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval,
848 interval_time[DISCARD_TIME]);
849 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]);
850 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info,
851 umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]);
852 #ifdef CONFIG_F2FS_IOSTAT
853 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
854 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_period_ms, iostat_period_ms);
856 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
857 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_io_bytes, max_io_bytes);
858 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
859 F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list);
860 #ifdef CONFIG_F2FS_FAULT_INJECTION
861 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
862 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
864 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, data_io_flag, data_io_flag);
865 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, node_io_flag, node_io_flag);
866 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_remaining_trials, gc_remaining_trials);
867 F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, ckpt_thread_ioprio, ckpt_thread_ioprio);
868 F2FS_GENERAL_RO_ATTR(dirty_segments);
869 F2FS_GENERAL_RO_ATTR(free_segments);
870 F2FS_GENERAL_RO_ATTR(ovp_segments);
871 F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
872 F2FS_GENERAL_RO_ATTR(features);
873 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
874 F2FS_GENERAL_RO_ATTR(unusable);
875 F2FS_GENERAL_RO_ATTR(encoding);
876 F2FS_GENERAL_RO_ATTR(mounted_time_sec);
877 F2FS_GENERAL_RO_ATTR(main_blkaddr);
878 F2FS_GENERAL_RO_ATTR(pending_discard);
879 F2FS_GENERAL_RO_ATTR(gc_mode);
880 #ifdef CONFIG_F2FS_STAT_FS
881 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count);
882 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count);
883 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_foreground_calls, call_count);
884 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_background_calls, bg_gc);
885 F2FS_GENERAL_RO_ATTR(moved_blocks_background);
886 F2FS_GENERAL_RO_ATTR(moved_blocks_foreground);
887 F2FS_GENERAL_RO_ATTR(avg_vblocks);
890 #ifdef CONFIG_FS_ENCRYPTION
891 F2FS_FEATURE_RO_ATTR(encryption);
892 F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2);
893 #if IS_ENABLED(CONFIG_UNICODE)
894 F2FS_FEATURE_RO_ATTR(encrypted_casefold);
896 #endif /* CONFIG_FS_ENCRYPTION */
897 #ifdef CONFIG_BLK_DEV_ZONED
898 F2FS_FEATURE_RO_ATTR(block_zoned);
899 F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, unusable_blocks_per_sec,
900 unusable_blocks_per_sec);
902 F2FS_FEATURE_RO_ATTR(atomic_write);
903 F2FS_FEATURE_RO_ATTR(extra_attr);
904 F2FS_FEATURE_RO_ATTR(project_quota);
905 F2FS_FEATURE_RO_ATTR(inode_checksum);
906 F2FS_FEATURE_RO_ATTR(flexible_inline_xattr);
907 F2FS_FEATURE_RO_ATTR(quota_ino);
908 F2FS_FEATURE_RO_ATTR(inode_crtime);
909 F2FS_FEATURE_RO_ATTR(lost_found);
910 #ifdef CONFIG_FS_VERITY
911 F2FS_FEATURE_RO_ATTR(verity);
913 F2FS_FEATURE_RO_ATTR(sb_checksum);
914 #if IS_ENABLED(CONFIG_UNICODE)
915 F2FS_FEATURE_RO_ATTR(casefold);
917 F2FS_FEATURE_RO_ATTR(readonly);
918 #ifdef CONFIG_F2FS_FS_COMPRESSION
919 F2FS_FEATURE_RO_ATTR(compression);
920 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block);
921 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block);
922 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode);
924 F2FS_FEATURE_RO_ATTR(pin_file);
927 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio);
928 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count);
929 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
930 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
932 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, seq_file_ra_mul, seq_file_ra_mul);
933 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_segment_mode, gc_segment_mode);
934 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_reclaimed_segments, gc_reclaimed_segs);
935 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_chunk, max_fragment_chunk);
936 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_hole, max_fragment_hole);
938 /* For atomic write */
939 F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, current_atomic_write, current_atomic_write);
940 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, peak_atomic_write, peak_atomic_write);
941 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, committed_atomic_block, committed_atomic_block);
942 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block);
944 /* For block age extent cache */
945 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold);
946 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold);
948 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
949 static struct attribute *f2fs_attrs[] = {
950 ATTR_LIST(gc_urgent_sleep_time),
951 ATTR_LIST(gc_min_sleep_time),
952 ATTR_LIST(gc_max_sleep_time),
953 ATTR_LIST(gc_no_gc_sleep_time),
955 ATTR_LIST(gc_urgent),
956 ATTR_LIST(reclaim_segments),
957 ATTR_LIST(main_blkaddr),
958 ATTR_LIST(max_small_discards),
959 ATTR_LIST(max_discard_request),
960 ATTR_LIST(min_discard_issue_time),
961 ATTR_LIST(mid_discard_issue_time),
962 ATTR_LIST(max_discard_issue_time),
963 ATTR_LIST(discard_urgent_util),
964 ATTR_LIST(discard_granularity),
965 ATTR_LIST(max_ordered_discard),
966 ATTR_LIST(pending_discard),
968 ATTR_LIST(ipu_policy),
969 ATTR_LIST(min_ipu_util),
970 ATTR_LIST(min_fsync_blocks),
971 ATTR_LIST(min_seq_blocks),
972 ATTR_LIST(min_hot_blocks),
973 ATTR_LIST(min_ssr_sections),
974 ATTR_LIST(max_victim_search),
975 ATTR_LIST(migration_granularity),
976 ATTR_LIST(dir_level),
977 ATTR_LIST(ram_thresh),
978 ATTR_LIST(ra_nid_pages),
979 ATTR_LIST(dirty_nats_ratio),
980 ATTR_LIST(max_roll_forward_node_blocks),
981 ATTR_LIST(cp_interval),
982 ATTR_LIST(idle_interval),
983 ATTR_LIST(discard_idle_interval),
984 ATTR_LIST(gc_idle_interval),
985 ATTR_LIST(umount_discard_timeout),
986 #ifdef CONFIG_F2FS_IOSTAT
987 ATTR_LIST(iostat_enable),
988 ATTR_LIST(iostat_period_ms),
990 ATTR_LIST(readdir_ra),
991 ATTR_LIST(max_io_bytes),
992 ATTR_LIST(gc_pin_file_thresh),
993 ATTR_LIST(extension_list),
994 #ifdef CONFIG_F2FS_FAULT_INJECTION
995 ATTR_LIST(inject_rate),
996 ATTR_LIST(inject_type),
998 ATTR_LIST(data_io_flag),
999 ATTR_LIST(node_io_flag),
1000 ATTR_LIST(gc_remaining_trials),
1001 ATTR_LIST(ckpt_thread_ioprio),
1002 ATTR_LIST(dirty_segments),
1003 ATTR_LIST(free_segments),
1004 ATTR_LIST(ovp_segments),
1005 ATTR_LIST(unusable),
1006 ATTR_LIST(lifetime_write_kbytes),
1007 ATTR_LIST(features),
1008 ATTR_LIST(reserved_blocks),
1009 ATTR_LIST(current_reserved_blocks),
1010 ATTR_LIST(encoding),
1011 ATTR_LIST(mounted_time_sec),
1012 #ifdef CONFIG_F2FS_STAT_FS
1013 ATTR_LIST(cp_foreground_calls),
1014 ATTR_LIST(cp_background_calls),
1015 ATTR_LIST(gc_foreground_calls),
1016 ATTR_LIST(gc_background_calls),
1017 ATTR_LIST(moved_blocks_foreground),
1018 ATTR_LIST(moved_blocks_background),
1019 ATTR_LIST(avg_vblocks),
1021 #ifdef CONFIG_BLK_DEV_ZONED
1022 ATTR_LIST(unusable_blocks_per_sec),
1024 #ifdef CONFIG_F2FS_FS_COMPRESSION
1025 ATTR_LIST(compr_written_block),
1026 ATTR_LIST(compr_saved_block),
1027 ATTR_LIST(compr_new_inode),
1030 ATTR_LIST(atgc_candidate_ratio),
1031 ATTR_LIST(atgc_candidate_count),
1032 ATTR_LIST(atgc_age_weight),
1033 ATTR_LIST(atgc_age_threshold),
1034 ATTR_LIST(seq_file_ra_mul),
1035 ATTR_LIST(gc_segment_mode),
1036 ATTR_LIST(gc_reclaimed_segments),
1037 ATTR_LIST(max_fragment_chunk),
1038 ATTR_LIST(max_fragment_hole),
1039 ATTR_LIST(current_atomic_write),
1040 ATTR_LIST(peak_atomic_write),
1041 ATTR_LIST(committed_atomic_block),
1042 ATTR_LIST(revoked_atomic_block),
1043 ATTR_LIST(hot_data_age_threshold),
1044 ATTR_LIST(warm_data_age_threshold),
1047 ATTRIBUTE_GROUPS(f2fs);
1049 static struct attribute *f2fs_feat_attrs[] = {
1050 #ifdef CONFIG_FS_ENCRYPTION
1051 ATTR_LIST(encryption),
1052 ATTR_LIST(test_dummy_encryption_v2),
1053 #if IS_ENABLED(CONFIG_UNICODE)
1054 ATTR_LIST(encrypted_casefold),
1056 #endif /* CONFIG_FS_ENCRYPTION */
1057 #ifdef CONFIG_BLK_DEV_ZONED
1058 ATTR_LIST(block_zoned),
1060 ATTR_LIST(atomic_write),
1061 ATTR_LIST(extra_attr),
1062 ATTR_LIST(project_quota),
1063 ATTR_LIST(inode_checksum),
1064 ATTR_LIST(flexible_inline_xattr),
1065 ATTR_LIST(quota_ino),
1066 ATTR_LIST(inode_crtime),
1067 ATTR_LIST(lost_found),
1068 #ifdef CONFIG_FS_VERITY
1071 ATTR_LIST(sb_checksum),
1072 #if IS_ENABLED(CONFIG_UNICODE)
1073 ATTR_LIST(casefold),
1075 ATTR_LIST(readonly),
1076 #ifdef CONFIG_F2FS_FS_COMPRESSION
1077 ATTR_LIST(compression),
1079 ATTR_LIST(pin_file),
1082 ATTRIBUTE_GROUPS(f2fs_feat);
1084 F2FS_GENERAL_RO_ATTR(sb_status);
1085 F2FS_GENERAL_RO_ATTR(cp_status);
1086 static struct attribute *f2fs_stat_attrs[] = {
1087 ATTR_LIST(sb_status),
1088 ATTR_LIST(cp_status),
1091 ATTRIBUTE_GROUPS(f2fs_stat);
1093 F2FS_SB_FEATURE_RO_ATTR(encryption, ENCRYPT);
1094 F2FS_SB_FEATURE_RO_ATTR(block_zoned, BLKZONED);
1095 F2FS_SB_FEATURE_RO_ATTR(extra_attr, EXTRA_ATTR);
1096 F2FS_SB_FEATURE_RO_ATTR(project_quota, PRJQUOTA);
1097 F2FS_SB_FEATURE_RO_ATTR(inode_checksum, INODE_CHKSUM);
1098 F2FS_SB_FEATURE_RO_ATTR(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
1099 F2FS_SB_FEATURE_RO_ATTR(quota_ino, QUOTA_INO);
1100 F2FS_SB_FEATURE_RO_ATTR(inode_crtime, INODE_CRTIME);
1101 F2FS_SB_FEATURE_RO_ATTR(lost_found, LOST_FOUND);
1102 F2FS_SB_FEATURE_RO_ATTR(verity, VERITY);
1103 F2FS_SB_FEATURE_RO_ATTR(sb_checksum, SB_CHKSUM);
1104 F2FS_SB_FEATURE_RO_ATTR(casefold, CASEFOLD);
1105 F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION);
1106 F2FS_SB_FEATURE_RO_ATTR(readonly, RO);
1108 static struct attribute *f2fs_sb_feat_attrs[] = {
1109 ATTR_LIST(sb_encryption),
1110 ATTR_LIST(sb_block_zoned),
1111 ATTR_LIST(sb_extra_attr),
1112 ATTR_LIST(sb_project_quota),
1113 ATTR_LIST(sb_inode_checksum),
1114 ATTR_LIST(sb_flexible_inline_xattr),
1115 ATTR_LIST(sb_quota_ino),
1116 ATTR_LIST(sb_inode_crtime),
1117 ATTR_LIST(sb_lost_found),
1118 ATTR_LIST(sb_verity),
1119 ATTR_LIST(sb_sb_checksum),
1120 ATTR_LIST(sb_casefold),
1121 ATTR_LIST(sb_compression),
1122 ATTR_LIST(sb_readonly),
1125 ATTRIBUTE_GROUPS(f2fs_sb_feat);
1127 static const struct sysfs_ops f2fs_attr_ops = {
1128 .show = f2fs_attr_show,
1129 .store = f2fs_attr_store,
1132 static struct kobj_type f2fs_sb_ktype = {
1133 .default_groups = f2fs_groups,
1134 .sysfs_ops = &f2fs_attr_ops,
1135 .release = f2fs_sb_release,
1138 static struct kobj_type f2fs_ktype = {
1139 .sysfs_ops = &f2fs_attr_ops,
1142 static struct kset f2fs_kset = {
1143 .kobj = {.ktype = &f2fs_ktype},
1146 static struct kobj_type f2fs_feat_ktype = {
1147 .default_groups = f2fs_feat_groups,
1148 .sysfs_ops = &f2fs_attr_ops,
1151 static struct kobject f2fs_feat = {
1155 static ssize_t f2fs_stat_attr_show(struct kobject *kobj,
1156 struct attribute *attr, char *buf)
1158 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1160 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1162 return a->show ? a->show(a, sbi, buf) : 0;
1165 static ssize_t f2fs_stat_attr_store(struct kobject *kobj, struct attribute *attr,
1166 const char *buf, size_t len)
1168 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1170 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1172 return a->store ? a->store(a, sbi, buf, len) : 0;
1175 static void f2fs_stat_kobj_release(struct kobject *kobj)
1177 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1179 complete(&sbi->s_stat_kobj_unregister);
1182 static const struct sysfs_ops f2fs_stat_attr_ops = {
1183 .show = f2fs_stat_attr_show,
1184 .store = f2fs_stat_attr_store,
1187 static struct kobj_type f2fs_stat_ktype = {
1188 .default_groups = f2fs_stat_groups,
1189 .sysfs_ops = &f2fs_stat_attr_ops,
1190 .release = f2fs_stat_kobj_release,
1193 static ssize_t f2fs_sb_feat_attr_show(struct kobject *kobj,
1194 struct attribute *attr, char *buf)
1196 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1197 s_feature_list_kobj);
1198 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1200 return a->show ? a->show(a, sbi, buf) : 0;
1203 static void f2fs_feature_list_kobj_release(struct kobject *kobj)
1205 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1206 s_feature_list_kobj);
1207 complete(&sbi->s_feature_list_kobj_unregister);
1210 static const struct sysfs_ops f2fs_feature_list_attr_ops = {
1211 .show = f2fs_sb_feat_attr_show,
1214 static struct kobj_type f2fs_feature_list_ktype = {
1215 .default_groups = f2fs_sb_feat_groups,
1216 .sysfs_ops = &f2fs_feature_list_attr_ops,
1217 .release = f2fs_feature_list_kobj_release,
1220 static int __maybe_unused segment_info_seq_show(struct seq_file *seq,
1223 struct super_block *sb = seq->private;
1224 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1225 unsigned int total_segs =
1226 le32_to_cpu(sbi->raw_super->segment_count_main);
1229 seq_puts(seq, "format: segment_type|valid_blocks\n"
1230 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1232 for (i = 0; i < total_segs; i++) {
1233 struct seg_entry *se = get_seg_entry(sbi, i);
1236 seq_printf(seq, "%-10d", i);
1237 seq_printf(seq, "%d|%-3u", se->type, se->valid_blocks);
1238 if ((i % 10) == 9 || i == (total_segs - 1))
1239 seq_putc(seq, '\n');
1247 static int __maybe_unused segment_bits_seq_show(struct seq_file *seq,
1250 struct super_block *sb = seq->private;
1251 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1252 unsigned int total_segs =
1253 le32_to_cpu(sbi->raw_super->segment_count_main);
1256 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
1257 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1259 for (i = 0; i < total_segs; i++) {
1260 struct seg_entry *se = get_seg_entry(sbi, i);
1262 seq_printf(seq, "%-10d", i);
1263 seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks);
1264 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
1265 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
1266 seq_putc(seq, '\n');
1271 static int __maybe_unused victim_bits_seq_show(struct seq_file *seq,
1274 struct super_block *sb = seq->private;
1275 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1276 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
1279 seq_puts(seq, "format: victim_secmap bitmaps\n");
1281 for (i = 0; i < MAIN_SECS(sbi); i++) {
1283 seq_printf(seq, "%-10d", i);
1284 seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0);
1285 if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1))
1286 seq_putc(seq, '\n');
1293 static int __maybe_unused discard_plist_seq_show(struct seq_file *seq,
1296 struct super_block *sb = seq->private;
1297 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1298 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
1301 seq_puts(seq, "Discard pend list(Show diacrd_cmd count on each entry, .:not exist):\n");
1302 if (!f2fs_realtime_discard_enable(sbi))
1306 mutex_lock(&dcc->cmd_lock);
1307 for (i = 0; i < MAX_PLIST_NUM; i++) {
1308 struct list_head *pend_list;
1309 struct discard_cmd *dc, *tmp;
1312 seq_printf(seq, " %-3d", i);
1314 pend_list = &dcc->pend_list[i];
1315 list_for_each_entry_safe(dc, tmp, pend_list, list)
1318 seq_printf(seq, " %7d", count);
1320 seq_puts(seq, " .");
1322 seq_putc(seq, '\n');
1324 seq_putc(seq, '\n');
1325 mutex_unlock(&dcc->cmd_lock);
1331 int __init f2fs_init_sysfs(void)
1335 kobject_set_name(&f2fs_kset.kobj, "f2fs");
1336 f2fs_kset.kobj.parent = fs_kobj;
1337 ret = kset_register(&f2fs_kset);
1341 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
1344 kobject_put(&f2fs_feat);
1345 kset_unregister(&f2fs_kset);
1347 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
1352 void f2fs_exit_sysfs(void)
1354 kobject_put(&f2fs_feat);
1355 kset_unregister(&f2fs_kset);
1356 remove_proc_entry("fs/f2fs", NULL);
1357 f2fs_proc_root = NULL;
1360 int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
1362 struct super_block *sb = sbi->sb;
1365 sbi->s_kobj.kset = &f2fs_kset;
1366 init_completion(&sbi->s_kobj_unregister);
1367 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
1372 sbi->s_stat_kobj.kset = &f2fs_kset;
1373 init_completion(&sbi->s_stat_kobj_unregister);
1374 err = kobject_init_and_add(&sbi->s_stat_kobj, &f2fs_stat_ktype,
1375 &sbi->s_kobj, "stat");
1379 sbi->s_feature_list_kobj.kset = &f2fs_kset;
1380 init_completion(&sbi->s_feature_list_kobj_unregister);
1381 err = kobject_init_and_add(&sbi->s_feature_list_kobj,
1382 &f2fs_feature_list_ktype,
1383 &sbi->s_kobj, "feature_list");
1385 goto put_feature_list_kobj;
1388 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
1391 proc_create_single_data("segment_info", 0444, sbi->s_proc,
1392 segment_info_seq_show, sb);
1393 proc_create_single_data("segment_bits", 0444, sbi->s_proc,
1394 segment_bits_seq_show, sb);
1395 #ifdef CONFIG_F2FS_IOSTAT
1396 proc_create_single_data("iostat_info", 0444, sbi->s_proc,
1397 iostat_info_seq_show, sb);
1399 proc_create_single_data("victim_bits", 0444, sbi->s_proc,
1400 victim_bits_seq_show, sb);
1401 proc_create_single_data("discard_plist_info", 0444, sbi->s_proc,
1402 discard_plist_seq_show, sb);
1405 put_feature_list_kobj:
1406 kobject_put(&sbi->s_feature_list_kobj);
1407 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1409 kobject_put(&sbi->s_stat_kobj);
1410 wait_for_completion(&sbi->s_stat_kobj_unregister);
1412 kobject_put(&sbi->s_kobj);
1413 wait_for_completion(&sbi->s_kobj_unregister);
1417 void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
1420 #ifdef CONFIG_F2FS_IOSTAT
1421 remove_proc_entry("iostat_info", sbi->s_proc);
1423 remove_proc_entry("segment_info", sbi->s_proc);
1424 remove_proc_entry("segment_bits", sbi->s_proc);
1425 remove_proc_entry("victim_bits", sbi->s_proc);
1426 remove_proc_entry("discard_plist_info", sbi->s_proc);
1427 remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
1430 kobject_del(&sbi->s_stat_kobj);
1431 kobject_put(&sbi->s_stat_kobj);
1432 wait_for_completion(&sbi->s_stat_kobj_unregister);
1433 kobject_del(&sbi->s_feature_list_kobj);
1434 kobject_put(&sbi->s_feature_list_kobj);
1435 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1437 kobject_del(&sbi->s_kobj);
1438 kobject_put(&sbi->s_kobj);
1439 wait_for_completion(&sbi->s_kobj_unregister);