1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 * Copyright (c) 2017 Chao Yu <chao@kernel.org>
9 #include <linux/compiler.h>
10 #include <linux/proc_fs.h>
11 #include <linux/f2fs_fs.h>
12 #include <linux/seq_file.h>
18 static struct proc_dir_entry *f2fs_proc_root;
20 /* Sysfs support for f2fs */
22 GC_THREAD, /* struct f2fs_gc_thread */
23 SM_INFO, /* struct f2fs_sm_info */
24 DCC_INFO, /* struct discard_cmd_control */
25 NM_INFO, /* struct f2fs_nm_info */
26 F2FS_SBI, /* struct f2fs_sb_info */
27 #ifdef CONFIG_F2FS_FAULT_INJECTION
28 FAULT_INFO_RATE, /* struct f2fs_fault_info */
29 FAULT_INFO_TYPE, /* struct f2fs_fault_info */
31 RESERVED_BLOCKS, /* struct f2fs_sb_info */
35 struct attribute attr;
36 ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *);
37 ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *,
38 const char *, size_t);
44 static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
46 if (struct_type == GC_THREAD)
47 return (unsigned char *)sbi->gc_thread;
48 else if (struct_type == SM_INFO)
49 return (unsigned char *)SM_I(sbi);
50 else if (struct_type == DCC_INFO)
51 return (unsigned char *)SM_I(sbi)->dcc_info;
52 else if (struct_type == NM_INFO)
53 return (unsigned char *)NM_I(sbi);
54 else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS)
55 return (unsigned char *)sbi;
56 #ifdef CONFIG_F2FS_FAULT_INJECTION
57 else if (struct_type == FAULT_INFO_RATE ||
58 struct_type == FAULT_INFO_TYPE)
59 return (unsigned char *)&F2FS_OPTION(sbi).fault_info;
64 static ssize_t dirty_segments_show(struct f2fs_attr *a,
65 struct f2fs_sb_info *sbi, char *buf)
67 return snprintf(buf, PAGE_SIZE, "%llu\n",
68 (unsigned long long)(dirty_segments(sbi)));
71 static ssize_t unusable_show(struct f2fs_attr *a,
72 struct f2fs_sb_info *sbi, char *buf)
76 if (test_opt(sbi, DISABLE_CHECKPOINT))
77 unusable = sbi->unusable_block_count;
79 unusable = f2fs_get_unusable_blocks(sbi);
80 return snprintf(buf, PAGE_SIZE, "%llu\n",
81 (unsigned long long)unusable);
85 static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
86 struct f2fs_sb_info *sbi, char *buf)
88 struct super_block *sb = sbi->sb;
90 if (!sb->s_bdev->bd_part)
91 return snprintf(buf, PAGE_SIZE, "0\n");
93 return snprintf(buf, PAGE_SIZE, "%llu\n",
94 (unsigned long long)(sbi->kbytes_written +
95 BD_PART_WRITTEN(sbi)));
98 static ssize_t features_show(struct f2fs_attr *a,
99 struct f2fs_sb_info *sbi, char *buf)
101 struct super_block *sb = sbi->sb;
104 if (!sb->s_bdev->bd_part)
105 return snprintf(buf, PAGE_SIZE, "0\n");
107 if (f2fs_sb_has_encrypt(sbi))
108 len += snprintf(buf, PAGE_SIZE - len, "%s",
110 if (f2fs_sb_has_blkzoned(sbi))
111 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
112 len ? ", " : "", "blkzoned");
113 if (f2fs_sb_has_extra_attr(sbi))
114 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
115 len ? ", " : "", "extra_attr");
116 if (f2fs_sb_has_project_quota(sbi))
117 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
118 len ? ", " : "", "projquota");
119 if (f2fs_sb_has_inode_chksum(sbi))
120 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
121 len ? ", " : "", "inode_checksum");
122 if (f2fs_sb_has_flexible_inline_xattr(sbi))
123 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
124 len ? ", " : "", "flexible_inline_xattr");
125 if (f2fs_sb_has_quota_ino(sbi))
126 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
127 len ? ", " : "", "quota_ino");
128 if (f2fs_sb_has_inode_crtime(sbi))
129 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
130 len ? ", " : "", "inode_crtime");
131 if (f2fs_sb_has_lost_found(sbi))
132 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
133 len ? ", " : "", "lost_found");
134 if (f2fs_sb_has_verity(sbi))
135 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
136 len ? ", " : "", "verity");
137 if (f2fs_sb_has_sb_chksum(sbi))
138 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
139 len ? ", " : "", "sb_checksum");
140 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
144 static ssize_t current_reserved_blocks_show(struct f2fs_attr *a,
145 struct f2fs_sb_info *sbi, char *buf)
147 return snprintf(buf, PAGE_SIZE, "%u\n", sbi->current_reserved_blocks);
150 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
151 struct f2fs_sb_info *sbi, char *buf)
153 unsigned char *ptr = NULL;
156 ptr = __struct_ptr(sbi, a->struct_type);
160 if (!strcmp(a->attr.name, "extension_list")) {
161 __u8 (*extlist)[F2FS_EXTENSION_LEN] =
162 sbi->raw_super->extension_list;
163 int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
164 int hot_count = sbi->raw_super->hot_ext_count;
167 len += snprintf(buf + len, PAGE_SIZE - len,
168 "cold file extension:\n");
169 for (i = 0; i < cold_count; i++)
170 len += snprintf(buf + len, PAGE_SIZE - len, "%s\n",
173 len += snprintf(buf + len, PAGE_SIZE - len,
174 "hot file extension:\n");
175 for (i = cold_count; i < cold_count + hot_count; i++)
176 len += snprintf(buf + len, PAGE_SIZE - len, "%s\n",
181 ui = (unsigned int *)(ptr + a->offset);
183 return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
186 static ssize_t __sbi_store(struct f2fs_attr *a,
187 struct f2fs_sb_info *sbi,
188 const char *buf, size_t count)
195 ptr = __struct_ptr(sbi, a->struct_type);
199 if (!strcmp(a->attr.name, "extension_list")) {
200 const char *name = strim((char *)buf);
201 bool set = true, hot;
203 if (!strncmp(name, "[h]", 3))
205 else if (!strncmp(name, "[c]", 3))
217 if (strlen(name) >= F2FS_EXTENSION_LEN)
220 down_write(&sbi->sb_lock);
222 ret = f2fs_update_extension_list(sbi, name, hot, set);
226 ret = f2fs_commit_super(sbi, false);
228 f2fs_update_extension_list(sbi, name, hot, !set);
230 up_write(&sbi->sb_lock);
231 return ret ? ret : count;
234 ui = (unsigned int *)(ptr + a->offset);
236 ret = kstrtoul(skip_spaces(buf), 0, &t);
239 #ifdef CONFIG_F2FS_FAULT_INJECTION
240 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
242 if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX)
245 if (a->struct_type == RESERVED_BLOCKS) {
246 spin_lock(&sbi->stat_lock);
247 if (t > (unsigned long)(sbi->user_block_count -
248 F2FS_OPTION(sbi).root_reserved_blocks)) {
249 spin_unlock(&sbi->stat_lock);
253 sbi->current_reserved_blocks = min(sbi->reserved_blocks,
254 sbi->user_block_count - valid_user_blocks(sbi));
255 spin_unlock(&sbi->stat_lock);
259 if (!strcmp(a->attr.name, "discard_granularity")) {
260 if (t == 0 || t > MAX_PLIST_NUM)
268 if (!strcmp(a->attr.name, "migration_granularity")) {
269 if (t == 0 || t > sbi->segs_per_sec)
273 if (!strcmp(a->attr.name, "trim_sections"))
276 if (!strcmp(a->attr.name, "gc_urgent")) {
278 sbi->gc_mode = GC_URGENT;
279 if (sbi->gc_thread) {
280 sbi->gc_thread->gc_wake = 1;
281 wake_up_interruptible_all(
282 &sbi->gc_thread->gc_wait_queue_head);
283 wake_up_discard_thread(sbi, true);
286 sbi->gc_mode = GC_NORMAL;
290 if (!strcmp(a->attr.name, "gc_idle")) {
292 sbi->gc_mode = GC_IDLE_CB;
293 else if (t == GC_IDLE_GREEDY)
294 sbi->gc_mode = GC_IDLE_GREEDY;
296 sbi->gc_mode = GC_NORMAL;
301 if (!strcmp(a->attr.name, "iostat_enable")) {
302 sbi->iostat_enable = !!t;
303 if (!sbi->iostat_enable)
304 f2fs_reset_iostat(sbi);
308 *ui = (unsigned int)t;
313 static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
314 struct f2fs_sb_info *sbi,
315 const char *buf, size_t count)
318 bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") ||
319 a->struct_type == GC_THREAD);
322 if (!down_read_trylock(&sbi->sb->s_umount))
325 ret = __sbi_store(a, sbi, buf, count);
327 up_read(&sbi->sb->s_umount);
332 static ssize_t f2fs_attr_show(struct kobject *kobj,
333 struct attribute *attr, char *buf)
335 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
337 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
339 return a->show ? a->show(a, sbi, buf) : 0;
342 static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
343 const char *buf, size_t len)
345 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
347 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
349 return a->store ? a->store(a, sbi, buf, len) : 0;
352 static void f2fs_sb_release(struct kobject *kobj)
354 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
356 complete(&sbi->s_kobj_unregister);
366 FEAT_FLEXIBLE_INLINE_XATTR,
374 static ssize_t f2fs_feature_show(struct f2fs_attr *a,
375 struct f2fs_sb_info *sbi, char *buf)
380 case FEAT_ATOMIC_WRITE:
381 case FEAT_EXTRA_ATTR:
382 case FEAT_PROJECT_QUOTA:
383 case FEAT_INODE_CHECKSUM:
384 case FEAT_FLEXIBLE_INLINE_XATTR:
386 case FEAT_INODE_CRTIME:
387 case FEAT_LOST_FOUND:
389 case FEAT_SB_CHECKSUM:
390 return snprintf(buf, PAGE_SIZE, "supported\n");
395 #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
396 static struct f2fs_attr f2fs_attr_##_name = { \
397 .attr = {.name = __stringify(_name), .mode = _mode }, \
400 .struct_type = _struct_type, \
404 #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
405 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
406 f2fs_sbi_show, f2fs_sbi_store, \
407 offsetof(struct struct_name, elname))
409 #define F2FS_GENERAL_RO_ATTR(name) \
410 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
412 #define F2FS_FEATURE_RO_ATTR(_name, _id) \
413 static struct f2fs_attr f2fs_attr_##_name = { \
414 .attr = {.name = __stringify(_name), .mode = 0444 }, \
415 .show = f2fs_feature_show, \
419 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time,
421 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
422 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
423 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
424 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode);
425 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode);
426 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
427 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
428 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity);
429 F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
430 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
431 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
432 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
433 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
434 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_seq_blocks, min_seq_blocks);
435 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
436 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections);
437 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
438 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
439 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
440 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
441 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, migration_granularity, migration_granularity);
442 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
443 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
444 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
445 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval,
446 interval_time[DISCARD_TIME]);
447 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]);
448 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info,
449 umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]);
450 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
451 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
452 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
453 F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list);
454 #ifdef CONFIG_F2FS_FAULT_INJECTION
455 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
456 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
458 F2FS_GENERAL_RO_ATTR(dirty_segments);
459 F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
460 F2FS_GENERAL_RO_ATTR(features);
461 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
462 F2FS_GENERAL_RO_ATTR(unusable);
464 #ifdef CONFIG_FS_ENCRYPTION
465 F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
467 #ifdef CONFIG_BLK_DEV_ZONED
468 F2FS_FEATURE_RO_ATTR(block_zoned, FEAT_BLKZONED);
470 F2FS_FEATURE_RO_ATTR(atomic_write, FEAT_ATOMIC_WRITE);
471 F2FS_FEATURE_RO_ATTR(extra_attr, FEAT_EXTRA_ATTR);
472 F2FS_FEATURE_RO_ATTR(project_quota, FEAT_PROJECT_QUOTA);
473 F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM);
474 F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR);
475 F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO);
476 F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME);
477 F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND);
478 #ifdef CONFIG_FS_VERITY
479 F2FS_FEATURE_RO_ATTR(verity, FEAT_VERITY);
481 F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM);
483 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
484 static struct attribute *f2fs_attrs[] = {
485 ATTR_LIST(gc_urgent_sleep_time),
486 ATTR_LIST(gc_min_sleep_time),
487 ATTR_LIST(gc_max_sleep_time),
488 ATTR_LIST(gc_no_gc_sleep_time),
490 ATTR_LIST(gc_urgent),
491 ATTR_LIST(reclaim_segments),
492 ATTR_LIST(max_small_discards),
493 ATTR_LIST(discard_granularity),
494 ATTR_LIST(batched_trim_sections),
495 ATTR_LIST(ipu_policy),
496 ATTR_LIST(min_ipu_util),
497 ATTR_LIST(min_fsync_blocks),
498 ATTR_LIST(min_seq_blocks),
499 ATTR_LIST(min_hot_blocks),
500 ATTR_LIST(min_ssr_sections),
501 ATTR_LIST(max_victim_search),
502 ATTR_LIST(migration_granularity),
503 ATTR_LIST(dir_level),
504 ATTR_LIST(ram_thresh),
505 ATTR_LIST(ra_nid_pages),
506 ATTR_LIST(dirty_nats_ratio),
507 ATTR_LIST(cp_interval),
508 ATTR_LIST(idle_interval),
509 ATTR_LIST(discard_idle_interval),
510 ATTR_LIST(gc_idle_interval),
511 ATTR_LIST(umount_discard_timeout),
512 ATTR_LIST(iostat_enable),
513 ATTR_LIST(readdir_ra),
514 ATTR_LIST(gc_pin_file_thresh),
515 ATTR_LIST(extension_list),
516 #ifdef CONFIG_F2FS_FAULT_INJECTION
517 ATTR_LIST(inject_rate),
518 ATTR_LIST(inject_type),
520 ATTR_LIST(dirty_segments),
522 ATTR_LIST(lifetime_write_kbytes),
524 ATTR_LIST(reserved_blocks),
525 ATTR_LIST(current_reserved_blocks),
528 ATTRIBUTE_GROUPS(f2fs);
530 static struct attribute *f2fs_feat_attrs[] = {
531 #ifdef CONFIG_FS_ENCRYPTION
532 ATTR_LIST(encryption),
534 #ifdef CONFIG_BLK_DEV_ZONED
535 ATTR_LIST(block_zoned),
537 ATTR_LIST(atomic_write),
538 ATTR_LIST(extra_attr),
539 ATTR_LIST(project_quota),
540 ATTR_LIST(inode_checksum),
541 ATTR_LIST(flexible_inline_xattr),
542 ATTR_LIST(quota_ino),
543 ATTR_LIST(inode_crtime),
544 ATTR_LIST(lost_found),
545 #ifdef CONFIG_FS_VERITY
548 ATTR_LIST(sb_checksum),
551 ATTRIBUTE_GROUPS(f2fs_feat);
553 static const struct sysfs_ops f2fs_attr_ops = {
554 .show = f2fs_attr_show,
555 .store = f2fs_attr_store,
558 static struct kobj_type f2fs_sb_ktype = {
559 .default_groups = f2fs_groups,
560 .sysfs_ops = &f2fs_attr_ops,
561 .release = f2fs_sb_release,
564 static struct kobj_type f2fs_ktype = {
565 .sysfs_ops = &f2fs_attr_ops,
568 static struct kset f2fs_kset = {
569 .kobj = {.ktype = &f2fs_ktype},
572 static struct kobj_type f2fs_feat_ktype = {
573 .default_groups = f2fs_feat_groups,
574 .sysfs_ops = &f2fs_attr_ops,
577 static struct kobject f2fs_feat = {
581 static int __maybe_unused segment_info_seq_show(struct seq_file *seq,
584 struct super_block *sb = seq->private;
585 struct f2fs_sb_info *sbi = F2FS_SB(sb);
586 unsigned int total_segs =
587 le32_to_cpu(sbi->raw_super->segment_count_main);
590 seq_puts(seq, "format: segment_type|valid_blocks\n"
591 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
593 for (i = 0; i < total_segs; i++) {
594 struct seg_entry *se = get_seg_entry(sbi, i);
597 seq_printf(seq, "%-10d", i);
598 seq_printf(seq, "%d|%-3u", se->type, se->valid_blocks);
599 if ((i % 10) == 9 || i == (total_segs - 1))
608 static int __maybe_unused segment_bits_seq_show(struct seq_file *seq,
611 struct super_block *sb = seq->private;
612 struct f2fs_sb_info *sbi = F2FS_SB(sb);
613 unsigned int total_segs =
614 le32_to_cpu(sbi->raw_super->segment_count_main);
617 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
618 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
620 for (i = 0; i < total_segs; i++) {
621 struct seg_entry *se = get_seg_entry(sbi, i);
623 seq_printf(seq, "%-10d", i);
624 seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks);
625 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
626 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
632 static int __maybe_unused iostat_info_seq_show(struct seq_file *seq,
635 struct super_block *sb = seq->private;
636 struct f2fs_sb_info *sbi = F2FS_SB(sb);
637 time64_t now = ktime_get_real_seconds();
639 if (!sbi->iostat_enable)
642 seq_printf(seq, "time: %-16llu\n", now);
645 seq_printf(seq, "app buffered: %-16llu\n",
646 sbi->write_iostat[APP_BUFFERED_IO]);
647 seq_printf(seq, "app direct: %-16llu\n",
648 sbi->write_iostat[APP_DIRECT_IO]);
649 seq_printf(seq, "app mapped: %-16llu\n",
650 sbi->write_iostat[APP_MAPPED_IO]);
653 seq_printf(seq, "fs data: %-16llu\n",
654 sbi->write_iostat[FS_DATA_IO]);
655 seq_printf(seq, "fs node: %-16llu\n",
656 sbi->write_iostat[FS_NODE_IO]);
657 seq_printf(seq, "fs meta: %-16llu\n",
658 sbi->write_iostat[FS_META_IO]);
659 seq_printf(seq, "fs gc data: %-16llu\n",
660 sbi->write_iostat[FS_GC_DATA_IO]);
661 seq_printf(seq, "fs gc node: %-16llu\n",
662 sbi->write_iostat[FS_GC_NODE_IO]);
663 seq_printf(seq, "fs cp data: %-16llu\n",
664 sbi->write_iostat[FS_CP_DATA_IO]);
665 seq_printf(seq, "fs cp node: %-16llu\n",
666 sbi->write_iostat[FS_CP_NODE_IO]);
667 seq_printf(seq, "fs cp meta: %-16llu\n",
668 sbi->write_iostat[FS_CP_META_IO]);
669 seq_printf(seq, "fs discard: %-16llu\n",
670 sbi->write_iostat[FS_DISCARD]);
675 static int __maybe_unused victim_bits_seq_show(struct seq_file *seq,
678 struct super_block *sb = seq->private;
679 struct f2fs_sb_info *sbi = F2FS_SB(sb);
680 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
683 seq_puts(seq, "format: victim_secmap bitmaps\n");
685 for (i = 0; i < MAIN_SECS(sbi); i++) {
687 seq_printf(seq, "%-10d", i);
688 seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0);
689 if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1))
697 int __init f2fs_init_sysfs(void)
701 kobject_set_name(&f2fs_kset.kobj, "f2fs");
702 f2fs_kset.kobj.parent = fs_kobj;
703 ret = kset_register(&f2fs_kset);
707 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
710 kset_unregister(&f2fs_kset);
712 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
716 void f2fs_exit_sysfs(void)
718 kobject_put(&f2fs_feat);
719 kset_unregister(&f2fs_kset);
720 remove_proc_entry("fs/f2fs", NULL);
721 f2fs_proc_root = NULL;
724 int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
726 struct super_block *sb = sbi->sb;
729 sbi->s_kobj.kset = &f2fs_kset;
730 init_completion(&sbi->s_kobj_unregister);
731 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
737 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
740 proc_create_single_data("segment_info", S_IRUGO, sbi->s_proc,
741 segment_info_seq_show, sb);
742 proc_create_single_data("segment_bits", S_IRUGO, sbi->s_proc,
743 segment_bits_seq_show, sb);
744 proc_create_single_data("iostat_info", S_IRUGO, sbi->s_proc,
745 iostat_info_seq_show, sb);
746 proc_create_single_data("victim_bits", S_IRUGO, sbi->s_proc,
747 victim_bits_seq_show, sb);
752 void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
755 remove_proc_entry("iostat_info", sbi->s_proc);
756 remove_proc_entry("segment_info", sbi->s_proc);
757 remove_proc_entry("segment_bits", sbi->s_proc);
758 remove_proc_entry("victim_bits", sbi->s_proc);
759 remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
761 kobject_del(&sbi->s_kobj);