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 lifetime_write_kbytes_show(struct f2fs_attr *a,
72 struct f2fs_sb_info *sbi, char *buf)
74 struct super_block *sb = sbi->sb;
76 if (!sb->s_bdev->bd_part)
77 return snprintf(buf, PAGE_SIZE, "0\n");
79 return snprintf(buf, PAGE_SIZE, "%llu\n",
80 (unsigned long long)(sbi->kbytes_written +
81 BD_PART_WRITTEN(sbi)));
84 static ssize_t features_show(struct f2fs_attr *a,
85 struct f2fs_sb_info *sbi, char *buf)
87 struct super_block *sb = sbi->sb;
90 if (!sb->s_bdev->bd_part)
91 return snprintf(buf, PAGE_SIZE, "0\n");
93 if (f2fs_sb_has_encrypt(sb))
94 len += snprintf(buf, PAGE_SIZE - len, "%s",
96 if (f2fs_sb_has_blkzoned(sb))
97 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
98 len ? ", " : "", "blkzoned");
99 if (f2fs_sb_has_extra_attr(sb))
100 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
101 len ? ", " : "", "extra_attr");
102 if (f2fs_sb_has_project_quota(sb))
103 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
104 len ? ", " : "", "projquota");
105 if (f2fs_sb_has_inode_chksum(sb))
106 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
107 len ? ", " : "", "inode_checksum");
108 if (f2fs_sb_has_flexible_inline_xattr(sb))
109 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
110 len ? ", " : "", "flexible_inline_xattr");
111 if (f2fs_sb_has_quota_ino(sb))
112 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
113 len ? ", " : "", "quota_ino");
114 if (f2fs_sb_has_inode_crtime(sb))
115 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
116 len ? ", " : "", "inode_crtime");
117 if (f2fs_sb_has_lost_found(sb))
118 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
119 len ? ", " : "", "lost_found");
120 if (f2fs_sb_has_sb_chksum(sb))
121 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
122 len ? ", " : "", "sb_checksum");
123 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
127 static ssize_t current_reserved_blocks_show(struct f2fs_attr *a,
128 struct f2fs_sb_info *sbi, char *buf)
130 return snprintf(buf, PAGE_SIZE, "%u\n", sbi->current_reserved_blocks);
133 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
134 struct f2fs_sb_info *sbi, char *buf)
136 unsigned char *ptr = NULL;
139 ptr = __struct_ptr(sbi, a->struct_type);
143 if (!strcmp(a->attr.name, "extension_list")) {
144 __u8 (*extlist)[F2FS_EXTENSION_LEN] =
145 sbi->raw_super->extension_list;
146 int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
147 int hot_count = sbi->raw_super->hot_ext_count;
150 len += snprintf(buf + len, PAGE_SIZE - len,
151 "cold file extension:\n");
152 for (i = 0; i < cold_count; i++)
153 len += snprintf(buf + len, PAGE_SIZE - len, "%s\n",
156 len += snprintf(buf + len, PAGE_SIZE - len,
157 "hot file extension:\n");
158 for (i = cold_count; i < cold_count + hot_count; i++)
159 len += snprintf(buf + len, PAGE_SIZE - len, "%s\n",
164 ui = (unsigned int *)(ptr + a->offset);
166 return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
169 static ssize_t __sbi_store(struct f2fs_attr *a,
170 struct f2fs_sb_info *sbi,
171 const char *buf, size_t count)
178 ptr = __struct_ptr(sbi, a->struct_type);
182 if (!strcmp(a->attr.name, "extension_list")) {
183 const char *name = strim((char *)buf);
184 bool set = true, hot;
186 if (!strncmp(name, "[h]", 3))
188 else if (!strncmp(name, "[c]", 3))
200 if (strlen(name) >= F2FS_EXTENSION_LEN)
203 down_write(&sbi->sb_lock);
205 ret = f2fs_update_extension_list(sbi, name, hot, set);
209 ret = f2fs_commit_super(sbi, false);
211 f2fs_update_extension_list(sbi, name, hot, !set);
213 up_write(&sbi->sb_lock);
214 return ret ? ret : count;
217 ui = (unsigned int *)(ptr + a->offset);
219 ret = kstrtoul(skip_spaces(buf), 0, &t);
222 #ifdef CONFIG_F2FS_FAULT_INJECTION
223 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
226 if (a->struct_type == RESERVED_BLOCKS) {
227 spin_lock(&sbi->stat_lock);
228 if (t > (unsigned long)(sbi->user_block_count -
229 F2FS_OPTION(sbi).root_reserved_blocks)) {
230 spin_unlock(&sbi->stat_lock);
234 sbi->current_reserved_blocks = min(sbi->reserved_blocks,
235 sbi->user_block_count - valid_user_blocks(sbi));
236 spin_unlock(&sbi->stat_lock);
240 if (!strcmp(a->attr.name, "discard_granularity")) {
241 if (t == 0 || t > MAX_PLIST_NUM)
249 if (!strcmp(a->attr.name, "trim_sections"))
252 if (!strcmp(a->attr.name, "gc_urgent")) {
254 sbi->gc_mode = GC_URGENT;
255 if (sbi->gc_thread) {
256 sbi->gc_thread->gc_wake = 1;
257 wake_up_interruptible_all(
258 &sbi->gc_thread->gc_wait_queue_head);
259 wake_up_discard_thread(sbi, true);
262 sbi->gc_mode = GC_NORMAL;
266 if (!strcmp(a->attr.name, "gc_idle")) {
268 sbi->gc_mode = GC_IDLE_CB;
269 else if (t == GC_IDLE_GREEDY)
270 sbi->gc_mode = GC_IDLE_GREEDY;
272 sbi->gc_mode = GC_NORMAL;
278 if (!strcmp(a->attr.name, "iostat_enable") && *ui == 0)
279 f2fs_reset_iostat(sbi);
283 static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
284 struct f2fs_sb_info *sbi,
285 const char *buf, size_t count)
288 bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") ||
289 a->struct_type == GC_THREAD);
292 if (!down_read_trylock(&sbi->sb->s_umount))
295 ret = __sbi_store(a, sbi, buf, count);
297 up_read(&sbi->sb->s_umount);
302 static ssize_t f2fs_attr_show(struct kobject *kobj,
303 struct attribute *attr, char *buf)
305 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
307 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
309 return a->show ? a->show(a, sbi, buf) : 0;
312 static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
313 const char *buf, size_t len)
315 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
317 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
319 return a->store ? a->store(a, sbi, buf, len) : 0;
322 static void f2fs_sb_release(struct kobject *kobj)
324 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
326 complete(&sbi->s_kobj_unregister);
336 FEAT_FLEXIBLE_INLINE_XATTR,
343 static ssize_t f2fs_feature_show(struct f2fs_attr *a,
344 struct f2fs_sb_info *sbi, char *buf)
349 case FEAT_ATOMIC_WRITE:
350 case FEAT_EXTRA_ATTR:
351 case FEAT_PROJECT_QUOTA:
352 case FEAT_INODE_CHECKSUM:
353 case FEAT_FLEXIBLE_INLINE_XATTR:
355 case FEAT_INODE_CRTIME:
356 case FEAT_LOST_FOUND:
357 case FEAT_SB_CHECKSUM:
358 return snprintf(buf, PAGE_SIZE, "supported\n");
363 #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
364 static struct f2fs_attr f2fs_attr_##_name = { \
365 .attr = {.name = __stringify(_name), .mode = _mode }, \
368 .struct_type = _struct_type, \
372 #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
373 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
374 f2fs_sbi_show, f2fs_sbi_store, \
375 offsetof(struct struct_name, elname))
377 #define F2FS_GENERAL_RO_ATTR(name) \
378 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
380 #define F2FS_FEATURE_RO_ATTR(_name, _id) \
381 static struct f2fs_attr f2fs_attr_##_name = { \
382 .attr = {.name = __stringify(_name), .mode = 0444 }, \
383 .show = f2fs_feature_show, \
387 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time,
389 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
390 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
391 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
392 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode);
393 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode);
394 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
395 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
396 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity);
397 F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
398 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
399 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
400 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
401 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
402 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_seq_blocks, min_seq_blocks);
403 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
404 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections);
405 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
406 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
407 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
408 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
409 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
410 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
411 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
412 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval,
413 interval_time[DISCARD_TIME]);
414 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]);
415 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
416 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
417 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
418 F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list);
419 #ifdef CONFIG_F2FS_FAULT_INJECTION
420 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
421 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
423 F2FS_GENERAL_RO_ATTR(dirty_segments);
424 F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
425 F2FS_GENERAL_RO_ATTR(features);
426 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
428 #ifdef CONFIG_F2FS_FS_ENCRYPTION
429 F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
431 #ifdef CONFIG_BLK_DEV_ZONED
432 F2FS_FEATURE_RO_ATTR(block_zoned, FEAT_BLKZONED);
434 F2FS_FEATURE_RO_ATTR(atomic_write, FEAT_ATOMIC_WRITE);
435 F2FS_FEATURE_RO_ATTR(extra_attr, FEAT_EXTRA_ATTR);
436 F2FS_FEATURE_RO_ATTR(project_quota, FEAT_PROJECT_QUOTA);
437 F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM);
438 F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR);
439 F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO);
440 F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME);
441 F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND);
442 F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM);
444 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
445 static struct attribute *f2fs_attrs[] = {
446 ATTR_LIST(gc_urgent_sleep_time),
447 ATTR_LIST(gc_min_sleep_time),
448 ATTR_LIST(gc_max_sleep_time),
449 ATTR_LIST(gc_no_gc_sleep_time),
451 ATTR_LIST(gc_urgent),
452 ATTR_LIST(reclaim_segments),
453 ATTR_LIST(max_small_discards),
454 ATTR_LIST(discard_granularity),
455 ATTR_LIST(batched_trim_sections),
456 ATTR_LIST(ipu_policy),
457 ATTR_LIST(min_ipu_util),
458 ATTR_LIST(min_fsync_blocks),
459 ATTR_LIST(min_seq_blocks),
460 ATTR_LIST(min_hot_blocks),
461 ATTR_LIST(min_ssr_sections),
462 ATTR_LIST(max_victim_search),
463 ATTR_LIST(dir_level),
464 ATTR_LIST(ram_thresh),
465 ATTR_LIST(ra_nid_pages),
466 ATTR_LIST(dirty_nats_ratio),
467 ATTR_LIST(cp_interval),
468 ATTR_LIST(idle_interval),
469 ATTR_LIST(discard_idle_interval),
470 ATTR_LIST(gc_idle_interval),
471 ATTR_LIST(iostat_enable),
472 ATTR_LIST(readdir_ra),
473 ATTR_LIST(gc_pin_file_thresh),
474 ATTR_LIST(extension_list),
475 #ifdef CONFIG_F2FS_FAULT_INJECTION
476 ATTR_LIST(inject_rate),
477 ATTR_LIST(inject_type),
479 ATTR_LIST(dirty_segments),
480 ATTR_LIST(lifetime_write_kbytes),
482 ATTR_LIST(reserved_blocks),
483 ATTR_LIST(current_reserved_blocks),
487 static struct attribute *f2fs_feat_attrs[] = {
488 #ifdef CONFIG_F2FS_FS_ENCRYPTION
489 ATTR_LIST(encryption),
491 #ifdef CONFIG_BLK_DEV_ZONED
492 ATTR_LIST(block_zoned),
494 ATTR_LIST(atomic_write),
495 ATTR_LIST(extra_attr),
496 ATTR_LIST(project_quota),
497 ATTR_LIST(inode_checksum),
498 ATTR_LIST(flexible_inline_xattr),
499 ATTR_LIST(quota_ino),
500 ATTR_LIST(inode_crtime),
501 ATTR_LIST(lost_found),
502 ATTR_LIST(sb_checksum),
506 static const struct sysfs_ops f2fs_attr_ops = {
507 .show = f2fs_attr_show,
508 .store = f2fs_attr_store,
511 static struct kobj_type f2fs_sb_ktype = {
512 .default_attrs = f2fs_attrs,
513 .sysfs_ops = &f2fs_attr_ops,
514 .release = f2fs_sb_release,
517 static struct kobj_type f2fs_ktype = {
518 .sysfs_ops = &f2fs_attr_ops,
521 static struct kset f2fs_kset = {
522 .kobj = {.ktype = &f2fs_ktype},
525 static struct kobj_type f2fs_feat_ktype = {
526 .default_attrs = f2fs_feat_attrs,
527 .sysfs_ops = &f2fs_attr_ops,
530 static struct kobject f2fs_feat = {
534 static int __maybe_unused segment_info_seq_show(struct seq_file *seq,
537 struct super_block *sb = seq->private;
538 struct f2fs_sb_info *sbi = F2FS_SB(sb);
539 unsigned int total_segs =
540 le32_to_cpu(sbi->raw_super->segment_count_main);
543 seq_puts(seq, "format: segment_type|valid_blocks\n"
544 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
546 for (i = 0; i < total_segs; i++) {
547 struct seg_entry *se = get_seg_entry(sbi, i);
550 seq_printf(seq, "%-10d", i);
551 seq_printf(seq, "%d|%-3u", se->type,
552 get_valid_blocks(sbi, i, false));
553 if ((i % 10) == 9 || i == (total_segs - 1))
562 static int __maybe_unused segment_bits_seq_show(struct seq_file *seq,
565 struct super_block *sb = seq->private;
566 struct f2fs_sb_info *sbi = F2FS_SB(sb);
567 unsigned int total_segs =
568 le32_to_cpu(sbi->raw_super->segment_count_main);
571 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
572 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
574 for (i = 0; i < total_segs; i++) {
575 struct seg_entry *se = get_seg_entry(sbi, i);
577 seq_printf(seq, "%-10d", i);
578 seq_printf(seq, "%d|%-3u|", se->type,
579 get_valid_blocks(sbi, i, false));
580 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
581 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
587 static int __maybe_unused iostat_info_seq_show(struct seq_file *seq,
590 struct super_block *sb = seq->private;
591 struct f2fs_sb_info *sbi = F2FS_SB(sb);
592 time64_t now = ktime_get_real_seconds();
594 if (!sbi->iostat_enable)
597 seq_printf(seq, "time: %-16llu\n", now);
600 seq_printf(seq, "app buffered: %-16llu\n",
601 sbi->write_iostat[APP_BUFFERED_IO]);
602 seq_printf(seq, "app direct: %-16llu\n",
603 sbi->write_iostat[APP_DIRECT_IO]);
604 seq_printf(seq, "app mapped: %-16llu\n",
605 sbi->write_iostat[APP_MAPPED_IO]);
608 seq_printf(seq, "fs data: %-16llu\n",
609 sbi->write_iostat[FS_DATA_IO]);
610 seq_printf(seq, "fs node: %-16llu\n",
611 sbi->write_iostat[FS_NODE_IO]);
612 seq_printf(seq, "fs meta: %-16llu\n",
613 sbi->write_iostat[FS_META_IO]);
614 seq_printf(seq, "fs gc data: %-16llu\n",
615 sbi->write_iostat[FS_GC_DATA_IO]);
616 seq_printf(seq, "fs gc node: %-16llu\n",
617 sbi->write_iostat[FS_GC_NODE_IO]);
618 seq_printf(seq, "fs cp data: %-16llu\n",
619 sbi->write_iostat[FS_CP_DATA_IO]);
620 seq_printf(seq, "fs cp node: %-16llu\n",
621 sbi->write_iostat[FS_CP_NODE_IO]);
622 seq_printf(seq, "fs cp meta: %-16llu\n",
623 sbi->write_iostat[FS_CP_META_IO]);
624 seq_printf(seq, "fs discard: %-16llu\n",
625 sbi->write_iostat[FS_DISCARD]);
630 static int __maybe_unused victim_bits_seq_show(struct seq_file *seq,
633 struct super_block *sb = seq->private;
634 struct f2fs_sb_info *sbi = F2FS_SB(sb);
635 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
638 seq_puts(seq, "format: victim_secmap bitmaps\n");
640 for (i = 0; i < MAIN_SECS(sbi); i++) {
642 seq_printf(seq, "%-10d", i);
643 seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0);
644 if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1))
652 int __init f2fs_init_sysfs(void)
656 kobject_set_name(&f2fs_kset.kobj, "f2fs");
657 f2fs_kset.kobj.parent = fs_kobj;
658 ret = kset_register(&f2fs_kset);
662 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
665 kset_unregister(&f2fs_kset);
667 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
671 void f2fs_exit_sysfs(void)
673 kobject_put(&f2fs_feat);
674 kset_unregister(&f2fs_kset);
675 remove_proc_entry("fs/f2fs", NULL);
676 f2fs_proc_root = NULL;
679 int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
681 struct super_block *sb = sbi->sb;
684 sbi->s_kobj.kset = &f2fs_kset;
685 init_completion(&sbi->s_kobj_unregister);
686 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
692 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
695 proc_create_single_data("segment_info", S_IRUGO, sbi->s_proc,
696 segment_info_seq_show, sb);
697 proc_create_single_data("segment_bits", S_IRUGO, sbi->s_proc,
698 segment_bits_seq_show, sb);
699 proc_create_single_data("iostat_info", S_IRUGO, sbi->s_proc,
700 iostat_info_seq_show, sb);
701 proc_create_single_data("victim_bits", S_IRUGO, sbi->s_proc,
702 victim_bits_seq_show, sb);
707 void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
710 remove_proc_entry("iostat_info", sbi->s_proc);
711 remove_proc_entry("segment_info", sbi->s_proc);
712 remove_proc_entry("segment_bits", sbi->s_proc);
713 remove_proc_entry("victim_bits", sbi->s_proc);
714 remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
716 kobject_del(&sbi->s_kobj);