1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
9 #include <linux/compiler.h>
10 #include <linux/proc_fs.h>
11 #include <linux/f2fs_fs.h>
12 #include <linux/seq_file.h>
13 #include <linux/unicode.h>
14 #include <linux/ioprio.h>
15 #include <linux/sysfs.h>
21 #include <trace/events/f2fs.h>
23 static struct proc_dir_entry *f2fs_proc_root;
25 /* Sysfs support for f2fs */
27 GC_THREAD, /* struct f2fs_gc_thread */
28 SM_INFO, /* struct f2fs_sm_info */
29 DCC_INFO, /* struct discard_cmd_control */
30 NM_INFO, /* struct f2fs_nm_info */
31 F2FS_SBI, /* struct f2fs_sb_info */
32 #ifdef CONFIG_F2FS_STAT_FS
33 STAT_INFO, /* struct f2fs_stat_info */
35 #ifdef CONFIG_F2FS_FAULT_INJECTION
36 FAULT_INFO_RATE, /* struct f2fs_fault_info */
37 FAULT_INFO_TYPE, /* struct f2fs_fault_info */
39 RESERVED_BLOCKS, /* struct f2fs_sb_info */
40 CPRC_INFO, /* struct ckpt_req_control */
41 ATGC_INFO, /* struct atgc_management */
44 static const char *gc_mode_names[MAX_GC_MODE] = {
55 struct attribute attr;
56 ssize_t (*show)(struct f2fs_attr *, 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 ui = (unsigned int *)(ptr + a->offset);
344 return sprintf(buf, "%u\n", *ui);
347 static ssize_t __sbi_store(struct f2fs_attr *a,
348 struct f2fs_sb_info *sbi,
349 const char *buf, size_t count)
356 ptr = __struct_ptr(sbi, a->struct_type);
360 if (!strcmp(a->attr.name, "extension_list")) {
361 const char *name = strim((char *)buf);
362 bool set = true, hot;
364 if (!strncmp(name, "[h]", 3))
366 else if (!strncmp(name, "[c]", 3))
378 if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN)
381 f2fs_down_write(&sbi->sb_lock);
383 ret = f2fs_update_extension_list(sbi, name, hot, set);
387 ret = f2fs_commit_super(sbi, false);
389 f2fs_update_extension_list(sbi, name, hot, !set);
391 f2fs_up_write(&sbi->sb_lock);
392 return ret ? ret : count;
395 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
396 const char *name = strim((char *)buf);
397 struct ckpt_req_control *cprc = &sbi->cprc_info;
402 if (!strncmp(name, "rt,", 3))
403 class = IOPRIO_CLASS_RT;
404 else if (!strncmp(name, "be,", 3))
405 class = IOPRIO_CLASS_BE;
410 ret = kstrtol(name, 10, &data);
413 if (data >= IOPRIO_NR_LEVELS || data < 0)
416 cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, data);
417 if (test_opt(sbi, MERGE_CHECKPOINT)) {
418 ret = set_task_ioprio(cprc->f2fs_issue_ckpt,
419 cprc->ckpt_thread_ioprio);
427 ui = (unsigned int *)(ptr + a->offset);
429 ret = kstrtoul(skip_spaces(buf), 0, &t);
432 #ifdef CONFIG_F2FS_FAULT_INJECTION
433 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
435 if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX)
438 if (a->struct_type == RESERVED_BLOCKS) {
439 spin_lock(&sbi->stat_lock);
440 if (t > (unsigned long)(sbi->user_block_count -
441 F2FS_OPTION(sbi).root_reserved_blocks -
442 sbi->blocks_per_seg *
443 SM_I(sbi)->additional_reserved_segments)) {
444 spin_unlock(&sbi->stat_lock);
448 sbi->current_reserved_blocks = min(sbi->reserved_blocks,
449 sbi->user_block_count - valid_user_blocks(sbi));
450 spin_unlock(&sbi->stat_lock);
454 if (!strcmp(a->attr.name, "discard_granularity")) {
455 if (t == 0 || t > MAX_PLIST_NUM)
457 if (!f2fs_block_unit_discard(sbi))
465 if (!strcmp(a->attr.name, "migration_granularity")) {
466 if (t == 0 || t > sbi->segs_per_sec)
470 if (!strcmp(a->attr.name, "trim_sections"))
473 if (!strcmp(a->attr.name, "gc_urgent")) {
475 sbi->gc_mode = GC_NORMAL;
477 sbi->gc_mode = GC_URGENT_HIGH;
478 if (sbi->gc_thread) {
479 sbi->gc_thread->gc_wake = 1;
480 wake_up_interruptible_all(
481 &sbi->gc_thread->gc_wait_queue_head);
482 wake_up_discard_thread(sbi, true);
485 sbi->gc_mode = GC_URGENT_LOW;
487 sbi->gc_mode = GC_URGENT_MID;
488 if (sbi->gc_thread) {
489 sbi->gc_thread->gc_wake = 1;
490 wake_up_interruptible_all(
491 &sbi->gc_thread->gc_wait_queue_head);
498 if (!strcmp(a->attr.name, "gc_idle")) {
499 if (t == GC_IDLE_CB) {
500 sbi->gc_mode = GC_IDLE_CB;
501 } else if (t == GC_IDLE_GREEDY) {
502 sbi->gc_mode = GC_IDLE_GREEDY;
503 } else if (t == GC_IDLE_AT) {
504 if (!sbi->am.atgc_enabled)
506 sbi->gc_mode = GC_IDLE_AT;
508 sbi->gc_mode = GC_NORMAL;
513 if (!strcmp(a->attr.name, "gc_urgent_high_remaining")) {
514 spin_lock(&sbi->gc_urgent_high_lock);
515 sbi->gc_urgent_high_limited = t != 0;
516 sbi->gc_urgent_high_remaining = t;
517 spin_unlock(&sbi->gc_urgent_high_lock);
522 #ifdef CONFIG_F2FS_IOSTAT
523 if (!strcmp(a->attr.name, "iostat_enable")) {
524 sbi->iostat_enable = !!t;
525 if (!sbi->iostat_enable)
526 f2fs_reset_iostat(sbi);
530 if (!strcmp(a->attr.name, "iostat_period_ms")) {
531 if (t < MIN_IOSTAT_PERIOD_MS || t > MAX_IOSTAT_PERIOD_MS)
533 spin_lock(&sbi->iostat_lock);
534 sbi->iostat_period_ms = (unsigned int)t;
535 spin_unlock(&sbi->iostat_lock);
540 #ifdef CONFIG_F2FS_FS_COMPRESSION
541 if (!strcmp(a->attr.name, "compr_written_block") ||
542 !strcmp(a->attr.name, "compr_saved_block")) {
545 sbi->compr_written_block = 0;
546 sbi->compr_saved_block = 0;
550 if (!strcmp(a->attr.name, "compr_new_inode")) {
553 sbi->compr_new_inode = 0;
558 if (!strcmp(a->attr.name, "atgc_candidate_ratio")) {
561 sbi->am.candidate_ratio = t;
565 if (!strcmp(a->attr.name, "atgc_age_weight")) {
568 sbi->am.age_weight = t;
572 if (!strcmp(a->attr.name, "gc_segment_mode")) {
574 sbi->gc_segment_mode = t;
580 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
583 sbi->gc_reclaimed_segs[sbi->gc_segment_mode] = 0;
587 if (!strcmp(a->attr.name, "seq_file_ra_mul")) {
588 if (t >= MIN_RA_MUL && t <= MAX_RA_MUL)
589 sbi->seq_file_ra_mul = t;
595 if (!strcmp(a->attr.name, "max_fragment_chunk")) {
596 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE)
597 sbi->max_fragment_chunk = t;
603 if (!strcmp(a->attr.name, "max_fragment_hole")) {
604 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE)
605 sbi->max_fragment_hole = t;
611 *ui = (unsigned int)t;
616 static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
617 struct f2fs_sb_info *sbi,
618 const char *buf, size_t count)
621 bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") ||
622 a->struct_type == GC_THREAD);
625 if (!down_read_trylock(&sbi->sb->s_umount))
628 ret = __sbi_store(a, sbi, buf, count);
630 up_read(&sbi->sb->s_umount);
635 static ssize_t f2fs_attr_show(struct kobject *kobj,
636 struct attribute *attr, char *buf)
638 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
640 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
642 return a->show ? a->show(a, sbi, buf) : 0;
645 static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
646 const char *buf, size_t len)
648 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
650 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
652 return a->store ? a->store(a, sbi, buf, len) : 0;
655 static void f2fs_sb_release(struct kobject *kobj)
657 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
659 complete(&sbi->s_kobj_unregister);
663 * Note that there are three feature list entries:
664 * 1) /sys/fs/f2fs/features
665 * : shows runtime features supported by in-kernel f2fs along with Kconfig.
666 * - ref. F2FS_FEATURE_RO_ATTR()
668 * 2) /sys/fs/f2fs/$s_id/features <deprecated>
669 * : shows on-disk features enabled by mkfs.f2fs, used for old kernels. This
670 * won't add new feature anymore, and thus, users should check entries in 3)
671 * instead of this 2).
673 * 3) /sys/fs/f2fs/$s_id/feature_list
674 * : shows on-disk features enabled by mkfs.f2fs per instance, which follows
675 * sysfs entry rule where each entry should expose single value.
676 * This list covers old feature list provided by 2) and beyond. Therefore,
677 * please add new on-disk feature in this list only.
678 * - ref. F2FS_SB_FEATURE_RO_ATTR()
680 static ssize_t f2fs_feature_show(struct f2fs_attr *a,
681 struct f2fs_sb_info *sbi, char *buf)
683 return sprintf(buf, "supported\n");
686 #define F2FS_FEATURE_RO_ATTR(_name) \
687 static struct f2fs_attr f2fs_attr_##_name = { \
688 .attr = {.name = __stringify(_name), .mode = 0444 }, \
689 .show = f2fs_feature_show, \
692 static ssize_t f2fs_sb_feature_show(struct f2fs_attr *a,
693 struct f2fs_sb_info *sbi, char *buf)
695 if (F2FS_HAS_FEATURE(sbi, a->id))
696 return sprintf(buf, "supported\n");
697 return sprintf(buf, "unsupported\n");
700 #define F2FS_SB_FEATURE_RO_ATTR(_name, _feat) \
701 static struct f2fs_attr f2fs_attr_sb_##_name = { \
702 .attr = {.name = __stringify(_name), .mode = 0444 }, \
703 .show = f2fs_sb_feature_show, \
704 .id = F2FS_FEATURE_##_feat, \
707 #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
708 static struct f2fs_attr f2fs_attr_##_name = { \
709 .attr = {.name = __stringify(_name), .mode = _mode }, \
712 .struct_type = _struct_type, \
716 #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
717 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
718 f2fs_sbi_show, f2fs_sbi_store, \
719 offsetof(struct struct_name, elname))
721 #define F2FS_GENERAL_RO_ATTR(name) \
722 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
724 #define F2FS_STAT_ATTR(_struct_type, _struct_name, _name, _elname) \
725 static struct f2fs_attr f2fs_attr_##_name = { \
726 .attr = {.name = __stringify(_name), .mode = 0444 }, \
727 .show = f2fs_sbi_show, \
728 .struct_type = _struct_type, \
729 .offset = offsetof(struct _struct_name, _elname), \
732 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time,
734 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
735 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
736 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
737 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode);
738 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode);
739 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
740 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
741 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_request, max_discard_request);
742 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, min_discard_issue_time, min_discard_issue_time);
743 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, mid_discard_issue_time, mid_discard_issue_time);
744 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_issue_time, max_discard_issue_time);
745 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity);
746 F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
747 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
748 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
749 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
750 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
751 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_seq_blocks, min_seq_blocks);
752 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
753 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections);
754 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
755 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
756 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
757 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, max_roll_forward_node_blocks, max_rf_node_blocks);
758 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
759 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, migration_granularity, migration_granularity);
760 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
761 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
762 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
763 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval,
764 interval_time[DISCARD_TIME]);
765 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]);
766 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info,
767 umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]);
768 #ifdef CONFIG_F2FS_IOSTAT
769 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
770 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_period_ms, iostat_period_ms);
772 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
773 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_io_bytes, max_io_bytes);
774 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
775 F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list);
776 #ifdef CONFIG_F2FS_FAULT_INJECTION
777 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
778 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
780 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, data_io_flag, data_io_flag);
781 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, node_io_flag, node_io_flag);
782 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent_high_remaining, gc_urgent_high_remaining);
783 F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, ckpt_thread_ioprio, ckpt_thread_ioprio);
784 F2FS_GENERAL_RO_ATTR(dirty_segments);
785 F2FS_GENERAL_RO_ATTR(free_segments);
786 F2FS_GENERAL_RO_ATTR(ovp_segments);
787 F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
788 F2FS_GENERAL_RO_ATTR(features);
789 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
790 F2FS_GENERAL_RO_ATTR(unusable);
791 F2FS_GENERAL_RO_ATTR(encoding);
792 F2FS_GENERAL_RO_ATTR(mounted_time_sec);
793 F2FS_GENERAL_RO_ATTR(main_blkaddr);
794 F2FS_GENERAL_RO_ATTR(pending_discard);
795 #ifdef CONFIG_F2FS_STAT_FS
796 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count);
797 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count);
798 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_foreground_calls, call_count);
799 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_background_calls, bg_gc);
800 F2FS_GENERAL_RO_ATTR(moved_blocks_background);
801 F2FS_GENERAL_RO_ATTR(moved_blocks_foreground);
802 F2FS_GENERAL_RO_ATTR(avg_vblocks);
805 #ifdef CONFIG_FS_ENCRYPTION
806 F2FS_FEATURE_RO_ATTR(encryption);
807 F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2);
808 #if IS_ENABLED(CONFIG_UNICODE)
809 F2FS_FEATURE_RO_ATTR(encrypted_casefold);
811 #endif /* CONFIG_FS_ENCRYPTION */
812 #ifdef CONFIG_BLK_DEV_ZONED
813 F2FS_FEATURE_RO_ATTR(block_zoned);
815 F2FS_FEATURE_RO_ATTR(atomic_write);
816 F2FS_FEATURE_RO_ATTR(extra_attr);
817 F2FS_FEATURE_RO_ATTR(project_quota);
818 F2FS_FEATURE_RO_ATTR(inode_checksum);
819 F2FS_FEATURE_RO_ATTR(flexible_inline_xattr);
820 F2FS_FEATURE_RO_ATTR(quota_ino);
821 F2FS_FEATURE_RO_ATTR(inode_crtime);
822 F2FS_FEATURE_RO_ATTR(lost_found);
823 #ifdef CONFIG_FS_VERITY
824 F2FS_FEATURE_RO_ATTR(verity);
826 F2FS_FEATURE_RO_ATTR(sb_checksum);
827 #if IS_ENABLED(CONFIG_UNICODE)
828 F2FS_FEATURE_RO_ATTR(casefold);
830 F2FS_FEATURE_RO_ATTR(readonly);
831 #ifdef CONFIG_F2FS_FS_COMPRESSION
832 F2FS_FEATURE_RO_ATTR(compression);
833 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block);
834 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block);
835 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode);
837 F2FS_FEATURE_RO_ATTR(pin_file);
840 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio);
841 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count);
842 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
843 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
845 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, seq_file_ra_mul, seq_file_ra_mul);
846 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_segment_mode, gc_segment_mode);
847 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_reclaimed_segments, gc_reclaimed_segs);
848 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_chunk, max_fragment_chunk);
849 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_hole, max_fragment_hole);
851 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
852 static struct attribute *f2fs_attrs[] = {
853 ATTR_LIST(gc_urgent_sleep_time),
854 ATTR_LIST(gc_min_sleep_time),
855 ATTR_LIST(gc_max_sleep_time),
856 ATTR_LIST(gc_no_gc_sleep_time),
858 ATTR_LIST(gc_urgent),
859 ATTR_LIST(reclaim_segments),
860 ATTR_LIST(main_blkaddr),
861 ATTR_LIST(max_small_discards),
862 ATTR_LIST(max_discard_request),
863 ATTR_LIST(min_discard_issue_time),
864 ATTR_LIST(mid_discard_issue_time),
865 ATTR_LIST(max_discard_issue_time),
866 ATTR_LIST(discard_granularity),
867 ATTR_LIST(pending_discard),
868 ATTR_LIST(batched_trim_sections),
869 ATTR_LIST(ipu_policy),
870 ATTR_LIST(min_ipu_util),
871 ATTR_LIST(min_fsync_blocks),
872 ATTR_LIST(min_seq_blocks),
873 ATTR_LIST(min_hot_blocks),
874 ATTR_LIST(min_ssr_sections),
875 ATTR_LIST(max_victim_search),
876 ATTR_LIST(migration_granularity),
877 ATTR_LIST(dir_level),
878 ATTR_LIST(ram_thresh),
879 ATTR_LIST(ra_nid_pages),
880 ATTR_LIST(dirty_nats_ratio),
881 ATTR_LIST(max_roll_forward_node_blocks),
882 ATTR_LIST(cp_interval),
883 ATTR_LIST(idle_interval),
884 ATTR_LIST(discard_idle_interval),
885 ATTR_LIST(gc_idle_interval),
886 ATTR_LIST(umount_discard_timeout),
887 #ifdef CONFIG_F2FS_IOSTAT
888 ATTR_LIST(iostat_enable),
889 ATTR_LIST(iostat_period_ms),
891 ATTR_LIST(readdir_ra),
892 ATTR_LIST(max_io_bytes),
893 ATTR_LIST(gc_pin_file_thresh),
894 ATTR_LIST(extension_list),
895 #ifdef CONFIG_F2FS_FAULT_INJECTION
896 ATTR_LIST(inject_rate),
897 ATTR_LIST(inject_type),
899 ATTR_LIST(data_io_flag),
900 ATTR_LIST(node_io_flag),
901 ATTR_LIST(gc_urgent_high_remaining),
902 ATTR_LIST(ckpt_thread_ioprio),
903 ATTR_LIST(dirty_segments),
904 ATTR_LIST(free_segments),
905 ATTR_LIST(ovp_segments),
907 ATTR_LIST(lifetime_write_kbytes),
909 ATTR_LIST(reserved_blocks),
910 ATTR_LIST(current_reserved_blocks),
912 ATTR_LIST(mounted_time_sec),
913 #ifdef CONFIG_F2FS_STAT_FS
914 ATTR_LIST(cp_foreground_calls),
915 ATTR_LIST(cp_background_calls),
916 ATTR_LIST(gc_foreground_calls),
917 ATTR_LIST(gc_background_calls),
918 ATTR_LIST(moved_blocks_foreground),
919 ATTR_LIST(moved_blocks_background),
920 ATTR_LIST(avg_vblocks),
922 #ifdef CONFIG_F2FS_FS_COMPRESSION
923 ATTR_LIST(compr_written_block),
924 ATTR_LIST(compr_saved_block),
925 ATTR_LIST(compr_new_inode),
928 ATTR_LIST(atgc_candidate_ratio),
929 ATTR_LIST(atgc_candidate_count),
930 ATTR_LIST(atgc_age_weight),
931 ATTR_LIST(atgc_age_threshold),
932 ATTR_LIST(seq_file_ra_mul),
933 ATTR_LIST(gc_segment_mode),
934 ATTR_LIST(gc_reclaimed_segments),
935 ATTR_LIST(max_fragment_chunk),
936 ATTR_LIST(max_fragment_hole),
939 ATTRIBUTE_GROUPS(f2fs);
941 static struct attribute *f2fs_feat_attrs[] = {
942 #ifdef CONFIG_FS_ENCRYPTION
943 ATTR_LIST(encryption),
944 ATTR_LIST(test_dummy_encryption_v2),
945 #if IS_ENABLED(CONFIG_UNICODE)
946 ATTR_LIST(encrypted_casefold),
948 #endif /* CONFIG_FS_ENCRYPTION */
949 #ifdef CONFIG_BLK_DEV_ZONED
950 ATTR_LIST(block_zoned),
952 ATTR_LIST(atomic_write),
953 ATTR_LIST(extra_attr),
954 ATTR_LIST(project_quota),
955 ATTR_LIST(inode_checksum),
956 ATTR_LIST(flexible_inline_xattr),
957 ATTR_LIST(quota_ino),
958 ATTR_LIST(inode_crtime),
959 ATTR_LIST(lost_found),
960 #ifdef CONFIG_FS_VERITY
963 ATTR_LIST(sb_checksum),
964 #if IS_ENABLED(CONFIG_UNICODE)
968 #ifdef CONFIG_F2FS_FS_COMPRESSION
969 ATTR_LIST(compression),
974 ATTRIBUTE_GROUPS(f2fs_feat);
976 F2FS_GENERAL_RO_ATTR(sb_status);
977 static struct attribute *f2fs_stat_attrs[] = {
978 ATTR_LIST(sb_status),
981 ATTRIBUTE_GROUPS(f2fs_stat);
983 F2FS_SB_FEATURE_RO_ATTR(encryption, ENCRYPT);
984 F2FS_SB_FEATURE_RO_ATTR(block_zoned, BLKZONED);
985 F2FS_SB_FEATURE_RO_ATTR(extra_attr, EXTRA_ATTR);
986 F2FS_SB_FEATURE_RO_ATTR(project_quota, PRJQUOTA);
987 F2FS_SB_FEATURE_RO_ATTR(inode_checksum, INODE_CHKSUM);
988 F2FS_SB_FEATURE_RO_ATTR(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
989 F2FS_SB_FEATURE_RO_ATTR(quota_ino, QUOTA_INO);
990 F2FS_SB_FEATURE_RO_ATTR(inode_crtime, INODE_CRTIME);
991 F2FS_SB_FEATURE_RO_ATTR(lost_found, LOST_FOUND);
992 F2FS_SB_FEATURE_RO_ATTR(verity, VERITY);
993 F2FS_SB_FEATURE_RO_ATTR(sb_checksum, SB_CHKSUM);
994 F2FS_SB_FEATURE_RO_ATTR(casefold, CASEFOLD);
995 F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION);
996 F2FS_SB_FEATURE_RO_ATTR(readonly, RO);
998 static struct attribute *f2fs_sb_feat_attrs[] = {
999 ATTR_LIST(sb_encryption),
1000 ATTR_LIST(sb_block_zoned),
1001 ATTR_LIST(sb_extra_attr),
1002 ATTR_LIST(sb_project_quota),
1003 ATTR_LIST(sb_inode_checksum),
1004 ATTR_LIST(sb_flexible_inline_xattr),
1005 ATTR_LIST(sb_quota_ino),
1006 ATTR_LIST(sb_inode_crtime),
1007 ATTR_LIST(sb_lost_found),
1008 ATTR_LIST(sb_verity),
1009 ATTR_LIST(sb_sb_checksum),
1010 ATTR_LIST(sb_casefold),
1011 ATTR_LIST(sb_compression),
1012 ATTR_LIST(sb_readonly),
1015 ATTRIBUTE_GROUPS(f2fs_sb_feat);
1017 static const struct sysfs_ops f2fs_attr_ops = {
1018 .show = f2fs_attr_show,
1019 .store = f2fs_attr_store,
1022 static struct kobj_type f2fs_sb_ktype = {
1023 .default_groups = f2fs_groups,
1024 .sysfs_ops = &f2fs_attr_ops,
1025 .release = f2fs_sb_release,
1028 static struct kobj_type f2fs_ktype = {
1029 .sysfs_ops = &f2fs_attr_ops,
1032 static struct kset f2fs_kset = {
1033 .kobj = {.ktype = &f2fs_ktype},
1036 static struct kobj_type f2fs_feat_ktype = {
1037 .default_groups = f2fs_feat_groups,
1038 .sysfs_ops = &f2fs_attr_ops,
1041 static struct kobject f2fs_feat = {
1045 static ssize_t f2fs_stat_attr_show(struct kobject *kobj,
1046 struct attribute *attr, char *buf)
1048 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1050 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1052 return a->show ? a->show(a, sbi, buf) : 0;
1055 static ssize_t f2fs_stat_attr_store(struct kobject *kobj, struct attribute *attr,
1056 const char *buf, size_t len)
1058 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1060 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1062 return a->store ? a->store(a, sbi, buf, len) : 0;
1065 static void f2fs_stat_kobj_release(struct kobject *kobj)
1067 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1069 complete(&sbi->s_stat_kobj_unregister);
1072 static const struct sysfs_ops f2fs_stat_attr_ops = {
1073 .show = f2fs_stat_attr_show,
1074 .store = f2fs_stat_attr_store,
1077 static struct kobj_type f2fs_stat_ktype = {
1078 .default_groups = f2fs_stat_groups,
1079 .sysfs_ops = &f2fs_stat_attr_ops,
1080 .release = f2fs_stat_kobj_release,
1083 static ssize_t f2fs_sb_feat_attr_show(struct kobject *kobj,
1084 struct attribute *attr, char *buf)
1086 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1087 s_feature_list_kobj);
1088 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
1090 return a->show ? a->show(a, sbi, buf) : 0;
1093 static void f2fs_feature_list_kobj_release(struct kobject *kobj)
1095 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
1096 s_feature_list_kobj);
1097 complete(&sbi->s_feature_list_kobj_unregister);
1100 static const struct sysfs_ops f2fs_feature_list_attr_ops = {
1101 .show = f2fs_sb_feat_attr_show,
1104 static struct kobj_type f2fs_feature_list_ktype = {
1105 .default_groups = f2fs_sb_feat_groups,
1106 .sysfs_ops = &f2fs_feature_list_attr_ops,
1107 .release = f2fs_feature_list_kobj_release,
1110 static int __maybe_unused segment_info_seq_show(struct seq_file *seq,
1113 struct super_block *sb = seq->private;
1114 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1115 unsigned int total_segs =
1116 le32_to_cpu(sbi->raw_super->segment_count_main);
1119 seq_puts(seq, "format: segment_type|valid_blocks\n"
1120 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1122 for (i = 0; i < total_segs; i++) {
1123 struct seg_entry *se = get_seg_entry(sbi, i);
1126 seq_printf(seq, "%-10d", i);
1127 seq_printf(seq, "%d|%-3u", se->type, se->valid_blocks);
1128 if ((i % 10) == 9 || i == (total_segs - 1))
1129 seq_putc(seq, '\n');
1137 static int __maybe_unused segment_bits_seq_show(struct seq_file *seq,
1140 struct super_block *sb = seq->private;
1141 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1142 unsigned int total_segs =
1143 le32_to_cpu(sbi->raw_super->segment_count_main);
1146 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
1147 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1149 for (i = 0; i < total_segs; i++) {
1150 struct seg_entry *se = get_seg_entry(sbi, i);
1152 seq_printf(seq, "%-10d", i);
1153 seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks);
1154 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
1155 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
1156 seq_putc(seq, '\n');
1161 static int __maybe_unused victim_bits_seq_show(struct seq_file *seq,
1164 struct super_block *sb = seq->private;
1165 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1166 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
1169 seq_puts(seq, "format: victim_secmap bitmaps\n");
1171 for (i = 0; i < MAIN_SECS(sbi); i++) {
1173 seq_printf(seq, "%-10d", i);
1174 seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0);
1175 if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1))
1176 seq_putc(seq, '\n');
1183 int __init f2fs_init_sysfs(void)
1187 kobject_set_name(&f2fs_kset.kobj, "f2fs");
1188 f2fs_kset.kobj.parent = fs_kobj;
1189 ret = kset_register(&f2fs_kset);
1193 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
1196 kobject_put(&f2fs_feat);
1197 kset_unregister(&f2fs_kset);
1199 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
1204 void f2fs_exit_sysfs(void)
1206 kobject_put(&f2fs_feat);
1207 kset_unregister(&f2fs_kset);
1208 remove_proc_entry("fs/f2fs", NULL);
1209 f2fs_proc_root = NULL;
1212 int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
1214 struct super_block *sb = sbi->sb;
1217 sbi->s_kobj.kset = &f2fs_kset;
1218 init_completion(&sbi->s_kobj_unregister);
1219 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
1224 sbi->s_stat_kobj.kset = &f2fs_kset;
1225 init_completion(&sbi->s_stat_kobj_unregister);
1226 err = kobject_init_and_add(&sbi->s_stat_kobj, &f2fs_stat_ktype,
1227 &sbi->s_kobj, "stat");
1231 sbi->s_feature_list_kobj.kset = &f2fs_kset;
1232 init_completion(&sbi->s_feature_list_kobj_unregister);
1233 err = kobject_init_and_add(&sbi->s_feature_list_kobj,
1234 &f2fs_feature_list_ktype,
1235 &sbi->s_kobj, "feature_list");
1237 goto put_feature_list_kobj;
1240 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
1243 proc_create_single_data("segment_info", 0444, sbi->s_proc,
1244 segment_info_seq_show, sb);
1245 proc_create_single_data("segment_bits", 0444, sbi->s_proc,
1246 segment_bits_seq_show, sb);
1247 #ifdef CONFIG_F2FS_IOSTAT
1248 proc_create_single_data("iostat_info", 0444, sbi->s_proc,
1249 iostat_info_seq_show, sb);
1251 proc_create_single_data("victim_bits", 0444, sbi->s_proc,
1252 victim_bits_seq_show, sb);
1255 put_feature_list_kobj:
1256 kobject_put(&sbi->s_feature_list_kobj);
1257 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1259 kobject_put(&sbi->s_stat_kobj);
1260 wait_for_completion(&sbi->s_stat_kobj_unregister);
1262 kobject_put(&sbi->s_kobj);
1263 wait_for_completion(&sbi->s_kobj_unregister);
1267 void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
1270 #ifdef CONFIG_F2FS_IOSTAT
1271 remove_proc_entry("iostat_info", sbi->s_proc);
1273 remove_proc_entry("segment_info", sbi->s_proc);
1274 remove_proc_entry("segment_bits", sbi->s_proc);
1275 remove_proc_entry("victim_bits", sbi->s_proc);
1276 remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
1279 kobject_del(&sbi->s_stat_kobj);
1280 kobject_put(&sbi->s_stat_kobj);
1281 wait_for_completion(&sbi->s_stat_kobj_unregister);
1282 kobject_del(&sbi->s_feature_list_kobj);
1283 kobject_put(&sbi->s_feature_list_kobj);
1284 wait_for_completion(&sbi->s_feature_list_kobj_unregister);
1286 kobject_del(&sbi->s_kobj);
1287 kobject_put(&sbi->s_kobj);
1288 wait_for_completion(&sbi->s_kobj_unregister);