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;
315 int class = IOPRIO_PRIO_CLASS(cprc->ckpt_thread_ioprio);
316 int data = IOPRIO_PRIO_DATA(cprc->ckpt_thread_ioprio);
318 if (class != IOPRIO_CLASS_RT && class != IOPRIO_CLASS_BE)
321 return sysfs_emit(buf, "%s,%d\n",
322 class == IOPRIO_CLASS_RT ? "rt" : "be", data);
325 #ifdef CONFIG_F2FS_FS_COMPRESSION
326 if (!strcmp(a->attr.name, "compr_written_block"))
327 return sysfs_emit(buf, "%llu\n", sbi->compr_written_block);
329 if (!strcmp(a->attr.name, "compr_saved_block"))
330 return sysfs_emit(buf, "%llu\n", sbi->compr_saved_block);
332 if (!strcmp(a->attr.name, "compr_new_inode"))
333 return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
336 if (!strcmp(a->attr.name, "gc_segment_mode"))
337 return sysfs_emit(buf, "%u\n", sbi->gc_segment_mode);
339 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
340 return sysfs_emit(buf, "%u\n",
341 sbi->gc_reclaimed_segs[sbi->gc_segment_mode]);
344 if (!strcmp(a->attr.name, "current_atomic_write")) {
345 s64 current_write = atomic64_read(&sbi->current_atomic_write);
347 return sysfs_emit(buf, "%lld\n", current_write);
350 if (!strcmp(a->attr.name, "peak_atomic_write"))
351 return sysfs_emit(buf, "%lld\n", sbi->peak_atomic_write);
353 if (!strcmp(a->attr.name, "committed_atomic_block"))
354 return sysfs_emit(buf, "%llu\n", sbi->committed_atomic_block);
356 if (!strcmp(a->attr.name, "revoked_atomic_block"))
357 return sysfs_emit(buf, "%llu\n", sbi->revoked_atomic_block);
359 ui = (unsigned int *)(ptr + a->offset);
361 return sysfs_emit(buf, "%u\n", *ui);
364 static ssize_t __sbi_store(struct f2fs_attr *a,
365 struct f2fs_sb_info *sbi,
366 const char *buf, size_t count)
373 ptr = __struct_ptr(sbi, a->struct_type);
377 if (!strcmp(a->attr.name, "extension_list")) {
378 const char *name = strim((char *)buf);
379 bool set = true, hot;
381 if (!strncmp(name, "[h]", 3))
383 else if (!strncmp(name, "[c]", 3))
395 if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN)
398 f2fs_down_write(&sbi->sb_lock);
400 ret = f2fs_update_extension_list(sbi, name, hot, set);
404 ret = f2fs_commit_super(sbi, false);
406 f2fs_update_extension_list(sbi, name, hot, !set);
408 f2fs_up_write(&sbi->sb_lock);
409 return ret ? ret : count;
412 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
413 const char *name = strim((char *)buf);
414 struct ckpt_req_control *cprc = &sbi->cprc_info;
419 if (!strncmp(name, "rt,", 3))
420 class = IOPRIO_CLASS_RT;
421 else if (!strncmp(name, "be,", 3))
422 class = IOPRIO_CLASS_BE;
427 ret = kstrtol(name, 10, &data);
430 if (data >= IOPRIO_NR_LEVELS || data < 0)
433 cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, data);
434 if (test_opt(sbi, MERGE_CHECKPOINT)) {
435 ret = set_task_ioprio(cprc->f2fs_issue_ckpt,
436 cprc->ckpt_thread_ioprio);
444 ui = (unsigned int *)(ptr + a->offset);
446 ret = kstrtoul(skip_spaces(buf), 0, &t);
449 #ifdef CONFIG_F2FS_FAULT_INJECTION
450 if (a->struct_type == FAULT_INFO_TYPE && t >= BIT(FAULT_MAX))
452 if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX)
455 if (a->struct_type == RESERVED_BLOCKS) {
456 spin_lock(&sbi->stat_lock);
457 if (t > (unsigned long)(sbi->user_block_count -
458 F2FS_OPTION(sbi).root_reserved_blocks -
459 sbi->blocks_per_seg *
460 SM_I(sbi)->additional_reserved_segments)) {
461 spin_unlock(&sbi->stat_lock);
465 sbi->current_reserved_blocks = min(sbi->reserved_blocks,
466 sbi->user_block_count - valid_user_blocks(sbi));
467 spin_unlock(&sbi->stat_lock);
471 if (!strcmp(a->attr.name, "discard_io_aware_gran")) {
472 if (t > MAX_PLIST_NUM)
474 if (!f2fs_block_unit_discard(sbi))
482 if (!strcmp(a->attr.name, "discard_granularity")) {
483 if (t == 0 || t > MAX_PLIST_NUM)
485 if (!f2fs_block_unit_discard(sbi))
493 if (!strcmp(a->attr.name, "max_ordered_discard")) {
494 if (t == 0 || t > MAX_PLIST_NUM)
496 if (!f2fs_block_unit_discard(sbi))
502 if (!strcmp(a->attr.name, "discard_urgent_util")) {
509 if (!strcmp(a->attr.name, "migration_granularity")) {
510 if (t == 0 || t > sbi->segs_per_sec)
514 if (!strcmp(a->attr.name, "gc_urgent")) {
516 sbi->gc_mode = GC_NORMAL;
518 sbi->gc_mode = GC_URGENT_HIGH;
519 if (sbi->gc_thread) {
520 sbi->gc_thread->gc_wake = true;
521 wake_up_interruptible_all(
522 &sbi->gc_thread->gc_wait_queue_head);
523 wake_up_discard_thread(sbi, true);
526 sbi->gc_mode = GC_URGENT_LOW;
528 sbi->gc_mode = GC_URGENT_MID;
529 if (sbi->gc_thread) {
530 sbi->gc_thread->gc_wake = true;
531 wake_up_interruptible_all(
532 &sbi->gc_thread->gc_wait_queue_head);
539 if (!strcmp(a->attr.name, "gc_idle")) {
540 if (t == GC_IDLE_CB) {
541 sbi->gc_mode = GC_IDLE_CB;
542 } else if (t == GC_IDLE_GREEDY) {
543 sbi->gc_mode = GC_IDLE_GREEDY;
544 } else if (t == GC_IDLE_AT) {
545 if (!sbi->am.atgc_enabled)
547 sbi->gc_mode = GC_IDLE_AT;
549 sbi->gc_mode = GC_NORMAL;
554 if (!strcmp(a->attr.name, "gc_remaining_trials")) {
555 spin_lock(&sbi->gc_remaining_trials_lock);
556 sbi->gc_remaining_trials = t;
557 spin_unlock(&sbi->gc_remaining_trials_lock);
562 #ifdef CONFIG_F2FS_IOSTAT
563 if (!strcmp(a->attr.name, "iostat_enable")) {
564 sbi->iostat_enable = !!t;
565 if (!sbi->iostat_enable)
566 f2fs_reset_iostat(sbi);
570 if (!strcmp(a->attr.name, "iostat_period_ms")) {
571 if (t < MIN_IOSTAT_PERIOD_MS || t > MAX_IOSTAT_PERIOD_MS)
573 spin_lock_irq(&sbi->iostat_lock);
574 sbi->iostat_period_ms = (unsigned int)t;
575 spin_unlock_irq(&sbi->iostat_lock);
580 #ifdef CONFIG_F2FS_FS_COMPRESSION
581 if (!strcmp(a->attr.name, "compr_written_block") ||
582 !strcmp(a->attr.name, "compr_saved_block")) {
585 sbi->compr_written_block = 0;
586 sbi->compr_saved_block = 0;
590 if (!strcmp(a->attr.name, "compr_new_inode")) {
593 sbi->compr_new_inode = 0;
597 if (!strcmp(a->attr.name, "compress_percent")) {
598 if (t == 0 || t > 100)
604 if (!strcmp(a->attr.name, "compress_watermark")) {
605 if (t == 0 || t > 100)
612 if (!strcmp(a->attr.name, "atgc_candidate_ratio")) {
615 sbi->am.candidate_ratio = t;
619 if (!strcmp(a->attr.name, "atgc_age_weight")) {
622 sbi->am.age_weight = t;
626 if (!strcmp(a->attr.name, "gc_segment_mode")) {
628 sbi->gc_segment_mode = t;
634 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
637 sbi->gc_reclaimed_segs[sbi->gc_segment_mode] = 0;
641 if (!strcmp(a->attr.name, "seq_file_ra_mul")) {
642 if (t >= MIN_RA_MUL && t <= MAX_RA_MUL)
643 sbi->seq_file_ra_mul = t;
649 if (!strcmp(a->attr.name, "max_fragment_chunk")) {
650 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE)
651 sbi->max_fragment_chunk = t;
657 if (!strcmp(a->attr.name, "max_fragment_hole")) {
658 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE)
659 sbi->max_fragment_hole = t;
665 if (!strcmp(a->attr.name, "peak_atomic_write")) {
668 sbi->peak_atomic_write = 0;
672 if (!strcmp(a->attr.name, "committed_atomic_block")) {
675 sbi->committed_atomic_block = 0;
679 if (!strcmp(a->attr.name, "revoked_atomic_block")) {
682 sbi->revoked_atomic_block = 0;
686 if (!strcmp(a->attr.name, "readdir_ra")) {
687 sbi->readdir_ra = !!t;
691 if (!strcmp(a->attr.name, "hot_data_age_threshold")) {
692 if (t == 0 || t >= sbi->warm_data_age_threshold)
696 *ui = (unsigned int)t;
700 if (!strcmp(a->attr.name, "warm_data_age_threshold")) {
701 if (t <= sbi->hot_data_age_threshold)
705 *ui = (unsigned int)t;
709 if (!strcmp(a->attr.name, "last_age_weight")) {
714 *ui = (unsigned int)t;
718 if (!strcmp(a->attr.name, "ipu_policy")) {
719 if (t >= BIT(F2FS_IPU_MAX))
721 if (t && f2fs_lfs_mode(sbi))
723 SM_I(sbi)->ipu_policy = (unsigned int)t;
727 *ui = (unsigned int)t;
732 static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
733 struct f2fs_sb_info *sbi,
734 const char *buf, size_t count)
737 bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") ||
738 a->struct_type == GC_THREAD);
741 if (!down_read_trylock(&sbi->sb->s_umount))
744 ret = __sbi_store(a, sbi, buf, count);
746 up_read(&sbi->sb->s_umount);
751 static ssize_t f2fs_attr_show(struct kobject *kobj,
752 struct attribute *attr, char *buf)
754 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
756 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
758 return a->show ? a->show(a, sbi, buf) : 0;
761 static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
762 const char *buf, size_t len)
764 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
766 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
768 return a->store ? a->store(a, sbi, buf, len) : 0;
771 static void f2fs_sb_release(struct kobject *kobj)
773 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
775 complete(&sbi->s_kobj_unregister);
779 * Note that there are three feature list entries:
780 * 1) /sys/fs/f2fs/features
781 * : shows runtime features supported by in-kernel f2fs along with Kconfig.
782 * - ref. F2FS_FEATURE_RO_ATTR()
784 * 2) /sys/fs/f2fs/$s_id/features <deprecated>
785 * : shows on-disk features enabled by mkfs.f2fs, used for old kernels. This
786 * won't add new feature anymore, and thus, users should check entries in 3)
787 * instead of this 2).
789 * 3) /sys/fs/f2fs/$s_id/feature_list
790 * : shows on-disk features enabled by mkfs.f2fs per instance, which follows
791 * sysfs entry rule where each entry should expose single value.
792 * This list covers old feature list provided by 2) and beyond. Therefore,
793 * please add new on-disk feature in this list only.
794 * - ref. F2FS_SB_FEATURE_RO_ATTR()
796 static ssize_t f2fs_feature_show(struct f2fs_attr *a,
797 struct f2fs_sb_info *sbi, char *buf)
799 return sysfs_emit(buf, "supported\n");
802 #define F2FS_FEATURE_RO_ATTR(_name) \
803 static struct f2fs_attr f2fs_attr_##_name = { \
804 .attr = {.name = __stringify(_name), .mode = 0444 }, \
805 .show = f2fs_feature_show, \
808 static ssize_t f2fs_sb_feature_show(struct f2fs_attr *a,
809 struct f2fs_sb_info *sbi, char *buf)
811 if (F2FS_HAS_FEATURE(sbi, a->id))
812 return sysfs_emit(buf, "supported\n");
813 return sysfs_emit(buf, "unsupported\n");
816 #define F2FS_SB_FEATURE_RO_ATTR(_name, _feat) \
817 static struct f2fs_attr f2fs_attr_sb_##_name = { \
818 .attr = {.name = __stringify(_name), .mode = 0444 }, \
819 .show = f2fs_sb_feature_show, \
820 .id = F2FS_FEATURE_##_feat, \
823 #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
824 static struct f2fs_attr f2fs_attr_##_name = { \
825 .attr = {.name = __stringify(_name), .mode = _mode }, \
828 .struct_type = _struct_type, \
832 #define F2FS_RO_ATTR(struct_type, struct_name, name, elname) \
833 F2FS_ATTR_OFFSET(struct_type, name, 0444, \
834 f2fs_sbi_show, NULL, \
835 offsetof(struct struct_name, elname))
837 #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
838 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
839 f2fs_sbi_show, f2fs_sbi_store, \
840 offsetof(struct struct_name, elname))
842 #define F2FS_GENERAL_RO_ATTR(name) \
843 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
845 #define F2FS_STAT_ATTR(_struct_type, _struct_name, _name, _elname) \
846 static struct f2fs_attr f2fs_attr_##_name = { \
847 .attr = {.name = __stringify(_name), .mode = 0444 }, \
848 .show = f2fs_sbi_show, \
849 .struct_type = _struct_type, \
850 .offset = offsetof(struct _struct_name, _elname), \
853 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time,
855 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
856 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
857 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
858 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode);
859 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode);
860 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
861 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
862 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_request, max_discard_request);
863 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, min_discard_issue_time, min_discard_issue_time);
864 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, mid_discard_issue_time, mid_discard_issue_time);
865 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_issue_time, max_discard_issue_time);
866 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_io_aware_gran, discard_io_aware_gran);
867 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_urgent_util, discard_urgent_util);
868 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity);
869 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_ordered_discard, max_ordered_discard);
870 F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
871 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
872 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
873 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
874 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_seq_blocks, min_seq_blocks);
875 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
876 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections);
877 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
878 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
879 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
880 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, max_roll_forward_node_blocks, max_rf_node_blocks);
881 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
882 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, migration_granularity, migration_granularity);
883 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
884 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
885 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
886 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval,
887 interval_time[DISCARD_TIME]);
888 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]);
889 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info,
890 umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]);
891 #ifdef CONFIG_F2FS_IOSTAT
892 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
893 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_period_ms, iostat_period_ms);
895 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
896 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_io_bytes, max_io_bytes);
897 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
898 F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list);
899 #ifdef CONFIG_F2FS_FAULT_INJECTION
900 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
901 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
903 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, data_io_flag, data_io_flag);
904 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, node_io_flag, node_io_flag);
905 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_remaining_trials, gc_remaining_trials);
906 F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, ckpt_thread_ioprio, ckpt_thread_ioprio);
907 F2FS_GENERAL_RO_ATTR(dirty_segments);
908 F2FS_GENERAL_RO_ATTR(free_segments);
909 F2FS_GENERAL_RO_ATTR(ovp_segments);
910 F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
911 F2FS_GENERAL_RO_ATTR(features);
912 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
913 F2FS_GENERAL_RO_ATTR(unusable);
914 F2FS_GENERAL_RO_ATTR(encoding);
915 F2FS_GENERAL_RO_ATTR(mounted_time_sec);
916 F2FS_GENERAL_RO_ATTR(main_blkaddr);
917 F2FS_GENERAL_RO_ATTR(pending_discard);
918 F2FS_GENERAL_RO_ATTR(gc_mode);
919 #ifdef CONFIG_F2FS_STAT_FS
920 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count);
921 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count);
922 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_foreground_calls, call_count);
923 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_background_calls, bg_gc);
924 F2FS_GENERAL_RO_ATTR(moved_blocks_background);
925 F2FS_GENERAL_RO_ATTR(moved_blocks_foreground);
926 F2FS_GENERAL_RO_ATTR(avg_vblocks);
929 #ifdef CONFIG_FS_ENCRYPTION
930 F2FS_FEATURE_RO_ATTR(encryption);
931 F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2);
932 #if IS_ENABLED(CONFIG_UNICODE)
933 F2FS_FEATURE_RO_ATTR(encrypted_casefold);
935 #endif /* CONFIG_FS_ENCRYPTION */
936 #ifdef CONFIG_BLK_DEV_ZONED
937 F2FS_FEATURE_RO_ATTR(block_zoned);
938 F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, unusable_blocks_per_sec,
939 unusable_blocks_per_sec);
941 F2FS_FEATURE_RO_ATTR(atomic_write);
942 F2FS_FEATURE_RO_ATTR(extra_attr);
943 F2FS_FEATURE_RO_ATTR(project_quota);
944 F2FS_FEATURE_RO_ATTR(inode_checksum);
945 F2FS_FEATURE_RO_ATTR(flexible_inline_xattr);
946 F2FS_FEATURE_RO_ATTR(quota_ino);
947 F2FS_FEATURE_RO_ATTR(inode_crtime);
948 F2FS_FEATURE_RO_ATTR(lost_found);
949 #ifdef CONFIG_FS_VERITY
950 F2FS_FEATURE_RO_ATTR(verity);
952 F2FS_FEATURE_RO_ATTR(sb_checksum);
953 #if IS_ENABLED(CONFIG_UNICODE)
954 F2FS_FEATURE_RO_ATTR(casefold);
956 F2FS_FEATURE_RO_ATTR(readonly);
957 #ifdef CONFIG_F2FS_FS_COMPRESSION
958 F2FS_FEATURE_RO_ATTR(compression);
959 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block);
960 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block);
961 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode);
962 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compress_percent, compress_percent);
963 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compress_watermark, compress_watermark);
965 F2FS_FEATURE_RO_ATTR(pin_file);
968 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio);
969 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count);
970 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
971 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
973 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, seq_file_ra_mul, seq_file_ra_mul);
974 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_segment_mode, gc_segment_mode);
975 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_reclaimed_segments, gc_reclaimed_segs);
976 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_chunk, max_fragment_chunk);
977 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_hole, max_fragment_hole);
979 /* For atomic write */
980 F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, current_atomic_write, current_atomic_write);
981 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, peak_atomic_write, peak_atomic_write);
982 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, committed_atomic_block, committed_atomic_block);
983 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block);
985 /* For block age extent cache */
986 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold);
987 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold);
988 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, last_age_weight, last_age_weight);
990 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
991 static struct attribute *f2fs_attrs[] = {
992 ATTR_LIST(gc_urgent_sleep_time),
993 ATTR_LIST(gc_min_sleep_time),
994 ATTR_LIST(gc_max_sleep_time),
995 ATTR_LIST(gc_no_gc_sleep_time),
997 ATTR_LIST(gc_urgent),
998 ATTR_LIST(reclaim_segments),
999 ATTR_LIST(main_blkaddr),
1000 ATTR_LIST(max_small_discards),
1001 ATTR_LIST(max_discard_request),
1002 ATTR_LIST(min_discard_issue_time),
1003 ATTR_LIST(mid_discard_issue_time),
1004 ATTR_LIST(max_discard_issue_time),
1005 ATTR_LIST(discard_io_aware_gran),
1006 ATTR_LIST(discard_urgent_util),
1007 ATTR_LIST(discard_granularity),
1008 ATTR_LIST(max_ordered_discard),
1009 ATTR_LIST(pending_discard),
1011 ATTR_LIST(ipu_policy),
1012 ATTR_LIST(min_ipu_util),
1013 ATTR_LIST(min_fsync_blocks),
1014 ATTR_LIST(min_seq_blocks),
1015 ATTR_LIST(min_hot_blocks),
1016 ATTR_LIST(min_ssr_sections),
1017 ATTR_LIST(max_victim_search),
1018 ATTR_LIST(migration_granularity),
1019 ATTR_LIST(dir_level),
1020 ATTR_LIST(ram_thresh),
1021 ATTR_LIST(ra_nid_pages),
1022 ATTR_LIST(dirty_nats_ratio),
1023 ATTR_LIST(max_roll_forward_node_blocks),
1024 ATTR_LIST(cp_interval),
1025 ATTR_LIST(idle_interval),
1026 ATTR_LIST(discard_idle_interval),
1027 ATTR_LIST(gc_idle_interval),
1028 ATTR_LIST(umount_discard_timeout),
1029 #ifdef CONFIG_F2FS_IOSTAT
1030 ATTR_LIST(iostat_enable),
1031 ATTR_LIST(iostat_period_ms),
1033 ATTR_LIST(readdir_ra),
1034 ATTR_LIST(max_io_bytes),
1035 ATTR_LIST(gc_pin_file_thresh),
1036 ATTR_LIST(extension_list),
1037 #ifdef CONFIG_F2FS_FAULT_INJECTION
1038 ATTR_LIST(inject_rate),
1039 ATTR_LIST(inject_type),
1041 ATTR_LIST(data_io_flag),
1042 ATTR_LIST(node_io_flag),
1043 ATTR_LIST(gc_remaining_trials),
1044 ATTR_LIST(ckpt_thread_ioprio),
1045 ATTR_LIST(dirty_segments),
1046 ATTR_LIST(free_segments),
1047 ATTR_LIST(ovp_segments),
1048 ATTR_LIST(unusable),
1049 ATTR_LIST(lifetime_write_kbytes),
1050 ATTR_LIST(features),
1051 ATTR_LIST(reserved_blocks),
1052 ATTR_LIST(current_reserved_blocks),
1053 ATTR_LIST(encoding),
1054 ATTR_LIST(mounted_time_sec),
1055 #ifdef CONFIG_F2FS_STAT_FS
1056 ATTR_LIST(cp_foreground_calls),
1057 ATTR_LIST(cp_background_calls),
1058 ATTR_LIST(gc_foreground_calls),
1059 ATTR_LIST(gc_background_calls),
1060 ATTR_LIST(moved_blocks_foreground),
1061 ATTR_LIST(moved_blocks_background),
1062 ATTR_LIST(avg_vblocks),
1064 #ifdef CONFIG_BLK_DEV_ZONED
1065 ATTR_LIST(unusable_blocks_per_sec),
1067 #ifdef CONFIG_F2FS_FS_COMPRESSION
1068 ATTR_LIST(compr_written_block),
1069 ATTR_LIST(compr_saved_block),
1070 ATTR_LIST(compr_new_inode),
1071 ATTR_LIST(compress_percent),
1072 ATTR_LIST(compress_watermark),
1075 ATTR_LIST(atgc_candidate_ratio),
1076 ATTR_LIST(atgc_candidate_count),
1077 ATTR_LIST(atgc_age_weight),
1078 ATTR_LIST(atgc_age_threshold),
1079 ATTR_LIST(seq_file_ra_mul),
1080 ATTR_LIST(gc_segment_mode),
1081 ATTR_LIST(gc_reclaimed_segments),
1082 ATTR_LIST(max_fragment_chunk),
1083 ATTR_LIST(max_fragment_hole),
1084 ATTR_LIST(current_atomic_write),
1085 ATTR_LIST(peak_atomic_write),
1086 ATTR_LIST(committed_atomic_block),
1087 ATTR_LIST(revoked_atomic_block),
1088 ATTR_LIST(hot_data_age_threshold),
1089 ATTR_LIST(warm_data_age_threshold),
1090 ATTR_LIST(last_age_weight),
1093 ATTRIBUTE_GROUPS(f2fs);
1095 static struct attribute *f2fs_feat_attrs[] = {
1096 #ifdef CONFIG_FS_ENCRYPTION
1097 ATTR_LIST(encryption),
1098 ATTR_LIST(test_dummy_encryption_v2),
1099 #if IS_ENABLED(CONFIG_UNICODE)
1100 ATTR_LIST(encrypted_casefold),
1102 #endif /* CONFIG_FS_ENCRYPTION */
1103 #ifdef CONFIG_BLK_DEV_ZONED
1104 ATTR_LIST(block_zoned),
1106 ATTR_LIST(atomic_write),
1107 ATTR_LIST(extra_attr),
1108 ATTR_LIST(project_quota),
1109 ATTR_LIST(inode_checksum),
1110 ATTR_LIST(flexible_inline_xattr),
1111 ATTR_LIST(quota_ino),
1112 ATTR_LIST(inode_crtime),
1113 ATTR_LIST(lost_found),
1114 #ifdef CONFIG_FS_VERITY
1117 ATTR_LIST(sb_checksum),
1118 #if IS_ENABLED(CONFIG_UNICODE)
1119 ATTR_LIST(casefold),
1121 ATTR_LIST(readonly),
1122 #ifdef CONFIG_F2FS_FS_COMPRESSION
1123 ATTR_LIST(compression),
1125 ATTR_LIST(pin_file),
1128 ATTRIBUTE_GROUPS(f2fs_feat);
1130 F2FS_GENERAL_RO_ATTR(sb_status);
1131 F2FS_GENERAL_RO_ATTR(cp_status);
1132 static struct attribute *f2fs_stat_attrs[] = {
1133 ATTR_LIST(sb_status),
1134 ATTR_LIST(cp_status),
1137 ATTRIBUTE_GROUPS(f2fs_stat);
1139 F2FS_SB_FEATURE_RO_ATTR(encryption, ENCRYPT);
1140 F2FS_SB_FEATURE_RO_ATTR(block_zoned, BLKZONED);
1141 F2FS_SB_FEATURE_RO_ATTR(extra_attr, EXTRA_ATTR);
1142 F2FS_SB_FEATURE_RO_ATTR(project_quota, PRJQUOTA);
1143 F2FS_SB_FEATURE_RO_ATTR(inode_checksum, INODE_CHKSUM);
1144 F2FS_SB_FEATURE_RO_ATTR(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
1145 F2FS_SB_FEATURE_RO_ATTR(quota_ino, QUOTA_INO);
1146 F2FS_SB_FEATURE_RO_ATTR(inode_crtime, INODE_CRTIME);
1147 F2FS_SB_FEATURE_RO_ATTR(lost_found, LOST_FOUND);
1148 F2FS_SB_FEATURE_RO_ATTR(verity, VERITY);
1149 F2FS_SB_FEATURE_RO_ATTR(sb_checksum, SB_CHKSUM);
1150 F2FS_SB_FEATURE_RO_ATTR(casefold, CASEFOLD);
1151 F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION);
1152 F2FS_SB_FEATURE_RO_ATTR(readonly, RO);
1154 static struct attribute *f2fs_sb_feat_attrs[] = {
1155 ATTR_LIST(sb_encryption),
1156 ATTR_LIST(sb_block_zoned),
1157 ATTR_LIST(sb_extra_attr),
1158 ATTR_LIST(sb_project_quota),
1159 ATTR_LIST(sb_inode_checksum),
1160 ATTR_LIST(sb_flexible_inline_xattr),
1161 ATTR_LIST(sb_quota_ino),
1162 ATTR_LIST(sb_inode_crtime),
1163 ATTR_LIST(sb_lost_found),
1164 ATTR_LIST(sb_verity),
1165 ATTR_LIST(sb_sb_checksum),
1166 ATTR_LIST(sb_casefold),
1167 ATTR_LIST(sb_compression),
1168 ATTR_LIST(sb_readonly),
1171 ATTRIBUTE_GROUPS(f2fs_sb_feat);
1173 static const struct sysfs_ops f2fs_attr_ops = {
1174 .show = f2fs_attr_show,
1175 .store = f2fs_attr_store,
1178 static const struct kobj_type f2fs_sb_ktype = {
1179 .default_groups = f2fs_groups,
1180 .sysfs_ops = &f2fs_attr_ops,
1181 .release = f2fs_sb_release,
1184 static const struct kobj_type f2fs_ktype = {
1185 .sysfs_ops = &f2fs_attr_ops,
1188 static struct kset f2fs_kset = {
1189 .kobj = {.ktype = &f2fs_ktype},
1192 static const struct kobj_type f2fs_feat_ktype = {
1193 .default_groups = f2fs_feat_groups,
1194 .sysfs_ops = &f2fs_attr_ops,
1197 static struct kobject f2fs_feat = {
1201 static ssize_t f2fs_stat_attr_show(struct kobject *kobj,
1202 struct attribute *attr, char *buf)
1204 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1206 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1208 return a->show ? a->show(a, sbi, buf) : 0;
1211 static ssize_t f2fs_stat_attr_store(struct kobject *kobj, struct attribute *attr,
1212 const char *buf, size_t len)
1214 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1216 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1218 return a->store ? a->store(a, sbi, buf, len) : 0;
1221 static void f2fs_stat_kobj_release(struct kobject *kobj)
1223 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1225 complete(&sbi->s_stat_kobj_unregister);
1228 static const struct sysfs_ops f2fs_stat_attr_ops = {
1229 .show = f2fs_stat_attr_show,
1230 .store = f2fs_stat_attr_store,
1233 static const struct kobj_type f2fs_stat_ktype = {
1234 .default_groups = f2fs_stat_groups,
1235 .sysfs_ops = &f2fs_stat_attr_ops,
1236 .release = f2fs_stat_kobj_release,
1239 static ssize_t f2fs_sb_feat_attr_show(struct kobject *kobj,
1240 struct attribute *attr, char *buf)
1242 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1243 s_feature_list_kobj);
1244 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1246 return a->show ? a->show(a, sbi, buf) : 0;
1249 static void f2fs_feature_list_kobj_release(struct kobject *kobj)
1251 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1252 s_feature_list_kobj);
1253 complete(&sbi->s_feature_list_kobj_unregister);
1256 static const struct sysfs_ops f2fs_feature_list_attr_ops = {
1257 .show = f2fs_sb_feat_attr_show,
1260 static const struct kobj_type f2fs_feature_list_ktype = {
1261 .default_groups = f2fs_sb_feat_groups,
1262 .sysfs_ops = &f2fs_feature_list_attr_ops,
1263 .release = f2fs_feature_list_kobj_release,
1266 static int __maybe_unused segment_info_seq_show(struct seq_file *seq,
1269 struct super_block *sb = seq->private;
1270 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1271 unsigned int total_segs =
1272 le32_to_cpu(sbi->raw_super->segment_count_main);
1275 seq_puts(seq, "format: segment_type|valid_blocks\n"
1276 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1278 for (i = 0; i < total_segs; i++) {
1279 struct seg_entry *se = get_seg_entry(sbi, i);
1282 seq_printf(seq, "%-10d", i);
1283 seq_printf(seq, "%d|%-3u", se->type, se->valid_blocks);
1284 if ((i % 10) == 9 || i == (total_segs - 1))
1285 seq_putc(seq, '\n');
1293 static int __maybe_unused segment_bits_seq_show(struct seq_file *seq,
1296 struct super_block *sb = seq->private;
1297 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1298 unsigned int total_segs =
1299 le32_to_cpu(sbi->raw_super->segment_count_main);
1302 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
1303 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1305 for (i = 0; i < total_segs; i++) {
1306 struct seg_entry *se = get_seg_entry(sbi, i);
1308 seq_printf(seq, "%-10d", i);
1309 seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks);
1310 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
1311 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
1312 seq_putc(seq, '\n');
1317 static int __maybe_unused victim_bits_seq_show(struct seq_file *seq,
1320 struct super_block *sb = seq->private;
1321 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1322 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
1325 seq_puts(seq, "format: victim_secmap bitmaps\n");
1327 for (i = 0; i < MAIN_SECS(sbi); i++) {
1329 seq_printf(seq, "%-10d", i);
1330 seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0);
1331 if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1))
1332 seq_putc(seq, '\n');
1339 static int __maybe_unused discard_plist_seq_show(struct seq_file *seq,
1342 struct super_block *sb = seq->private;
1343 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1344 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
1347 seq_puts(seq, "Discard pend list(Show diacrd_cmd count on each entry, .:not exist):\n");
1348 if (!f2fs_realtime_discard_enable(sbi))
1352 mutex_lock(&dcc->cmd_lock);
1353 for (i = 0; i < MAX_PLIST_NUM; i++) {
1354 struct list_head *pend_list;
1355 struct discard_cmd *dc, *tmp;
1358 seq_printf(seq, " %-3d", i);
1360 pend_list = &dcc->pend_list[i];
1361 list_for_each_entry_safe(dc, tmp, pend_list, list)
1364 seq_printf(seq, " %7d", count);
1366 seq_puts(seq, " .");
1368 seq_putc(seq, '\n');
1370 seq_putc(seq, '\n');
1371 mutex_unlock(&dcc->cmd_lock);
1377 int __init f2fs_init_sysfs(void)
1381 kobject_set_name(&f2fs_kset.kobj, "f2fs");
1382 f2fs_kset.kobj.parent = fs_kobj;
1383 ret = kset_register(&f2fs_kset);
1387 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
1390 kobject_put(&f2fs_feat);
1391 kset_unregister(&f2fs_kset);
1393 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
1398 void f2fs_exit_sysfs(void)
1400 kobject_put(&f2fs_feat);
1401 kset_unregister(&f2fs_kset);
1402 remove_proc_entry("fs/f2fs", NULL);
1403 f2fs_proc_root = NULL;
1406 int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
1408 struct super_block *sb = sbi->sb;
1411 sbi->s_kobj.kset = &f2fs_kset;
1412 init_completion(&sbi->s_kobj_unregister);
1413 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
1418 sbi->s_stat_kobj.kset = &f2fs_kset;
1419 init_completion(&sbi->s_stat_kobj_unregister);
1420 err = kobject_init_and_add(&sbi->s_stat_kobj, &f2fs_stat_ktype,
1421 &sbi->s_kobj, "stat");
1425 sbi->s_feature_list_kobj.kset = &f2fs_kset;
1426 init_completion(&sbi->s_feature_list_kobj_unregister);
1427 err = kobject_init_and_add(&sbi->s_feature_list_kobj,
1428 &f2fs_feature_list_ktype,
1429 &sbi->s_kobj, "feature_list");
1431 goto put_feature_list_kobj;
1434 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
1437 proc_create_single_data("segment_info", 0444, sbi->s_proc,
1438 segment_info_seq_show, sb);
1439 proc_create_single_data("segment_bits", 0444, sbi->s_proc,
1440 segment_bits_seq_show, sb);
1441 #ifdef CONFIG_F2FS_IOSTAT
1442 proc_create_single_data("iostat_info", 0444, sbi->s_proc,
1443 iostat_info_seq_show, sb);
1445 proc_create_single_data("victim_bits", 0444, sbi->s_proc,
1446 victim_bits_seq_show, sb);
1447 proc_create_single_data("discard_plist_info", 0444, sbi->s_proc,
1448 discard_plist_seq_show, sb);
1451 put_feature_list_kobj:
1452 kobject_put(&sbi->s_feature_list_kobj);
1453 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1455 kobject_put(&sbi->s_stat_kobj);
1456 wait_for_completion(&sbi->s_stat_kobj_unregister);
1458 kobject_put(&sbi->s_kobj);
1459 wait_for_completion(&sbi->s_kobj_unregister);
1463 void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
1466 remove_proc_subtree(sbi->sb->s_id, f2fs_proc_root);
1468 kobject_put(&sbi->s_stat_kobj);
1469 wait_for_completion(&sbi->s_stat_kobj_unregister);
1470 kobject_put(&sbi->s_feature_list_kobj);
1471 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1473 kobject_put(&sbi->s_kobj);
1474 wait_for_completion(&sbi->s_kobj_unregister);