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>
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 *, struct f2fs_sb_info *, char *);
57 ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *,
58 const char *, size_t);
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 sprintf(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 sprintf(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 sprintf(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 sprintf(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 sprintf(buf, "%lx\n", sbi->s_flag);
131 static ssize_t pending_discard_show(struct f2fs_attr *a,
132 struct f2fs_sb_info *sbi, char *buf)
134 if (!SM_I(sbi)->dcc_info)
136 return sprintf(buf, "%llu\n", (unsigned long long)atomic_read(
137 &SM_I(sbi)->dcc_info->discard_cmd_cnt));
140 static ssize_t features_show(struct f2fs_attr *a,
141 struct f2fs_sb_info *sbi, char *buf)
145 if (f2fs_sb_has_encrypt(sbi))
146 len += scnprintf(buf, PAGE_SIZE - len, "%s",
148 if (f2fs_sb_has_blkzoned(sbi))
149 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
150 len ? ", " : "", "blkzoned");
151 if (f2fs_sb_has_extra_attr(sbi))
152 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
153 len ? ", " : "", "extra_attr");
154 if (f2fs_sb_has_project_quota(sbi))
155 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
156 len ? ", " : "", "projquota");
157 if (f2fs_sb_has_inode_chksum(sbi))
158 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
159 len ? ", " : "", "inode_checksum");
160 if (f2fs_sb_has_flexible_inline_xattr(sbi))
161 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
162 len ? ", " : "", "flexible_inline_xattr");
163 if (f2fs_sb_has_quota_ino(sbi))
164 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
165 len ? ", " : "", "quota_ino");
166 if (f2fs_sb_has_inode_crtime(sbi))
167 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
168 len ? ", " : "", "inode_crtime");
169 if (f2fs_sb_has_lost_found(sbi))
170 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
171 len ? ", " : "", "lost_found");
172 if (f2fs_sb_has_verity(sbi))
173 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
174 len ? ", " : "", "verity");
175 if (f2fs_sb_has_sb_chksum(sbi))
176 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
177 len ? ", " : "", "sb_checksum");
178 if (f2fs_sb_has_casefold(sbi))
179 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
180 len ? ", " : "", "casefold");
181 if (f2fs_sb_has_readonly(sbi))
182 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
183 len ? ", " : "", "readonly");
184 if (f2fs_sb_has_compression(sbi))
185 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
186 len ? ", " : "", "compression");
187 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
188 len ? ", " : "", "pin_file");
189 len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
193 static ssize_t current_reserved_blocks_show(struct f2fs_attr *a,
194 struct f2fs_sb_info *sbi, char *buf)
196 return sprintf(buf, "%u\n", sbi->current_reserved_blocks);
199 static ssize_t unusable_show(struct f2fs_attr *a,
200 struct f2fs_sb_info *sbi, char *buf)
204 if (test_opt(sbi, DISABLE_CHECKPOINT))
205 unusable = sbi->unusable_block_count;
207 unusable = f2fs_get_unusable_blocks(sbi);
208 return sprintf(buf, "%llu\n", (unsigned long long)unusable);
211 static ssize_t encoding_show(struct f2fs_attr *a,
212 struct f2fs_sb_info *sbi, char *buf)
214 #if IS_ENABLED(CONFIG_UNICODE)
215 struct super_block *sb = sbi->sb;
217 if (f2fs_sb_has_casefold(sbi))
218 return sysfs_emit(buf, "UTF-8 (%d.%d.%d)\n",
219 (sb->s_encoding->version >> 16) & 0xff,
220 (sb->s_encoding->version >> 8) & 0xff,
221 sb->s_encoding->version & 0xff);
223 return sprintf(buf, "(none)");
226 static ssize_t mounted_time_sec_show(struct f2fs_attr *a,
227 struct f2fs_sb_info *sbi, char *buf)
229 return sprintf(buf, "%llu", SIT_I(sbi)->mounted_time);
232 #ifdef CONFIG_F2FS_STAT_FS
233 static ssize_t moved_blocks_foreground_show(struct f2fs_attr *a,
234 struct f2fs_sb_info *sbi, char *buf)
236 struct f2fs_stat_info *si = F2FS_STAT(sbi);
238 return sprintf(buf, "%llu\n",
239 (unsigned long long)(si->tot_blks -
240 (si->bg_data_blks + si->bg_node_blks)));
243 static ssize_t moved_blocks_background_show(struct f2fs_attr *a,
244 struct f2fs_sb_info *sbi, char *buf)
246 struct f2fs_stat_info *si = F2FS_STAT(sbi);
248 return sprintf(buf, "%llu\n",
249 (unsigned long long)(si->bg_data_blks + si->bg_node_blks));
252 static ssize_t avg_vblocks_show(struct f2fs_attr *a,
253 struct f2fs_sb_info *sbi, char *buf)
255 struct f2fs_stat_info *si = F2FS_STAT(sbi);
257 si->dirty_count = dirty_segments(sbi);
258 f2fs_update_sit_info(sbi);
259 return sprintf(buf, "%llu\n", (unsigned long long)(si->avg_vblocks));
263 static ssize_t main_blkaddr_show(struct f2fs_attr *a,
264 struct f2fs_sb_info *sbi, char *buf)
266 return sysfs_emit(buf, "%llu\n",
267 (unsigned long long)MAIN_BLKADDR(sbi));
270 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
271 struct f2fs_sb_info *sbi, char *buf)
273 unsigned char *ptr = NULL;
276 ptr = __struct_ptr(sbi, a->struct_type);
280 if (!strcmp(a->attr.name, "extension_list")) {
281 __u8 (*extlist)[F2FS_EXTENSION_LEN] =
282 sbi->raw_super->extension_list;
283 int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
284 int hot_count = sbi->raw_super->hot_ext_count;
287 len += scnprintf(buf + len, PAGE_SIZE - len,
288 "cold file extension:\n");
289 for (i = 0; i < cold_count; i++)
290 len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n",
293 len += scnprintf(buf + len, PAGE_SIZE - len,
294 "hot file extension:\n");
295 for (i = cold_count; i < cold_count + hot_count; i++)
296 len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n",
301 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
302 struct ckpt_req_control *cprc = &sbi->cprc_info;
304 int class = IOPRIO_PRIO_CLASS(cprc->ckpt_thread_ioprio);
305 int data = IOPRIO_PRIO_DATA(cprc->ckpt_thread_ioprio);
307 if (class == IOPRIO_CLASS_RT)
308 len += scnprintf(buf + len, PAGE_SIZE - len, "rt,");
309 else if (class == IOPRIO_CLASS_BE)
310 len += scnprintf(buf + len, PAGE_SIZE - len, "be,");
314 len += scnprintf(buf + len, PAGE_SIZE - len, "%d\n", data);
318 #ifdef CONFIG_F2FS_FS_COMPRESSION
319 if (!strcmp(a->attr.name, "compr_written_block"))
320 return sysfs_emit(buf, "%llu\n", sbi->compr_written_block);
322 if (!strcmp(a->attr.name, "compr_saved_block"))
323 return sysfs_emit(buf, "%llu\n", sbi->compr_saved_block);
325 if (!strcmp(a->attr.name, "compr_new_inode"))
326 return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
329 if (!strcmp(a->attr.name, "gc_urgent"))
330 return sysfs_emit(buf, "%s\n",
331 gc_mode_names[sbi->gc_mode]);
333 if (!strcmp(a->attr.name, "gc_segment_mode"))
334 return sysfs_emit(buf, "%s\n",
335 gc_mode_names[sbi->gc_segment_mode]);
337 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
338 return sysfs_emit(buf, "%u\n",
339 sbi->gc_reclaimed_segs[sbi->gc_segment_mode]);
342 if (!strcmp(a->attr.name, "current_atomic_write")) {
343 s64 current_write = atomic64_read(&sbi->current_atomic_write);
345 return sysfs_emit(buf, "%lld\n", current_write);
348 if (!strcmp(a->attr.name, "peak_atomic_write"))
349 return sysfs_emit(buf, "%lld\n", sbi->peak_atomic_write);
351 if (!strcmp(a->attr.name, "committed_atomic_block"))
352 return sysfs_emit(buf, "%llu\n", sbi->committed_atomic_block);
354 if (!strcmp(a->attr.name, "revoked_atomic_block"))
355 return sysfs_emit(buf, "%llu\n", sbi->revoked_atomic_block);
357 ui = (unsigned int *)(ptr + a->offset);
359 return sprintf(buf, "%u\n", *ui);
362 static ssize_t __sbi_store(struct f2fs_attr *a,
363 struct f2fs_sb_info *sbi,
364 const char *buf, size_t count)
371 ptr = __struct_ptr(sbi, a->struct_type);
375 if (!strcmp(a->attr.name, "extension_list")) {
376 const char *name = strim((char *)buf);
377 bool set = true, hot;
379 if (!strncmp(name, "[h]", 3))
381 else if (!strncmp(name, "[c]", 3))
393 if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN)
396 f2fs_down_write(&sbi->sb_lock);
398 ret = f2fs_update_extension_list(sbi, name, hot, set);
402 ret = f2fs_commit_super(sbi, false);
404 f2fs_update_extension_list(sbi, name, hot, !set);
406 f2fs_up_write(&sbi->sb_lock);
407 return ret ? ret : count;
410 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
411 const char *name = strim((char *)buf);
412 struct ckpt_req_control *cprc = &sbi->cprc_info;
417 if (!strncmp(name, "rt,", 3))
418 class = IOPRIO_CLASS_RT;
419 else if (!strncmp(name, "be,", 3))
420 class = IOPRIO_CLASS_BE;
425 ret = kstrtol(name, 10, &data);
428 if (data >= IOPRIO_NR_LEVELS || data < 0)
431 cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, data);
432 if (test_opt(sbi, MERGE_CHECKPOINT)) {
433 ret = set_task_ioprio(cprc->f2fs_issue_ckpt,
434 cprc->ckpt_thread_ioprio);
442 ui = (unsigned int *)(ptr + a->offset);
444 ret = kstrtoul(skip_spaces(buf), 0, &t);
447 #ifdef CONFIG_F2FS_FAULT_INJECTION
448 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
450 if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX)
453 if (a->struct_type == RESERVED_BLOCKS) {
454 spin_lock(&sbi->stat_lock);
455 if (t > (unsigned long)(sbi->user_block_count -
456 F2FS_OPTION(sbi).root_reserved_blocks -
457 sbi->blocks_per_seg *
458 SM_I(sbi)->additional_reserved_segments)) {
459 spin_unlock(&sbi->stat_lock);
463 sbi->current_reserved_blocks = min(sbi->reserved_blocks,
464 sbi->user_block_count - valid_user_blocks(sbi));
465 spin_unlock(&sbi->stat_lock);
469 if (!strcmp(a->attr.name, "discard_granularity")) {
470 if (t == 0 || t > MAX_PLIST_NUM)
472 if (!f2fs_block_unit_discard(sbi))
480 if (!strcmp(a->attr.name, "migration_granularity")) {
481 if (t == 0 || t > sbi->segs_per_sec)
485 if (!strcmp(a->attr.name, "trim_sections"))
488 if (!strcmp(a->attr.name, "gc_urgent")) {
490 sbi->gc_mode = GC_NORMAL;
492 sbi->gc_mode = GC_URGENT_HIGH;
493 if (sbi->gc_thread) {
494 sbi->gc_thread->gc_wake = 1;
495 wake_up_interruptible_all(
496 &sbi->gc_thread->gc_wait_queue_head);
497 wake_up_discard_thread(sbi, true);
500 sbi->gc_mode = GC_URGENT_LOW;
502 sbi->gc_mode = GC_URGENT_MID;
503 if (sbi->gc_thread) {
504 sbi->gc_thread->gc_wake = 1;
505 wake_up_interruptible_all(
506 &sbi->gc_thread->gc_wait_queue_head);
513 if (!strcmp(a->attr.name, "gc_idle")) {
514 if (t == GC_IDLE_CB) {
515 sbi->gc_mode = GC_IDLE_CB;
516 } else if (t == GC_IDLE_GREEDY) {
517 sbi->gc_mode = GC_IDLE_GREEDY;
518 } else if (t == GC_IDLE_AT) {
519 if (!sbi->am.atgc_enabled)
521 sbi->gc_mode = GC_IDLE_AT;
523 sbi->gc_mode = GC_NORMAL;
528 if (!strcmp(a->attr.name, "gc_urgent_high_remaining")) {
529 spin_lock(&sbi->gc_urgent_high_lock);
530 sbi->gc_urgent_high_limited = t != 0;
531 sbi->gc_urgent_high_remaining = t;
532 spin_unlock(&sbi->gc_urgent_high_lock);
537 #ifdef CONFIG_F2FS_IOSTAT
538 if (!strcmp(a->attr.name, "iostat_enable")) {
539 sbi->iostat_enable = !!t;
540 if (!sbi->iostat_enable)
541 f2fs_reset_iostat(sbi);
545 if (!strcmp(a->attr.name, "iostat_period_ms")) {
546 if (t < MIN_IOSTAT_PERIOD_MS || t > MAX_IOSTAT_PERIOD_MS)
548 spin_lock(&sbi->iostat_lock);
549 sbi->iostat_period_ms = (unsigned int)t;
550 spin_unlock(&sbi->iostat_lock);
555 #ifdef CONFIG_F2FS_FS_COMPRESSION
556 if (!strcmp(a->attr.name, "compr_written_block") ||
557 !strcmp(a->attr.name, "compr_saved_block")) {
560 sbi->compr_written_block = 0;
561 sbi->compr_saved_block = 0;
565 if (!strcmp(a->attr.name, "compr_new_inode")) {
568 sbi->compr_new_inode = 0;
573 if (!strcmp(a->attr.name, "atgc_candidate_ratio")) {
576 sbi->am.candidate_ratio = t;
580 if (!strcmp(a->attr.name, "atgc_age_weight")) {
583 sbi->am.age_weight = t;
587 if (!strcmp(a->attr.name, "gc_segment_mode")) {
589 sbi->gc_segment_mode = t;
595 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
598 sbi->gc_reclaimed_segs[sbi->gc_segment_mode] = 0;
602 if (!strcmp(a->attr.name, "seq_file_ra_mul")) {
603 if (t >= MIN_RA_MUL && t <= MAX_RA_MUL)
604 sbi->seq_file_ra_mul = t;
610 if (!strcmp(a->attr.name, "max_fragment_chunk")) {
611 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE)
612 sbi->max_fragment_chunk = t;
618 if (!strcmp(a->attr.name, "max_fragment_hole")) {
619 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE)
620 sbi->max_fragment_hole = t;
626 if (!strcmp(a->attr.name, "peak_atomic_write")) {
629 sbi->peak_atomic_write = 0;
633 if (!strcmp(a->attr.name, "committed_atomic_block")) {
636 sbi->committed_atomic_block = 0;
640 if (!strcmp(a->attr.name, "revoked_atomic_block")) {
643 sbi->revoked_atomic_block = 0;
647 *ui = (unsigned int)t;
652 static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
653 struct f2fs_sb_info *sbi,
654 const char *buf, size_t count)
657 bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") ||
658 a->struct_type == GC_THREAD);
661 if (!down_read_trylock(&sbi->sb->s_umount))
664 ret = __sbi_store(a, sbi, buf, count);
666 up_read(&sbi->sb->s_umount);
671 static ssize_t f2fs_attr_show(struct kobject *kobj,
672 struct attribute *attr, char *buf)
674 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
676 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
678 return a->show ? a->show(a, sbi, buf) : 0;
681 static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
682 const char *buf, size_t len)
684 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
686 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
688 return a->store ? a->store(a, sbi, buf, len) : 0;
691 static void f2fs_sb_release(struct kobject *kobj)
693 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
695 complete(&sbi->s_kobj_unregister);
699 * Note that there are three feature list entries:
700 * 1) /sys/fs/f2fs/features
701 * : shows runtime features supported by in-kernel f2fs along with Kconfig.
702 * - ref. F2FS_FEATURE_RO_ATTR()
704 * 2) /sys/fs/f2fs/$s_id/features <deprecated>
705 * : shows on-disk features enabled by mkfs.f2fs, used for old kernels. This
706 * won't add new feature anymore, and thus, users should check entries in 3)
707 * instead of this 2).
709 * 3) /sys/fs/f2fs/$s_id/feature_list
710 * : shows on-disk features enabled by mkfs.f2fs per instance, which follows
711 * sysfs entry rule where each entry should expose single value.
712 * This list covers old feature list provided by 2) and beyond. Therefore,
713 * please add new on-disk feature in this list only.
714 * - ref. F2FS_SB_FEATURE_RO_ATTR()
716 static ssize_t f2fs_feature_show(struct f2fs_attr *a,
717 struct f2fs_sb_info *sbi, char *buf)
719 return sprintf(buf, "supported\n");
722 #define F2FS_FEATURE_RO_ATTR(_name) \
723 static struct f2fs_attr f2fs_attr_##_name = { \
724 .attr = {.name = __stringify(_name), .mode = 0444 }, \
725 .show = f2fs_feature_show, \
728 static ssize_t f2fs_sb_feature_show(struct f2fs_attr *a,
729 struct f2fs_sb_info *sbi, char *buf)
731 if (F2FS_HAS_FEATURE(sbi, a->id))
732 return sprintf(buf, "supported\n");
733 return sprintf(buf, "unsupported\n");
736 #define F2FS_SB_FEATURE_RO_ATTR(_name, _feat) \
737 static struct f2fs_attr f2fs_attr_sb_##_name = { \
738 .attr = {.name = __stringify(_name), .mode = 0444 }, \
739 .show = f2fs_sb_feature_show, \
740 .id = F2FS_FEATURE_##_feat, \
743 #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
744 static struct f2fs_attr f2fs_attr_##_name = { \
745 .attr = {.name = __stringify(_name), .mode = _mode }, \
748 .struct_type = _struct_type, \
752 #define F2FS_RO_ATTR(struct_type, struct_name, name, elname) \
753 F2FS_ATTR_OFFSET(struct_type, name, 0444, \
754 f2fs_sbi_show, NULL, \
755 offsetof(struct struct_name, elname))
757 #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
758 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
759 f2fs_sbi_show, f2fs_sbi_store, \
760 offsetof(struct struct_name, elname))
762 #define F2FS_GENERAL_RO_ATTR(name) \
763 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
765 #define F2FS_STAT_ATTR(_struct_type, _struct_name, _name, _elname) \
766 static struct f2fs_attr f2fs_attr_##_name = { \
767 .attr = {.name = __stringify(_name), .mode = 0444 }, \
768 .show = f2fs_sbi_show, \
769 .struct_type = _struct_type, \
770 .offset = offsetof(struct _struct_name, _elname), \
773 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time,
775 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
776 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
777 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
778 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode);
779 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode);
780 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
781 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
782 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_request, max_discard_request);
783 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, min_discard_issue_time, min_discard_issue_time);
784 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, mid_discard_issue_time, mid_discard_issue_time);
785 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_issue_time, max_discard_issue_time);
786 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity);
787 F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
788 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
789 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
790 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
791 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
792 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_seq_blocks, min_seq_blocks);
793 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
794 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections);
795 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
796 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
797 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
798 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, max_roll_forward_node_blocks, max_rf_node_blocks);
799 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
800 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, migration_granularity, migration_granularity);
801 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
802 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
803 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
804 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval,
805 interval_time[DISCARD_TIME]);
806 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]);
807 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info,
808 umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]);
809 #ifdef CONFIG_F2FS_IOSTAT
810 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
811 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_period_ms, iostat_period_ms);
813 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
814 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_io_bytes, max_io_bytes);
815 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
816 F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list);
817 #ifdef CONFIG_F2FS_FAULT_INJECTION
818 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
819 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
821 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, data_io_flag, data_io_flag);
822 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, node_io_flag, node_io_flag);
823 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent_high_remaining, gc_urgent_high_remaining);
824 F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, ckpt_thread_ioprio, ckpt_thread_ioprio);
825 F2FS_GENERAL_RO_ATTR(dirty_segments);
826 F2FS_GENERAL_RO_ATTR(free_segments);
827 F2FS_GENERAL_RO_ATTR(ovp_segments);
828 F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
829 F2FS_GENERAL_RO_ATTR(features);
830 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
831 F2FS_GENERAL_RO_ATTR(unusable);
832 F2FS_GENERAL_RO_ATTR(encoding);
833 F2FS_GENERAL_RO_ATTR(mounted_time_sec);
834 F2FS_GENERAL_RO_ATTR(main_blkaddr);
835 F2FS_GENERAL_RO_ATTR(pending_discard);
836 #ifdef CONFIG_F2FS_STAT_FS
837 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count);
838 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count);
839 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_foreground_calls, call_count);
840 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_background_calls, bg_gc);
841 F2FS_GENERAL_RO_ATTR(moved_blocks_background);
842 F2FS_GENERAL_RO_ATTR(moved_blocks_foreground);
843 F2FS_GENERAL_RO_ATTR(avg_vblocks);
846 #ifdef CONFIG_FS_ENCRYPTION
847 F2FS_FEATURE_RO_ATTR(encryption);
848 F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2);
849 #if IS_ENABLED(CONFIG_UNICODE)
850 F2FS_FEATURE_RO_ATTR(encrypted_casefold);
852 #endif /* CONFIG_FS_ENCRYPTION */
853 #ifdef CONFIG_BLK_DEV_ZONED
854 F2FS_FEATURE_RO_ATTR(block_zoned);
855 F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, unusable_blocks_per_sec,
856 unusable_blocks_per_sec);
858 F2FS_FEATURE_RO_ATTR(atomic_write);
859 F2FS_FEATURE_RO_ATTR(extra_attr);
860 F2FS_FEATURE_RO_ATTR(project_quota);
861 F2FS_FEATURE_RO_ATTR(inode_checksum);
862 F2FS_FEATURE_RO_ATTR(flexible_inline_xattr);
863 F2FS_FEATURE_RO_ATTR(quota_ino);
864 F2FS_FEATURE_RO_ATTR(inode_crtime);
865 F2FS_FEATURE_RO_ATTR(lost_found);
866 #ifdef CONFIG_FS_VERITY
867 F2FS_FEATURE_RO_ATTR(verity);
869 F2FS_FEATURE_RO_ATTR(sb_checksum);
870 #if IS_ENABLED(CONFIG_UNICODE)
871 F2FS_FEATURE_RO_ATTR(casefold);
873 F2FS_FEATURE_RO_ATTR(readonly);
874 #ifdef CONFIG_F2FS_FS_COMPRESSION
875 F2FS_FEATURE_RO_ATTR(compression);
876 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block);
877 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block);
878 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode);
880 F2FS_FEATURE_RO_ATTR(pin_file);
883 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio);
884 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count);
885 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
886 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
888 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, seq_file_ra_mul, seq_file_ra_mul);
889 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_segment_mode, gc_segment_mode);
890 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_reclaimed_segments, gc_reclaimed_segs);
891 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_chunk, max_fragment_chunk);
892 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_hole, max_fragment_hole);
894 /* For atomic write */
895 F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, current_atomic_write, current_atomic_write);
896 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, peak_atomic_write, peak_atomic_write);
897 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, committed_atomic_block, committed_atomic_block);
898 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block);
900 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
901 static struct attribute *f2fs_attrs[] = {
902 ATTR_LIST(gc_urgent_sleep_time),
903 ATTR_LIST(gc_min_sleep_time),
904 ATTR_LIST(gc_max_sleep_time),
905 ATTR_LIST(gc_no_gc_sleep_time),
907 ATTR_LIST(gc_urgent),
908 ATTR_LIST(reclaim_segments),
909 ATTR_LIST(main_blkaddr),
910 ATTR_LIST(max_small_discards),
911 ATTR_LIST(max_discard_request),
912 ATTR_LIST(min_discard_issue_time),
913 ATTR_LIST(mid_discard_issue_time),
914 ATTR_LIST(max_discard_issue_time),
915 ATTR_LIST(discard_granularity),
916 ATTR_LIST(pending_discard),
917 ATTR_LIST(batched_trim_sections),
918 ATTR_LIST(ipu_policy),
919 ATTR_LIST(min_ipu_util),
920 ATTR_LIST(min_fsync_blocks),
921 ATTR_LIST(min_seq_blocks),
922 ATTR_LIST(min_hot_blocks),
923 ATTR_LIST(min_ssr_sections),
924 ATTR_LIST(max_victim_search),
925 ATTR_LIST(migration_granularity),
926 ATTR_LIST(dir_level),
927 ATTR_LIST(ram_thresh),
928 ATTR_LIST(ra_nid_pages),
929 ATTR_LIST(dirty_nats_ratio),
930 ATTR_LIST(max_roll_forward_node_blocks),
931 ATTR_LIST(cp_interval),
932 ATTR_LIST(idle_interval),
933 ATTR_LIST(discard_idle_interval),
934 ATTR_LIST(gc_idle_interval),
935 ATTR_LIST(umount_discard_timeout),
936 #ifdef CONFIG_F2FS_IOSTAT
937 ATTR_LIST(iostat_enable),
938 ATTR_LIST(iostat_period_ms),
940 ATTR_LIST(readdir_ra),
941 ATTR_LIST(max_io_bytes),
942 ATTR_LIST(gc_pin_file_thresh),
943 ATTR_LIST(extension_list),
944 #ifdef CONFIG_F2FS_FAULT_INJECTION
945 ATTR_LIST(inject_rate),
946 ATTR_LIST(inject_type),
948 ATTR_LIST(data_io_flag),
949 ATTR_LIST(node_io_flag),
950 ATTR_LIST(gc_urgent_high_remaining),
951 ATTR_LIST(ckpt_thread_ioprio),
952 ATTR_LIST(dirty_segments),
953 ATTR_LIST(free_segments),
954 ATTR_LIST(ovp_segments),
956 ATTR_LIST(lifetime_write_kbytes),
958 ATTR_LIST(reserved_blocks),
959 ATTR_LIST(current_reserved_blocks),
961 ATTR_LIST(mounted_time_sec),
962 #ifdef CONFIG_F2FS_STAT_FS
963 ATTR_LIST(cp_foreground_calls),
964 ATTR_LIST(cp_background_calls),
965 ATTR_LIST(gc_foreground_calls),
966 ATTR_LIST(gc_background_calls),
967 ATTR_LIST(moved_blocks_foreground),
968 ATTR_LIST(moved_blocks_background),
969 ATTR_LIST(avg_vblocks),
971 #ifdef CONFIG_BLK_DEV_ZONED
972 ATTR_LIST(unusable_blocks_per_sec),
974 #ifdef CONFIG_F2FS_FS_COMPRESSION
975 ATTR_LIST(compr_written_block),
976 ATTR_LIST(compr_saved_block),
977 ATTR_LIST(compr_new_inode),
980 ATTR_LIST(atgc_candidate_ratio),
981 ATTR_LIST(atgc_candidate_count),
982 ATTR_LIST(atgc_age_weight),
983 ATTR_LIST(atgc_age_threshold),
984 ATTR_LIST(seq_file_ra_mul),
985 ATTR_LIST(gc_segment_mode),
986 ATTR_LIST(gc_reclaimed_segments),
987 ATTR_LIST(max_fragment_chunk),
988 ATTR_LIST(max_fragment_hole),
989 ATTR_LIST(current_atomic_write),
990 ATTR_LIST(peak_atomic_write),
991 ATTR_LIST(committed_atomic_block),
992 ATTR_LIST(revoked_atomic_block),
995 ATTRIBUTE_GROUPS(f2fs);
997 static struct attribute *f2fs_feat_attrs[] = {
998 #ifdef CONFIG_FS_ENCRYPTION
999 ATTR_LIST(encryption),
1000 ATTR_LIST(test_dummy_encryption_v2),
1001 #if IS_ENABLED(CONFIG_UNICODE)
1002 ATTR_LIST(encrypted_casefold),
1004 #endif /* CONFIG_FS_ENCRYPTION */
1005 #ifdef CONFIG_BLK_DEV_ZONED
1006 ATTR_LIST(block_zoned),
1008 ATTR_LIST(atomic_write),
1009 ATTR_LIST(extra_attr),
1010 ATTR_LIST(project_quota),
1011 ATTR_LIST(inode_checksum),
1012 ATTR_LIST(flexible_inline_xattr),
1013 ATTR_LIST(quota_ino),
1014 ATTR_LIST(inode_crtime),
1015 ATTR_LIST(lost_found),
1016 #ifdef CONFIG_FS_VERITY
1019 ATTR_LIST(sb_checksum),
1020 #if IS_ENABLED(CONFIG_UNICODE)
1021 ATTR_LIST(casefold),
1023 ATTR_LIST(readonly),
1024 #ifdef CONFIG_F2FS_FS_COMPRESSION
1025 ATTR_LIST(compression),
1027 ATTR_LIST(pin_file),
1030 ATTRIBUTE_GROUPS(f2fs_feat);
1032 F2FS_GENERAL_RO_ATTR(sb_status);
1033 static struct attribute *f2fs_stat_attrs[] = {
1034 ATTR_LIST(sb_status),
1037 ATTRIBUTE_GROUPS(f2fs_stat);
1039 F2FS_SB_FEATURE_RO_ATTR(encryption, ENCRYPT);
1040 F2FS_SB_FEATURE_RO_ATTR(block_zoned, BLKZONED);
1041 F2FS_SB_FEATURE_RO_ATTR(extra_attr, EXTRA_ATTR);
1042 F2FS_SB_FEATURE_RO_ATTR(project_quota, PRJQUOTA);
1043 F2FS_SB_FEATURE_RO_ATTR(inode_checksum, INODE_CHKSUM);
1044 F2FS_SB_FEATURE_RO_ATTR(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
1045 F2FS_SB_FEATURE_RO_ATTR(quota_ino, QUOTA_INO);
1046 F2FS_SB_FEATURE_RO_ATTR(inode_crtime, INODE_CRTIME);
1047 F2FS_SB_FEATURE_RO_ATTR(lost_found, LOST_FOUND);
1048 F2FS_SB_FEATURE_RO_ATTR(verity, VERITY);
1049 F2FS_SB_FEATURE_RO_ATTR(sb_checksum, SB_CHKSUM);
1050 F2FS_SB_FEATURE_RO_ATTR(casefold, CASEFOLD);
1051 F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION);
1052 F2FS_SB_FEATURE_RO_ATTR(readonly, RO);
1054 static struct attribute *f2fs_sb_feat_attrs[] = {
1055 ATTR_LIST(sb_encryption),
1056 ATTR_LIST(sb_block_zoned),
1057 ATTR_LIST(sb_extra_attr),
1058 ATTR_LIST(sb_project_quota),
1059 ATTR_LIST(sb_inode_checksum),
1060 ATTR_LIST(sb_flexible_inline_xattr),
1061 ATTR_LIST(sb_quota_ino),
1062 ATTR_LIST(sb_inode_crtime),
1063 ATTR_LIST(sb_lost_found),
1064 ATTR_LIST(sb_verity),
1065 ATTR_LIST(sb_sb_checksum),
1066 ATTR_LIST(sb_casefold),
1067 ATTR_LIST(sb_compression),
1068 ATTR_LIST(sb_readonly),
1071 ATTRIBUTE_GROUPS(f2fs_sb_feat);
1073 static const struct sysfs_ops f2fs_attr_ops = {
1074 .show = f2fs_attr_show,
1075 .store = f2fs_attr_store,
1078 static struct kobj_type f2fs_sb_ktype = {
1079 .default_groups = f2fs_groups,
1080 .sysfs_ops = &f2fs_attr_ops,
1081 .release = f2fs_sb_release,
1084 static struct kobj_type f2fs_ktype = {
1085 .sysfs_ops = &f2fs_attr_ops,
1088 static struct kset f2fs_kset = {
1089 .kobj = {.ktype = &f2fs_ktype},
1092 static struct kobj_type f2fs_feat_ktype = {
1093 .default_groups = f2fs_feat_groups,
1094 .sysfs_ops = &f2fs_attr_ops,
1097 static struct kobject f2fs_feat = {
1101 static ssize_t f2fs_stat_attr_show(struct kobject *kobj,
1102 struct attribute *attr, char *buf)
1104 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1106 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1108 return a->show ? a->show(a, sbi, buf) : 0;
1111 static ssize_t f2fs_stat_attr_store(struct kobject *kobj, struct attribute *attr,
1112 const char *buf, size_t len)
1114 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1116 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1118 return a->store ? a->store(a, sbi, buf, len) : 0;
1121 static void f2fs_stat_kobj_release(struct kobject *kobj)
1123 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1125 complete(&sbi->s_stat_kobj_unregister);
1128 static const struct sysfs_ops f2fs_stat_attr_ops = {
1129 .show = f2fs_stat_attr_show,
1130 .store = f2fs_stat_attr_store,
1133 static struct kobj_type f2fs_stat_ktype = {
1134 .default_groups = f2fs_stat_groups,
1135 .sysfs_ops = &f2fs_stat_attr_ops,
1136 .release = f2fs_stat_kobj_release,
1139 static ssize_t f2fs_sb_feat_attr_show(struct kobject *kobj,
1140 struct attribute *attr, char *buf)
1142 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1143 s_feature_list_kobj);
1144 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1146 return a->show ? a->show(a, sbi, buf) : 0;
1149 static void f2fs_feature_list_kobj_release(struct kobject *kobj)
1151 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1152 s_feature_list_kobj);
1153 complete(&sbi->s_feature_list_kobj_unregister);
1156 static const struct sysfs_ops f2fs_feature_list_attr_ops = {
1157 .show = f2fs_sb_feat_attr_show,
1160 static struct kobj_type f2fs_feature_list_ktype = {
1161 .default_groups = f2fs_sb_feat_groups,
1162 .sysfs_ops = &f2fs_feature_list_attr_ops,
1163 .release = f2fs_feature_list_kobj_release,
1166 static int __maybe_unused segment_info_seq_show(struct seq_file *seq,
1169 struct super_block *sb = seq->private;
1170 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1171 unsigned int total_segs =
1172 le32_to_cpu(sbi->raw_super->segment_count_main);
1175 seq_puts(seq, "format: segment_type|valid_blocks\n"
1176 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1178 for (i = 0; i < total_segs; i++) {
1179 struct seg_entry *se = get_seg_entry(sbi, i);
1182 seq_printf(seq, "%-10d", i);
1183 seq_printf(seq, "%d|%-3u", se->type, se->valid_blocks);
1184 if ((i % 10) == 9 || i == (total_segs - 1))
1185 seq_putc(seq, '\n');
1193 static int __maybe_unused segment_bits_seq_show(struct seq_file *seq,
1196 struct super_block *sb = seq->private;
1197 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1198 unsigned int total_segs =
1199 le32_to_cpu(sbi->raw_super->segment_count_main);
1202 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
1203 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1205 for (i = 0; i < total_segs; i++) {
1206 struct seg_entry *se = get_seg_entry(sbi, i);
1208 seq_printf(seq, "%-10d", i);
1209 seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks);
1210 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
1211 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
1212 seq_putc(seq, '\n');
1217 static int __maybe_unused victim_bits_seq_show(struct seq_file *seq,
1220 struct super_block *sb = seq->private;
1221 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1222 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
1225 seq_puts(seq, "format: victim_secmap bitmaps\n");
1227 for (i = 0; i < MAIN_SECS(sbi); i++) {
1229 seq_printf(seq, "%-10d", i);
1230 seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0);
1231 if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1))
1232 seq_putc(seq, '\n');
1239 int __init f2fs_init_sysfs(void)
1243 kobject_set_name(&f2fs_kset.kobj, "f2fs");
1244 f2fs_kset.kobj.parent = fs_kobj;
1245 ret = kset_register(&f2fs_kset);
1249 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
1252 kobject_put(&f2fs_feat);
1253 kset_unregister(&f2fs_kset);
1255 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
1260 void f2fs_exit_sysfs(void)
1262 kobject_put(&f2fs_feat);
1263 kset_unregister(&f2fs_kset);
1264 remove_proc_entry("fs/f2fs", NULL);
1265 f2fs_proc_root = NULL;
1268 int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
1270 struct super_block *sb = sbi->sb;
1273 sbi->s_kobj.kset = &f2fs_kset;
1274 init_completion(&sbi->s_kobj_unregister);
1275 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
1280 sbi->s_stat_kobj.kset = &f2fs_kset;
1281 init_completion(&sbi->s_stat_kobj_unregister);
1282 err = kobject_init_and_add(&sbi->s_stat_kobj, &f2fs_stat_ktype,
1283 &sbi->s_kobj, "stat");
1287 sbi->s_feature_list_kobj.kset = &f2fs_kset;
1288 init_completion(&sbi->s_feature_list_kobj_unregister);
1289 err = kobject_init_and_add(&sbi->s_feature_list_kobj,
1290 &f2fs_feature_list_ktype,
1291 &sbi->s_kobj, "feature_list");
1293 goto put_feature_list_kobj;
1296 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
1299 proc_create_single_data("segment_info", 0444, sbi->s_proc,
1300 segment_info_seq_show, sb);
1301 proc_create_single_data("segment_bits", 0444, sbi->s_proc,
1302 segment_bits_seq_show, sb);
1303 #ifdef CONFIG_F2FS_IOSTAT
1304 proc_create_single_data("iostat_info", 0444, sbi->s_proc,
1305 iostat_info_seq_show, sb);
1307 proc_create_single_data("victim_bits", 0444, sbi->s_proc,
1308 victim_bits_seq_show, sb);
1311 put_feature_list_kobj:
1312 kobject_put(&sbi->s_feature_list_kobj);
1313 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1315 kobject_put(&sbi->s_stat_kobj);
1316 wait_for_completion(&sbi->s_stat_kobj_unregister);
1318 kobject_put(&sbi->s_kobj);
1319 wait_for_completion(&sbi->s_kobj_unregister);
1323 void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
1326 #ifdef CONFIG_F2FS_IOSTAT
1327 remove_proc_entry("iostat_info", sbi->s_proc);
1329 remove_proc_entry("segment_info", sbi->s_proc);
1330 remove_proc_entry("segment_bits", sbi->s_proc);
1331 remove_proc_entry("victim_bits", sbi->s_proc);
1332 remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
1335 kobject_del(&sbi->s_stat_kobj);
1336 kobject_put(&sbi->s_stat_kobj);
1337 wait_for_completion(&sbi->s_stat_kobj_unregister);
1338 kobject_del(&sbi->s_feature_list_kobj);
1339 kobject_put(&sbi->s_feature_list_kobj);
1340 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1342 kobject_del(&sbi->s_kobj);
1343 kobject_put(&sbi->s_kobj);
1344 wait_for_completion(&sbi->s_kobj_unregister);