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 cp_status_show(struct f2fs_attr *a,
132 struct f2fs_sb_info *sbi, char *buf)
134 return sprintf(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 sprintf(buf, "%llu\n", (unsigned long long)atomic_read(
143 &SM_I(sbi)->dcc_info->discard_cmd_cnt));
146 static ssize_t features_show(struct f2fs_attr *a,
147 struct f2fs_sb_info *sbi, char *buf)
151 if (f2fs_sb_has_encrypt(sbi))
152 len += scnprintf(buf, PAGE_SIZE - len, "%s",
154 if (f2fs_sb_has_blkzoned(sbi))
155 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
156 len ? ", " : "", "blkzoned");
157 if (f2fs_sb_has_extra_attr(sbi))
158 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
159 len ? ", " : "", "extra_attr");
160 if (f2fs_sb_has_project_quota(sbi))
161 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
162 len ? ", " : "", "projquota");
163 if (f2fs_sb_has_inode_chksum(sbi))
164 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
165 len ? ", " : "", "inode_checksum");
166 if (f2fs_sb_has_flexible_inline_xattr(sbi))
167 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
168 len ? ", " : "", "flexible_inline_xattr");
169 if (f2fs_sb_has_quota_ino(sbi))
170 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
171 len ? ", " : "", "quota_ino");
172 if (f2fs_sb_has_inode_crtime(sbi))
173 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
174 len ? ", " : "", "inode_crtime");
175 if (f2fs_sb_has_lost_found(sbi))
176 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
177 len ? ", " : "", "lost_found");
178 if (f2fs_sb_has_verity(sbi))
179 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
180 len ? ", " : "", "verity");
181 if (f2fs_sb_has_sb_chksum(sbi))
182 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
183 len ? ", " : "", "sb_checksum");
184 if (f2fs_sb_has_casefold(sbi))
185 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
186 len ? ", " : "", "casefold");
187 if (f2fs_sb_has_readonly(sbi))
188 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
189 len ? ", " : "", "readonly");
190 if (f2fs_sb_has_compression(sbi))
191 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
192 len ? ", " : "", "compression");
193 len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s",
194 len ? ", " : "", "pin_file");
195 len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
199 static ssize_t current_reserved_blocks_show(struct f2fs_attr *a,
200 struct f2fs_sb_info *sbi, char *buf)
202 return sprintf(buf, "%u\n", sbi->current_reserved_blocks);
205 static ssize_t unusable_show(struct f2fs_attr *a,
206 struct f2fs_sb_info *sbi, char *buf)
210 if (test_opt(sbi, DISABLE_CHECKPOINT))
211 unusable = sbi->unusable_block_count;
213 unusable = f2fs_get_unusable_blocks(sbi);
214 return sprintf(buf, "%llu\n", (unsigned long long)unusable);
217 static ssize_t encoding_show(struct f2fs_attr *a,
218 struct f2fs_sb_info *sbi, char *buf)
220 #if IS_ENABLED(CONFIG_UNICODE)
221 struct super_block *sb = sbi->sb;
223 if (f2fs_sb_has_casefold(sbi))
224 return sysfs_emit(buf, "UTF-8 (%d.%d.%d)\n",
225 (sb->s_encoding->version >> 16) & 0xff,
226 (sb->s_encoding->version >> 8) & 0xff,
227 sb->s_encoding->version & 0xff);
229 return sprintf(buf, "(none)");
232 static ssize_t mounted_time_sec_show(struct f2fs_attr *a,
233 struct f2fs_sb_info *sbi, char *buf)
235 return sprintf(buf, "%llu", SIT_I(sbi)->mounted_time);
238 #ifdef CONFIG_F2FS_STAT_FS
239 static ssize_t moved_blocks_foreground_show(struct f2fs_attr *a,
240 struct f2fs_sb_info *sbi, char *buf)
242 struct f2fs_stat_info *si = F2FS_STAT(sbi);
244 return sprintf(buf, "%llu\n",
245 (unsigned long long)(si->tot_blks -
246 (si->bg_data_blks + si->bg_node_blks)));
249 static ssize_t moved_blocks_background_show(struct f2fs_attr *a,
250 struct f2fs_sb_info *sbi, char *buf)
252 struct f2fs_stat_info *si = F2FS_STAT(sbi);
254 return sprintf(buf, "%llu\n",
255 (unsigned long long)(si->bg_data_blks + si->bg_node_blks));
258 static ssize_t avg_vblocks_show(struct f2fs_attr *a,
259 struct f2fs_sb_info *sbi, char *buf)
261 struct f2fs_stat_info *si = F2FS_STAT(sbi);
263 si->dirty_count = dirty_segments(sbi);
264 f2fs_update_sit_info(sbi);
265 return sprintf(buf, "%llu\n", (unsigned long long)(si->avg_vblocks));
269 static ssize_t main_blkaddr_show(struct f2fs_attr *a,
270 struct f2fs_sb_info *sbi, char *buf)
272 return sysfs_emit(buf, "%llu\n",
273 (unsigned long long)MAIN_BLKADDR(sbi));
276 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
277 struct f2fs_sb_info *sbi, char *buf)
279 unsigned char *ptr = NULL;
282 ptr = __struct_ptr(sbi, a->struct_type);
286 if (!strcmp(a->attr.name, "extension_list")) {
287 __u8 (*extlist)[F2FS_EXTENSION_LEN] =
288 sbi->raw_super->extension_list;
289 int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
290 int hot_count = sbi->raw_super->hot_ext_count;
293 len += scnprintf(buf + len, PAGE_SIZE - len,
294 "cold file extension:\n");
295 for (i = 0; i < cold_count; i++)
296 len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n",
299 len += scnprintf(buf + len, PAGE_SIZE - len,
300 "hot file extension:\n");
301 for (i = cold_count; i < cold_count + hot_count; i++)
302 len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n",
307 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
308 struct ckpt_req_control *cprc = &sbi->cprc_info;
310 int class = IOPRIO_PRIO_CLASS(cprc->ckpt_thread_ioprio);
311 int data = IOPRIO_PRIO_DATA(cprc->ckpt_thread_ioprio);
313 if (class == IOPRIO_CLASS_RT)
314 len += scnprintf(buf + len, PAGE_SIZE - len, "rt,");
315 else if (class == IOPRIO_CLASS_BE)
316 len += scnprintf(buf + len, PAGE_SIZE - len, "be,");
320 len += scnprintf(buf + len, PAGE_SIZE - len, "%d\n", data);
324 #ifdef CONFIG_F2FS_FS_COMPRESSION
325 if (!strcmp(a->attr.name, "compr_written_block"))
326 return sysfs_emit(buf, "%llu\n", sbi->compr_written_block);
328 if (!strcmp(a->attr.name, "compr_saved_block"))
329 return sysfs_emit(buf, "%llu\n", sbi->compr_saved_block);
331 if (!strcmp(a->attr.name, "compr_new_inode"))
332 return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
335 if (!strcmp(a->attr.name, "gc_urgent"))
336 return sysfs_emit(buf, "%s\n",
337 gc_mode_names[sbi->gc_mode]);
339 if (!strcmp(a->attr.name, "gc_segment_mode"))
340 return sysfs_emit(buf, "%s\n",
341 gc_mode_names[sbi->gc_segment_mode]);
343 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
344 return sysfs_emit(buf, "%u\n",
345 sbi->gc_reclaimed_segs[sbi->gc_segment_mode]);
348 if (!strcmp(a->attr.name, "current_atomic_write")) {
349 s64 current_write = atomic64_read(&sbi->current_atomic_write);
351 return sysfs_emit(buf, "%lld\n", current_write);
354 if (!strcmp(a->attr.name, "peak_atomic_write"))
355 return sysfs_emit(buf, "%lld\n", sbi->peak_atomic_write);
357 if (!strcmp(a->attr.name, "committed_atomic_block"))
358 return sysfs_emit(buf, "%llu\n", sbi->committed_atomic_block);
360 if (!strcmp(a->attr.name, "revoked_atomic_block"))
361 return sysfs_emit(buf, "%llu\n", sbi->revoked_atomic_block);
363 ui = (unsigned int *)(ptr + a->offset);
365 return sprintf(buf, "%u\n", *ui);
368 static ssize_t __sbi_store(struct f2fs_attr *a,
369 struct f2fs_sb_info *sbi,
370 const char *buf, size_t count)
377 ptr = __struct_ptr(sbi, a->struct_type);
381 if (!strcmp(a->attr.name, "extension_list")) {
382 const char *name = strim((char *)buf);
383 bool set = true, hot;
385 if (!strncmp(name, "[h]", 3))
387 else if (!strncmp(name, "[c]", 3))
399 if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN)
402 f2fs_down_write(&sbi->sb_lock);
404 ret = f2fs_update_extension_list(sbi, name, hot, set);
408 ret = f2fs_commit_super(sbi, false);
410 f2fs_update_extension_list(sbi, name, hot, !set);
412 f2fs_up_write(&sbi->sb_lock);
413 return ret ? ret : count;
416 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
417 const char *name = strim((char *)buf);
418 struct ckpt_req_control *cprc = &sbi->cprc_info;
423 if (!strncmp(name, "rt,", 3))
424 class = IOPRIO_CLASS_RT;
425 else if (!strncmp(name, "be,", 3))
426 class = IOPRIO_CLASS_BE;
431 ret = kstrtol(name, 10, &data);
434 if (data >= IOPRIO_NR_LEVELS || data < 0)
437 cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, data);
438 if (test_opt(sbi, MERGE_CHECKPOINT)) {
439 ret = set_task_ioprio(cprc->f2fs_issue_ckpt,
440 cprc->ckpt_thread_ioprio);
448 ui = (unsigned int *)(ptr + a->offset);
450 ret = kstrtoul(skip_spaces(buf), 0, &t);
453 #ifdef CONFIG_F2FS_FAULT_INJECTION
454 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
456 if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX)
459 if (a->struct_type == RESERVED_BLOCKS) {
460 spin_lock(&sbi->stat_lock);
461 if (t > (unsigned long)(sbi->user_block_count -
462 F2FS_OPTION(sbi).root_reserved_blocks -
463 sbi->blocks_per_seg *
464 SM_I(sbi)->additional_reserved_segments)) {
465 spin_unlock(&sbi->stat_lock);
469 sbi->current_reserved_blocks = min(sbi->reserved_blocks,
470 sbi->user_block_count - valid_user_blocks(sbi));
471 spin_unlock(&sbi->stat_lock);
475 if (!strcmp(a->attr.name, "discard_granularity")) {
476 if (t == 0 || t > MAX_PLIST_NUM)
478 if (!f2fs_block_unit_discard(sbi))
486 if (!strcmp(a->attr.name, "migration_granularity")) {
487 if (t == 0 || t > sbi->segs_per_sec)
491 if (!strcmp(a->attr.name, "trim_sections"))
494 if (!strcmp(a->attr.name, "gc_urgent")) {
496 sbi->gc_mode = GC_NORMAL;
498 sbi->gc_mode = GC_URGENT_HIGH;
499 if (sbi->gc_thread) {
500 sbi->gc_thread->gc_wake = 1;
501 wake_up_interruptible_all(
502 &sbi->gc_thread->gc_wait_queue_head);
503 wake_up_discard_thread(sbi, true);
506 sbi->gc_mode = GC_URGENT_LOW;
508 sbi->gc_mode = GC_URGENT_MID;
509 if (sbi->gc_thread) {
510 sbi->gc_thread->gc_wake = 1;
511 wake_up_interruptible_all(
512 &sbi->gc_thread->gc_wait_queue_head);
519 if (!strcmp(a->attr.name, "gc_idle")) {
520 if (t == GC_IDLE_CB) {
521 sbi->gc_mode = GC_IDLE_CB;
522 } else if (t == GC_IDLE_GREEDY) {
523 sbi->gc_mode = GC_IDLE_GREEDY;
524 } else if (t == GC_IDLE_AT) {
525 if (!sbi->am.atgc_enabled)
527 sbi->gc_mode = GC_IDLE_AT;
529 sbi->gc_mode = GC_NORMAL;
534 if (!strcmp(a->attr.name, "gc_urgent_high_remaining")) {
535 spin_lock(&sbi->gc_urgent_high_lock);
536 sbi->gc_urgent_high_remaining = t;
537 spin_unlock(&sbi->gc_urgent_high_lock);
542 #ifdef CONFIG_F2FS_IOSTAT
543 if (!strcmp(a->attr.name, "iostat_enable")) {
544 sbi->iostat_enable = !!t;
545 if (!sbi->iostat_enable)
546 f2fs_reset_iostat(sbi);
550 if (!strcmp(a->attr.name, "iostat_period_ms")) {
551 if (t < MIN_IOSTAT_PERIOD_MS || t > MAX_IOSTAT_PERIOD_MS)
553 spin_lock(&sbi->iostat_lock);
554 sbi->iostat_period_ms = (unsigned int)t;
555 spin_unlock(&sbi->iostat_lock);
560 #ifdef CONFIG_F2FS_FS_COMPRESSION
561 if (!strcmp(a->attr.name, "compr_written_block") ||
562 !strcmp(a->attr.name, "compr_saved_block")) {
565 sbi->compr_written_block = 0;
566 sbi->compr_saved_block = 0;
570 if (!strcmp(a->attr.name, "compr_new_inode")) {
573 sbi->compr_new_inode = 0;
578 if (!strcmp(a->attr.name, "atgc_candidate_ratio")) {
581 sbi->am.candidate_ratio = t;
585 if (!strcmp(a->attr.name, "atgc_age_weight")) {
588 sbi->am.age_weight = t;
592 if (!strcmp(a->attr.name, "gc_segment_mode")) {
594 sbi->gc_segment_mode = t;
600 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
603 sbi->gc_reclaimed_segs[sbi->gc_segment_mode] = 0;
607 if (!strcmp(a->attr.name, "seq_file_ra_mul")) {
608 if (t >= MIN_RA_MUL && t <= MAX_RA_MUL)
609 sbi->seq_file_ra_mul = t;
615 if (!strcmp(a->attr.name, "max_fragment_chunk")) {
616 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE)
617 sbi->max_fragment_chunk = t;
623 if (!strcmp(a->attr.name, "max_fragment_hole")) {
624 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE)
625 sbi->max_fragment_hole = t;
631 if (!strcmp(a->attr.name, "peak_atomic_write")) {
634 sbi->peak_atomic_write = 0;
638 if (!strcmp(a->attr.name, "committed_atomic_block")) {
641 sbi->committed_atomic_block = 0;
645 if (!strcmp(a->attr.name, "revoked_atomic_block")) {
648 sbi->revoked_atomic_block = 0;
652 *ui = (unsigned int)t;
657 static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
658 struct f2fs_sb_info *sbi,
659 const char *buf, size_t count)
662 bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") ||
663 a->struct_type == GC_THREAD);
666 if (!down_read_trylock(&sbi->sb->s_umount))
669 ret = __sbi_store(a, sbi, buf, count);
671 up_read(&sbi->sb->s_umount);
676 static ssize_t f2fs_attr_show(struct kobject *kobj,
677 struct attribute *attr, char *buf)
679 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
681 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
683 return a->show ? a->show(a, sbi, buf) : 0;
686 static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
687 const char *buf, size_t len)
689 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
691 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
693 return a->store ? a->store(a, sbi, buf, len) : 0;
696 static void f2fs_sb_release(struct kobject *kobj)
698 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
700 complete(&sbi->s_kobj_unregister);
704 * Note that there are three feature list entries:
705 * 1) /sys/fs/f2fs/features
706 * : shows runtime features supported by in-kernel f2fs along with Kconfig.
707 * - ref. F2FS_FEATURE_RO_ATTR()
709 * 2) /sys/fs/f2fs/$s_id/features <deprecated>
710 * : shows on-disk features enabled by mkfs.f2fs, used for old kernels. This
711 * won't add new feature anymore, and thus, users should check entries in 3)
712 * instead of this 2).
714 * 3) /sys/fs/f2fs/$s_id/feature_list
715 * : shows on-disk features enabled by mkfs.f2fs per instance, which follows
716 * sysfs entry rule where each entry should expose single value.
717 * This list covers old feature list provided by 2) and beyond. Therefore,
718 * please add new on-disk feature in this list only.
719 * - ref. F2FS_SB_FEATURE_RO_ATTR()
721 static ssize_t f2fs_feature_show(struct f2fs_attr *a,
722 struct f2fs_sb_info *sbi, char *buf)
724 return sprintf(buf, "supported\n");
727 #define F2FS_FEATURE_RO_ATTR(_name) \
728 static struct f2fs_attr f2fs_attr_##_name = { \
729 .attr = {.name = __stringify(_name), .mode = 0444 }, \
730 .show = f2fs_feature_show, \
733 static ssize_t f2fs_sb_feature_show(struct f2fs_attr *a,
734 struct f2fs_sb_info *sbi, char *buf)
736 if (F2FS_HAS_FEATURE(sbi, a->id))
737 return sprintf(buf, "supported\n");
738 return sprintf(buf, "unsupported\n");
741 #define F2FS_SB_FEATURE_RO_ATTR(_name, _feat) \
742 static struct f2fs_attr f2fs_attr_sb_##_name = { \
743 .attr = {.name = __stringify(_name), .mode = 0444 }, \
744 .show = f2fs_sb_feature_show, \
745 .id = F2FS_FEATURE_##_feat, \
748 #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
749 static struct f2fs_attr f2fs_attr_##_name = { \
750 .attr = {.name = __stringify(_name), .mode = _mode }, \
753 .struct_type = _struct_type, \
757 #define F2FS_RO_ATTR(struct_type, struct_name, name, elname) \
758 F2FS_ATTR_OFFSET(struct_type, name, 0444, \
759 f2fs_sbi_show, NULL, \
760 offsetof(struct struct_name, elname))
762 #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
763 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
764 f2fs_sbi_show, f2fs_sbi_store, \
765 offsetof(struct struct_name, elname))
767 #define F2FS_GENERAL_RO_ATTR(name) \
768 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
770 #define F2FS_STAT_ATTR(_struct_type, _struct_name, _name, _elname) \
771 static struct f2fs_attr f2fs_attr_##_name = { \
772 .attr = {.name = __stringify(_name), .mode = 0444 }, \
773 .show = f2fs_sbi_show, \
774 .struct_type = _struct_type, \
775 .offset = offsetof(struct _struct_name, _elname), \
778 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time,
780 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
781 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
782 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
783 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode);
784 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode);
785 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
786 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
787 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_request, max_discard_request);
788 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, min_discard_issue_time, min_discard_issue_time);
789 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, mid_discard_issue_time, mid_discard_issue_time);
790 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_issue_time, max_discard_issue_time);
791 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity);
792 F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
793 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
794 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
795 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
796 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
797 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_seq_blocks, min_seq_blocks);
798 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
799 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections);
800 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
801 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
802 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
803 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, max_roll_forward_node_blocks, max_rf_node_blocks);
804 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
805 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, migration_granularity, migration_granularity);
806 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
807 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
808 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
809 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval,
810 interval_time[DISCARD_TIME]);
811 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]);
812 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info,
813 umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]);
814 #ifdef CONFIG_F2FS_IOSTAT
815 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
816 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_period_ms, iostat_period_ms);
818 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
819 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_io_bytes, max_io_bytes);
820 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
821 F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list);
822 #ifdef CONFIG_F2FS_FAULT_INJECTION
823 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
824 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
826 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, data_io_flag, data_io_flag);
827 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, node_io_flag, node_io_flag);
828 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent_high_remaining, gc_urgent_high_remaining);
829 F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, ckpt_thread_ioprio, ckpt_thread_ioprio);
830 F2FS_GENERAL_RO_ATTR(dirty_segments);
831 F2FS_GENERAL_RO_ATTR(free_segments);
832 F2FS_GENERAL_RO_ATTR(ovp_segments);
833 F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
834 F2FS_GENERAL_RO_ATTR(features);
835 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
836 F2FS_GENERAL_RO_ATTR(unusable);
837 F2FS_GENERAL_RO_ATTR(encoding);
838 F2FS_GENERAL_RO_ATTR(mounted_time_sec);
839 F2FS_GENERAL_RO_ATTR(main_blkaddr);
840 F2FS_GENERAL_RO_ATTR(pending_discard);
841 #ifdef CONFIG_F2FS_STAT_FS
842 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count);
843 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count);
844 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_foreground_calls, call_count);
845 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_background_calls, bg_gc);
846 F2FS_GENERAL_RO_ATTR(moved_blocks_background);
847 F2FS_GENERAL_RO_ATTR(moved_blocks_foreground);
848 F2FS_GENERAL_RO_ATTR(avg_vblocks);
851 #ifdef CONFIG_FS_ENCRYPTION
852 F2FS_FEATURE_RO_ATTR(encryption);
853 F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2);
854 #if IS_ENABLED(CONFIG_UNICODE)
855 F2FS_FEATURE_RO_ATTR(encrypted_casefold);
857 #endif /* CONFIG_FS_ENCRYPTION */
858 #ifdef CONFIG_BLK_DEV_ZONED
859 F2FS_FEATURE_RO_ATTR(block_zoned);
860 F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, unusable_blocks_per_sec,
861 unusable_blocks_per_sec);
863 F2FS_FEATURE_RO_ATTR(atomic_write);
864 F2FS_FEATURE_RO_ATTR(extra_attr);
865 F2FS_FEATURE_RO_ATTR(project_quota);
866 F2FS_FEATURE_RO_ATTR(inode_checksum);
867 F2FS_FEATURE_RO_ATTR(flexible_inline_xattr);
868 F2FS_FEATURE_RO_ATTR(quota_ino);
869 F2FS_FEATURE_RO_ATTR(inode_crtime);
870 F2FS_FEATURE_RO_ATTR(lost_found);
871 #ifdef CONFIG_FS_VERITY
872 F2FS_FEATURE_RO_ATTR(verity);
874 F2FS_FEATURE_RO_ATTR(sb_checksum);
875 #if IS_ENABLED(CONFIG_UNICODE)
876 F2FS_FEATURE_RO_ATTR(casefold);
878 F2FS_FEATURE_RO_ATTR(readonly);
879 #ifdef CONFIG_F2FS_FS_COMPRESSION
880 F2FS_FEATURE_RO_ATTR(compression);
881 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block);
882 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block);
883 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode);
885 F2FS_FEATURE_RO_ATTR(pin_file);
888 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio);
889 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count);
890 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
891 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
893 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, seq_file_ra_mul, seq_file_ra_mul);
894 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_segment_mode, gc_segment_mode);
895 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_reclaimed_segments, gc_reclaimed_segs);
896 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_chunk, max_fragment_chunk);
897 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_hole, max_fragment_hole);
899 /* For atomic write */
900 F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, current_atomic_write, current_atomic_write);
901 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, peak_atomic_write, peak_atomic_write);
902 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, committed_atomic_block, committed_atomic_block);
903 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block);
905 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
906 static struct attribute *f2fs_attrs[] = {
907 ATTR_LIST(gc_urgent_sleep_time),
908 ATTR_LIST(gc_min_sleep_time),
909 ATTR_LIST(gc_max_sleep_time),
910 ATTR_LIST(gc_no_gc_sleep_time),
912 ATTR_LIST(gc_urgent),
913 ATTR_LIST(reclaim_segments),
914 ATTR_LIST(main_blkaddr),
915 ATTR_LIST(max_small_discards),
916 ATTR_LIST(max_discard_request),
917 ATTR_LIST(min_discard_issue_time),
918 ATTR_LIST(mid_discard_issue_time),
919 ATTR_LIST(max_discard_issue_time),
920 ATTR_LIST(discard_granularity),
921 ATTR_LIST(pending_discard),
922 ATTR_LIST(batched_trim_sections),
923 ATTR_LIST(ipu_policy),
924 ATTR_LIST(min_ipu_util),
925 ATTR_LIST(min_fsync_blocks),
926 ATTR_LIST(min_seq_blocks),
927 ATTR_LIST(min_hot_blocks),
928 ATTR_LIST(min_ssr_sections),
929 ATTR_LIST(max_victim_search),
930 ATTR_LIST(migration_granularity),
931 ATTR_LIST(dir_level),
932 ATTR_LIST(ram_thresh),
933 ATTR_LIST(ra_nid_pages),
934 ATTR_LIST(dirty_nats_ratio),
935 ATTR_LIST(max_roll_forward_node_blocks),
936 ATTR_LIST(cp_interval),
937 ATTR_LIST(idle_interval),
938 ATTR_LIST(discard_idle_interval),
939 ATTR_LIST(gc_idle_interval),
940 ATTR_LIST(umount_discard_timeout),
941 #ifdef CONFIG_F2FS_IOSTAT
942 ATTR_LIST(iostat_enable),
943 ATTR_LIST(iostat_period_ms),
945 ATTR_LIST(readdir_ra),
946 ATTR_LIST(max_io_bytes),
947 ATTR_LIST(gc_pin_file_thresh),
948 ATTR_LIST(extension_list),
949 #ifdef CONFIG_F2FS_FAULT_INJECTION
950 ATTR_LIST(inject_rate),
951 ATTR_LIST(inject_type),
953 ATTR_LIST(data_io_flag),
954 ATTR_LIST(node_io_flag),
955 ATTR_LIST(gc_urgent_high_remaining),
956 ATTR_LIST(ckpt_thread_ioprio),
957 ATTR_LIST(dirty_segments),
958 ATTR_LIST(free_segments),
959 ATTR_LIST(ovp_segments),
961 ATTR_LIST(lifetime_write_kbytes),
963 ATTR_LIST(reserved_blocks),
964 ATTR_LIST(current_reserved_blocks),
966 ATTR_LIST(mounted_time_sec),
967 #ifdef CONFIG_F2FS_STAT_FS
968 ATTR_LIST(cp_foreground_calls),
969 ATTR_LIST(cp_background_calls),
970 ATTR_LIST(gc_foreground_calls),
971 ATTR_LIST(gc_background_calls),
972 ATTR_LIST(moved_blocks_foreground),
973 ATTR_LIST(moved_blocks_background),
974 ATTR_LIST(avg_vblocks),
976 #ifdef CONFIG_BLK_DEV_ZONED
977 ATTR_LIST(unusable_blocks_per_sec),
979 #ifdef CONFIG_F2FS_FS_COMPRESSION
980 ATTR_LIST(compr_written_block),
981 ATTR_LIST(compr_saved_block),
982 ATTR_LIST(compr_new_inode),
985 ATTR_LIST(atgc_candidate_ratio),
986 ATTR_LIST(atgc_candidate_count),
987 ATTR_LIST(atgc_age_weight),
988 ATTR_LIST(atgc_age_threshold),
989 ATTR_LIST(seq_file_ra_mul),
990 ATTR_LIST(gc_segment_mode),
991 ATTR_LIST(gc_reclaimed_segments),
992 ATTR_LIST(max_fragment_chunk),
993 ATTR_LIST(max_fragment_hole),
994 ATTR_LIST(current_atomic_write),
995 ATTR_LIST(peak_atomic_write),
996 ATTR_LIST(committed_atomic_block),
997 ATTR_LIST(revoked_atomic_block),
1000 ATTRIBUTE_GROUPS(f2fs);
1002 static struct attribute *f2fs_feat_attrs[] = {
1003 #ifdef CONFIG_FS_ENCRYPTION
1004 ATTR_LIST(encryption),
1005 ATTR_LIST(test_dummy_encryption_v2),
1006 #if IS_ENABLED(CONFIG_UNICODE)
1007 ATTR_LIST(encrypted_casefold),
1009 #endif /* CONFIG_FS_ENCRYPTION */
1010 #ifdef CONFIG_BLK_DEV_ZONED
1011 ATTR_LIST(block_zoned),
1013 ATTR_LIST(atomic_write),
1014 ATTR_LIST(extra_attr),
1015 ATTR_LIST(project_quota),
1016 ATTR_LIST(inode_checksum),
1017 ATTR_LIST(flexible_inline_xattr),
1018 ATTR_LIST(quota_ino),
1019 ATTR_LIST(inode_crtime),
1020 ATTR_LIST(lost_found),
1021 #ifdef CONFIG_FS_VERITY
1024 ATTR_LIST(sb_checksum),
1025 #if IS_ENABLED(CONFIG_UNICODE)
1026 ATTR_LIST(casefold),
1028 ATTR_LIST(readonly),
1029 #ifdef CONFIG_F2FS_FS_COMPRESSION
1030 ATTR_LIST(compression),
1032 ATTR_LIST(pin_file),
1035 ATTRIBUTE_GROUPS(f2fs_feat);
1037 F2FS_GENERAL_RO_ATTR(sb_status);
1038 F2FS_GENERAL_RO_ATTR(cp_status);
1039 static struct attribute *f2fs_stat_attrs[] = {
1040 ATTR_LIST(sb_status),
1041 ATTR_LIST(cp_status),
1044 ATTRIBUTE_GROUPS(f2fs_stat);
1046 F2FS_SB_FEATURE_RO_ATTR(encryption, ENCRYPT);
1047 F2FS_SB_FEATURE_RO_ATTR(block_zoned, BLKZONED);
1048 F2FS_SB_FEATURE_RO_ATTR(extra_attr, EXTRA_ATTR);
1049 F2FS_SB_FEATURE_RO_ATTR(project_quota, PRJQUOTA);
1050 F2FS_SB_FEATURE_RO_ATTR(inode_checksum, INODE_CHKSUM);
1051 F2FS_SB_FEATURE_RO_ATTR(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
1052 F2FS_SB_FEATURE_RO_ATTR(quota_ino, QUOTA_INO);
1053 F2FS_SB_FEATURE_RO_ATTR(inode_crtime, INODE_CRTIME);
1054 F2FS_SB_FEATURE_RO_ATTR(lost_found, LOST_FOUND);
1055 F2FS_SB_FEATURE_RO_ATTR(verity, VERITY);
1056 F2FS_SB_FEATURE_RO_ATTR(sb_checksum, SB_CHKSUM);
1057 F2FS_SB_FEATURE_RO_ATTR(casefold, CASEFOLD);
1058 F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION);
1059 F2FS_SB_FEATURE_RO_ATTR(readonly, RO);
1061 static struct attribute *f2fs_sb_feat_attrs[] = {
1062 ATTR_LIST(sb_encryption),
1063 ATTR_LIST(sb_block_zoned),
1064 ATTR_LIST(sb_extra_attr),
1065 ATTR_LIST(sb_project_quota),
1066 ATTR_LIST(sb_inode_checksum),
1067 ATTR_LIST(sb_flexible_inline_xattr),
1068 ATTR_LIST(sb_quota_ino),
1069 ATTR_LIST(sb_inode_crtime),
1070 ATTR_LIST(sb_lost_found),
1071 ATTR_LIST(sb_verity),
1072 ATTR_LIST(sb_sb_checksum),
1073 ATTR_LIST(sb_casefold),
1074 ATTR_LIST(sb_compression),
1075 ATTR_LIST(sb_readonly),
1078 ATTRIBUTE_GROUPS(f2fs_sb_feat);
1080 static const struct sysfs_ops f2fs_attr_ops = {
1081 .show = f2fs_attr_show,
1082 .store = f2fs_attr_store,
1085 static struct kobj_type f2fs_sb_ktype = {
1086 .default_groups = f2fs_groups,
1087 .sysfs_ops = &f2fs_attr_ops,
1088 .release = f2fs_sb_release,
1091 static struct kobj_type f2fs_ktype = {
1092 .sysfs_ops = &f2fs_attr_ops,
1095 static struct kset f2fs_kset = {
1096 .kobj = {.ktype = &f2fs_ktype},
1099 static struct kobj_type f2fs_feat_ktype = {
1100 .default_groups = f2fs_feat_groups,
1101 .sysfs_ops = &f2fs_attr_ops,
1104 static struct kobject f2fs_feat = {
1108 static ssize_t f2fs_stat_attr_show(struct kobject *kobj,
1109 struct attribute *attr, char *buf)
1111 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1113 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1115 return a->show ? a->show(a, sbi, buf) : 0;
1118 static ssize_t f2fs_stat_attr_store(struct kobject *kobj, struct attribute *attr,
1119 const char *buf, size_t len)
1121 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1123 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1125 return a->store ? a->store(a, sbi, buf, len) : 0;
1128 static void f2fs_stat_kobj_release(struct kobject *kobj)
1130 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1132 complete(&sbi->s_stat_kobj_unregister);
1135 static const struct sysfs_ops f2fs_stat_attr_ops = {
1136 .show = f2fs_stat_attr_show,
1137 .store = f2fs_stat_attr_store,
1140 static struct kobj_type f2fs_stat_ktype = {
1141 .default_groups = f2fs_stat_groups,
1142 .sysfs_ops = &f2fs_stat_attr_ops,
1143 .release = f2fs_stat_kobj_release,
1146 static ssize_t f2fs_sb_feat_attr_show(struct kobject *kobj,
1147 struct attribute *attr, char *buf)
1149 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1150 s_feature_list_kobj);
1151 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1153 return a->show ? a->show(a, sbi, buf) : 0;
1156 static void f2fs_feature_list_kobj_release(struct kobject *kobj)
1158 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1159 s_feature_list_kobj);
1160 complete(&sbi->s_feature_list_kobj_unregister);
1163 static const struct sysfs_ops f2fs_feature_list_attr_ops = {
1164 .show = f2fs_sb_feat_attr_show,
1167 static struct kobj_type f2fs_feature_list_ktype = {
1168 .default_groups = f2fs_sb_feat_groups,
1169 .sysfs_ops = &f2fs_feature_list_attr_ops,
1170 .release = f2fs_feature_list_kobj_release,
1173 static int __maybe_unused segment_info_seq_show(struct seq_file *seq,
1176 struct super_block *sb = seq->private;
1177 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1178 unsigned int total_segs =
1179 le32_to_cpu(sbi->raw_super->segment_count_main);
1182 seq_puts(seq, "format: segment_type|valid_blocks\n"
1183 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1185 for (i = 0; i < total_segs; i++) {
1186 struct seg_entry *se = get_seg_entry(sbi, i);
1189 seq_printf(seq, "%-10d", i);
1190 seq_printf(seq, "%d|%-3u", se->type, se->valid_blocks);
1191 if ((i % 10) == 9 || i == (total_segs - 1))
1192 seq_putc(seq, '\n');
1200 static int __maybe_unused segment_bits_seq_show(struct seq_file *seq,
1203 struct super_block *sb = seq->private;
1204 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1205 unsigned int total_segs =
1206 le32_to_cpu(sbi->raw_super->segment_count_main);
1209 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
1210 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1212 for (i = 0; i < total_segs; i++) {
1213 struct seg_entry *se = get_seg_entry(sbi, i);
1215 seq_printf(seq, "%-10d", i);
1216 seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks);
1217 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
1218 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
1219 seq_putc(seq, '\n');
1224 static int __maybe_unused victim_bits_seq_show(struct seq_file *seq,
1227 struct super_block *sb = seq->private;
1228 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1229 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
1232 seq_puts(seq, "format: victim_secmap bitmaps\n");
1234 for (i = 0; i < MAIN_SECS(sbi); i++) {
1236 seq_printf(seq, "%-10d", i);
1237 seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0);
1238 if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1))
1239 seq_putc(seq, '\n');
1246 int __init f2fs_init_sysfs(void)
1250 kobject_set_name(&f2fs_kset.kobj, "f2fs");
1251 f2fs_kset.kobj.parent = fs_kobj;
1252 ret = kset_register(&f2fs_kset);
1256 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
1259 kobject_put(&f2fs_feat);
1260 kset_unregister(&f2fs_kset);
1262 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
1267 void f2fs_exit_sysfs(void)
1269 kobject_put(&f2fs_feat);
1270 kset_unregister(&f2fs_kset);
1271 remove_proc_entry("fs/f2fs", NULL);
1272 f2fs_proc_root = NULL;
1275 int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
1277 struct super_block *sb = sbi->sb;
1280 sbi->s_kobj.kset = &f2fs_kset;
1281 init_completion(&sbi->s_kobj_unregister);
1282 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
1287 sbi->s_stat_kobj.kset = &f2fs_kset;
1288 init_completion(&sbi->s_stat_kobj_unregister);
1289 err = kobject_init_and_add(&sbi->s_stat_kobj, &f2fs_stat_ktype,
1290 &sbi->s_kobj, "stat");
1294 sbi->s_feature_list_kobj.kset = &f2fs_kset;
1295 init_completion(&sbi->s_feature_list_kobj_unregister);
1296 err = kobject_init_and_add(&sbi->s_feature_list_kobj,
1297 &f2fs_feature_list_ktype,
1298 &sbi->s_kobj, "feature_list");
1300 goto put_feature_list_kobj;
1303 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
1306 proc_create_single_data("segment_info", 0444, sbi->s_proc,
1307 segment_info_seq_show, sb);
1308 proc_create_single_data("segment_bits", 0444, sbi->s_proc,
1309 segment_bits_seq_show, sb);
1310 #ifdef CONFIG_F2FS_IOSTAT
1311 proc_create_single_data("iostat_info", 0444, sbi->s_proc,
1312 iostat_info_seq_show, sb);
1314 proc_create_single_data("victim_bits", 0444, sbi->s_proc,
1315 victim_bits_seq_show, sb);
1318 put_feature_list_kobj:
1319 kobject_put(&sbi->s_feature_list_kobj);
1320 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1322 kobject_put(&sbi->s_stat_kobj);
1323 wait_for_completion(&sbi->s_stat_kobj_unregister);
1325 kobject_put(&sbi->s_kobj);
1326 wait_for_completion(&sbi->s_kobj_unregister);
1330 void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
1333 #ifdef CONFIG_F2FS_IOSTAT
1334 remove_proc_entry("iostat_info", sbi->s_proc);
1336 remove_proc_entry("segment_info", sbi->s_proc);
1337 remove_proc_entry("segment_bits", sbi->s_proc);
1338 remove_proc_entry("victim_bits", sbi->s_proc);
1339 remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
1342 kobject_del(&sbi->s_stat_kobj);
1343 kobject_put(&sbi->s_stat_kobj);
1344 wait_for_completion(&sbi->s_stat_kobj_unregister);
1345 kobject_del(&sbi->s_feature_list_kobj);
1346 kobject_put(&sbi->s_feature_list_kobj);
1347 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1349 kobject_del(&sbi->s_kobj);
1350 kobject_put(&sbi->s_kobj);
1351 wait_for_completion(&sbi->s_kobj_unregister);