]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - fs/f2fs/sysfs.c
f2fs: support flexible inline xattr size
[mirror_ubuntu-bionic-kernel.git] / fs / f2fs / sysfs.c
CommitLineData
8ceffcb2
CY
1/*
2 * f2fs sysfs interface
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 * Copyright (c) 2017 Chao Yu <chao@kernel.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12#include <linux/proc_fs.h>
13#include <linux/f2fs_fs.h>
299aa41a 14#include <linux/seq_file.h>
8ceffcb2
CY
15
16#include "f2fs.h"
17#include "segment.h"
18#include "gc.h"
19
20static struct proc_dir_entry *f2fs_proc_root;
8ceffcb2
CY
21
22/* Sysfs support for f2fs */
23enum {
24 GC_THREAD, /* struct f2fs_gc_thread */
25 SM_INFO, /* struct f2fs_sm_info */
26 DCC_INFO, /* struct discard_cmd_control */
27 NM_INFO, /* struct f2fs_nm_info */
28 F2FS_SBI, /* struct f2fs_sb_info */
29#ifdef CONFIG_F2FS_FAULT_INJECTION
30 FAULT_INFO_RATE, /* struct f2fs_fault_info */
31 FAULT_INFO_TYPE, /* struct f2fs_fault_info */
32#endif
daeb433e 33 RESERVED_BLOCKS,
8ceffcb2
CY
34};
35
36struct f2fs_attr {
37 struct attribute attr;
38 ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *);
39 ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *,
40 const char *, size_t);
41 int struct_type;
42 int offset;
bf9e697e 43 int id;
8ceffcb2
CY
44};
45
46static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
47{
48 if (struct_type == GC_THREAD)
49 return (unsigned char *)sbi->gc_thread;
50 else if (struct_type == SM_INFO)
51 return (unsigned char *)SM_I(sbi);
52 else if (struct_type == DCC_INFO)
53 return (unsigned char *)SM_I(sbi)->dcc_info;
54 else if (struct_type == NM_INFO)
55 return (unsigned char *)NM_I(sbi);
daeb433e 56 else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS)
8ceffcb2
CY
57 return (unsigned char *)sbi;
58#ifdef CONFIG_F2FS_FAULT_INJECTION
59 else if (struct_type == FAULT_INFO_RATE ||
60 struct_type == FAULT_INFO_TYPE)
61 return (unsigned char *)&sbi->fault_info;
62#endif
63 return NULL;
64}
65
8f1572f7
JK
66static ssize_t dirty_segments_show(struct f2fs_attr *a,
67 struct f2fs_sb_info *sbi, char *buf)
68{
69 return snprintf(buf, PAGE_SIZE, "%llu\n",
70 (unsigned long long)(dirty_segments(sbi)));
71}
72
8ceffcb2
CY
73static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
74 struct f2fs_sb_info *sbi, char *buf)
75{
76 struct super_block *sb = sbi->sb;
77
78 if (!sb->s_bdev->bd_part)
79 return snprintf(buf, PAGE_SIZE, "0\n");
80
81 return snprintf(buf, PAGE_SIZE, "%llu\n",
82 (unsigned long long)(sbi->kbytes_written +
83 BD_PART_WRITTEN(sbi)));
84}
85
bf9e697e
JK
86static ssize_t features_show(struct f2fs_attr *a,
87 struct f2fs_sb_info *sbi, char *buf)
88{
89 struct super_block *sb = sbi->sb;
90 int len = 0;
91
92 if (!sb->s_bdev->bd_part)
93 return snprintf(buf, PAGE_SIZE, "0\n");
94
95 if (f2fs_sb_has_crypto(sb))
96 len += snprintf(buf, PAGE_SIZE - len, "%s",
97 "encryption");
98 if (f2fs_sb_mounted_blkzoned(sb))
99 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
100 len ? ", " : "", "blkzoned");
101 if (f2fs_sb_has_extra_attr(sb))
102 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
103 len ? ", " : "", "extra_attr");
104 if (f2fs_sb_has_project_quota(sb))
105 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
106 len ? ", " : "", "projquota");
107 if (f2fs_sb_has_inode_chksum(sb))
108 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
109 len ? ", " : "", "inode_checksum");
6afc662e
CY
110 if (f2fs_sb_has_flexible_inline_xattr(sb))
111 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
112 len ? ", " : "", "flexible_inline_xattr");
bf9e697e
JK
113 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
114 return len;
115}
116
8ceffcb2
CY
117static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
118 struct f2fs_sb_info *sbi, char *buf)
119{
120 unsigned char *ptr = NULL;
121 unsigned int *ui;
122
123 ptr = __struct_ptr(sbi, a->struct_type);
124 if (!ptr)
125 return -EINVAL;
126
127 ui = (unsigned int *)(ptr + a->offset);
128
129 return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
130}
131
132static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
133 struct f2fs_sb_info *sbi,
134 const char *buf, size_t count)
135{
136 unsigned char *ptr;
137 unsigned long t;
138 unsigned int *ui;
139 ssize_t ret;
140
141 ptr = __struct_ptr(sbi, a->struct_type);
142 if (!ptr)
143 return -EINVAL;
144
145 ui = (unsigned int *)(ptr + a->offset);
146
147 ret = kstrtoul(skip_spaces(buf), 0, &t);
148 if (ret < 0)
149 return ret;
150#ifdef CONFIG_F2FS_FAULT_INJECTION
151 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
152 return -EINVAL;
153#endif
daeb433e
CY
154 if (a->struct_type == RESERVED_BLOCKS) {
155 spin_lock(&sbi->stat_lock);
156 if ((unsigned long)sbi->total_valid_block_count + t >
157 (unsigned long)sbi->user_block_count) {
158 spin_unlock(&sbi->stat_lock);
159 return -EINVAL;
160 }
161 *ui = t;
162 spin_unlock(&sbi->stat_lock);
163 return count;
164 }
969d1b18
CY
165
166 if (!strcmp(a->attr.name, "discard_granularity")) {
969d1b18
CY
167 if (t == 0 || t > MAX_PLIST_NUM)
168 return -EINVAL;
169 if (t == *ui)
170 return count;
80647e5f 171 *ui = t;
969d1b18
CY
172 return count;
173 }
174
8ceffcb2 175 *ui = t;
b0af6d49
CY
176
177 if (!strcmp(a->attr.name, "iostat_enable") && *ui == 0)
178 f2fs_reset_iostat(sbi);
d9872a69
JK
179 if (!strcmp(a->attr.name, "gc_urgent") && t == 1 && sbi->gc_thread) {
180 sbi->gc_thread->gc_wake = 1;
181 wake_up_interruptible_all(&sbi->gc_thread->gc_wait_queue_head);
01983c71 182 wake_up_discard_thread(sbi, true);
d9872a69 183 }
b0af6d49 184
8ceffcb2
CY
185 return count;
186}
187
188static ssize_t f2fs_attr_show(struct kobject *kobj,
189 struct attribute *attr, char *buf)
190{
191 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
192 s_kobj);
193 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
194
195 return a->show ? a->show(a, sbi, buf) : 0;
196}
197
198static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
199 const char *buf, size_t len)
200{
201 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
202 s_kobj);
203 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
204
205 return a->store ? a->store(a, sbi, buf, len) : 0;
206}
207
208static void f2fs_sb_release(struct kobject *kobj)
209{
210 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
211 s_kobj);
212 complete(&sbi->s_kobj_unregister);
213}
214
bf9e697e
JK
215enum feat_id {
216 FEAT_CRYPTO = 0,
217 FEAT_BLKZONED,
218 FEAT_ATOMIC_WRITE,
219 FEAT_EXTRA_ATTR,
220 FEAT_PROJECT_QUOTA,
221 FEAT_INODE_CHECKSUM,
6afc662e 222 FEAT_FLEXIBLE_INLINE_XATTR,
bf9e697e
JK
223};
224
225static ssize_t f2fs_feature_show(struct f2fs_attr *a,
226 struct f2fs_sb_info *sbi, char *buf)
227{
228 switch (a->id) {
229 case FEAT_CRYPTO:
230 case FEAT_BLKZONED:
231 case FEAT_ATOMIC_WRITE:
232 case FEAT_EXTRA_ATTR:
233 case FEAT_PROJECT_QUOTA:
234 case FEAT_INODE_CHECKSUM:
6afc662e 235 case FEAT_FLEXIBLE_INLINE_XATTR:
bf9e697e
JK
236 return snprintf(buf, PAGE_SIZE, "supported\n");
237 }
238 return 0;
239}
240
8ceffcb2
CY
241#define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
242static struct f2fs_attr f2fs_attr_##_name = { \
243 .attr = {.name = __stringify(_name), .mode = _mode }, \
244 .show = _show, \
245 .store = _store, \
246 .struct_type = _struct_type, \
247 .offset = _offset \
248}
249
250#define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
251 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
252 f2fs_sbi_show, f2fs_sbi_store, \
253 offsetof(struct struct_name, elname))
254
255#define F2FS_GENERAL_RO_ATTR(name) \
256static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
257
bf9e697e
JK
258#define F2FS_FEATURE_RO_ATTR(_name, _id) \
259static struct f2fs_attr f2fs_attr_##_name = { \
260 .attr = {.name = __stringify(_name), .mode = 0444 }, \
261 .show = f2fs_feature_show, \
262 .id = _id, \
263}
264
d9872a69
JK
265F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time,
266 urgent_sleep_time);
8ceffcb2
CY
267F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
268F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
269F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
270F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle);
d9872a69 271F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent, gc_urgent);
8ceffcb2
CY
272F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
273F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
969d1b18 274F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity);
daeb433e 275F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
8ceffcb2
CY
276F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
277F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
278F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
279F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
280F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
281F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
282F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
283F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
284F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
285F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
286F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
287F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
b0af6d49 288F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
8ceffcb2
CY
289#ifdef CONFIG_F2FS_FAULT_INJECTION
290F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
291F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
292#endif
8f1572f7 293F2FS_GENERAL_RO_ATTR(dirty_segments);
8ceffcb2 294F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
bf9e697e
JK
295F2FS_GENERAL_RO_ATTR(features);
296
297#ifdef CONFIG_F2FS_FS_ENCRYPTION
298F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
299#endif
300#ifdef CONFIG_BLK_DEV_ZONED
301F2FS_FEATURE_RO_ATTR(block_zoned, FEAT_BLKZONED);
302#endif
303F2FS_FEATURE_RO_ATTR(atomic_write, FEAT_ATOMIC_WRITE);
304F2FS_FEATURE_RO_ATTR(extra_attr, FEAT_EXTRA_ATTR);
305F2FS_FEATURE_RO_ATTR(project_quota, FEAT_PROJECT_QUOTA);
306F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM);
6afc662e 307F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR);
8ceffcb2
CY
308
309#define ATTR_LIST(name) (&f2fs_attr_##name.attr)
310static struct attribute *f2fs_attrs[] = {
d9872a69 311 ATTR_LIST(gc_urgent_sleep_time),
8ceffcb2
CY
312 ATTR_LIST(gc_min_sleep_time),
313 ATTR_LIST(gc_max_sleep_time),
314 ATTR_LIST(gc_no_gc_sleep_time),
315 ATTR_LIST(gc_idle),
d9872a69 316 ATTR_LIST(gc_urgent),
8ceffcb2
CY
317 ATTR_LIST(reclaim_segments),
318 ATTR_LIST(max_small_discards),
969d1b18 319 ATTR_LIST(discard_granularity),
8ceffcb2
CY
320 ATTR_LIST(batched_trim_sections),
321 ATTR_LIST(ipu_policy),
322 ATTR_LIST(min_ipu_util),
323 ATTR_LIST(min_fsync_blocks),
324 ATTR_LIST(min_hot_blocks),
325 ATTR_LIST(max_victim_search),
326 ATTR_LIST(dir_level),
327 ATTR_LIST(ram_thresh),
328 ATTR_LIST(ra_nid_pages),
329 ATTR_LIST(dirty_nats_ratio),
330 ATTR_LIST(cp_interval),
331 ATTR_LIST(idle_interval),
b0af6d49 332 ATTR_LIST(iostat_enable),
8ceffcb2
CY
333#ifdef CONFIG_F2FS_FAULT_INJECTION
334 ATTR_LIST(inject_rate),
335 ATTR_LIST(inject_type),
336#endif
8f1572f7 337 ATTR_LIST(dirty_segments),
8ceffcb2 338 ATTR_LIST(lifetime_write_kbytes),
bf9e697e 339 ATTR_LIST(features),
daeb433e 340 ATTR_LIST(reserved_blocks),
8ceffcb2
CY
341 NULL,
342};
343
bf9e697e
JK
344static struct attribute *f2fs_feat_attrs[] = {
345#ifdef CONFIG_F2FS_FS_ENCRYPTION
346 ATTR_LIST(encryption),
347#endif
348#ifdef CONFIG_BLK_DEV_ZONED
349 ATTR_LIST(block_zoned),
350#endif
351 ATTR_LIST(atomic_write),
352 ATTR_LIST(extra_attr),
353 ATTR_LIST(project_quota),
354 ATTR_LIST(inode_checksum),
6afc662e 355 ATTR_LIST(flexible_inline_xattr),
bf9e697e
JK
356 NULL,
357};
358
8ceffcb2
CY
359static const struct sysfs_ops f2fs_attr_ops = {
360 .show = f2fs_attr_show,
361 .store = f2fs_attr_store,
362};
363
bf9e697e 364static struct kobj_type f2fs_sb_ktype = {
8ceffcb2
CY
365 .default_attrs = f2fs_attrs,
366 .sysfs_ops = &f2fs_attr_ops,
367 .release = f2fs_sb_release,
368};
369
bf9e697e
JK
370static struct kobj_type f2fs_ktype = {
371 .sysfs_ops = &f2fs_attr_ops,
372};
373
374static struct kset f2fs_kset = {
375 .kobj = {.ktype = &f2fs_ktype},
376};
377
378static struct kobj_type f2fs_feat_ktype = {
379 .default_attrs = f2fs_feat_attrs,
380 .sysfs_ops = &f2fs_attr_ops,
381};
382
383static struct kobject f2fs_feat = {
384 .kset = &f2fs_kset,
385};
386
8ceffcb2
CY
387static int segment_info_seq_show(struct seq_file *seq, void *offset)
388{
389 struct super_block *sb = seq->private;
390 struct f2fs_sb_info *sbi = F2FS_SB(sb);
391 unsigned int total_segs =
392 le32_to_cpu(sbi->raw_super->segment_count_main);
393 int i;
394
395 seq_puts(seq, "format: segment_type|valid_blocks\n"
396 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
397
398 for (i = 0; i < total_segs; i++) {
399 struct seg_entry *se = get_seg_entry(sbi, i);
400
401 if ((i % 10) == 0)
402 seq_printf(seq, "%-10d", i);
403 seq_printf(seq, "%d|%-3u", se->type,
404 get_valid_blocks(sbi, i, false));
405 if ((i % 10) == 9 || i == (total_segs - 1))
406 seq_putc(seq, '\n');
407 else
408 seq_putc(seq, ' ');
409 }
410
411 return 0;
412}
413
414static int segment_bits_seq_show(struct seq_file *seq, void *offset)
415{
416 struct super_block *sb = seq->private;
417 struct f2fs_sb_info *sbi = F2FS_SB(sb);
418 unsigned int total_segs =
419 le32_to_cpu(sbi->raw_super->segment_count_main);
420 int i, j;
421
422 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
423 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
424
425 for (i = 0; i < total_segs; i++) {
426 struct seg_entry *se = get_seg_entry(sbi, i);
427
428 seq_printf(seq, "%-10d", i);
429 seq_printf(seq, "%d|%-3u|", se->type,
430 get_valid_blocks(sbi, i, false));
431 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
432 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
433 seq_putc(seq, '\n');
434 }
435 return 0;
436}
437
b0af6d49
CY
438static int iostat_info_seq_show(struct seq_file *seq, void *offset)
439{
440 struct super_block *sb = seq->private;
441 struct f2fs_sb_info *sbi = F2FS_SB(sb);
442 time64_t now = ktime_get_real_seconds();
443
444 if (!sbi->iostat_enable)
445 return 0;
446
447 seq_printf(seq, "time: %-16llu\n", now);
448
449 /* print app IOs */
450 seq_printf(seq, "app buffered: %-16llu\n",
451 sbi->write_iostat[APP_BUFFERED_IO]);
452 seq_printf(seq, "app direct: %-16llu\n",
453 sbi->write_iostat[APP_DIRECT_IO]);
454 seq_printf(seq, "app mapped: %-16llu\n",
455 sbi->write_iostat[APP_MAPPED_IO]);
456
457 /* print fs IOs */
458 seq_printf(seq, "fs data: %-16llu\n",
459 sbi->write_iostat[FS_DATA_IO]);
460 seq_printf(seq, "fs node: %-16llu\n",
461 sbi->write_iostat[FS_NODE_IO]);
462 seq_printf(seq, "fs meta: %-16llu\n",
463 sbi->write_iostat[FS_META_IO]);
464 seq_printf(seq, "fs gc data: %-16llu\n",
465 sbi->write_iostat[FS_GC_DATA_IO]);
466 seq_printf(seq, "fs gc node: %-16llu\n",
467 sbi->write_iostat[FS_GC_NODE_IO]);
468 seq_printf(seq, "fs cp data: %-16llu\n",
469 sbi->write_iostat[FS_CP_DATA_IO]);
470 seq_printf(seq, "fs cp node: %-16llu\n",
471 sbi->write_iostat[FS_CP_NODE_IO]);
472 seq_printf(seq, "fs cp meta: %-16llu\n",
473 sbi->write_iostat[FS_CP_META_IO]);
474 seq_printf(seq, "fs discard: %-16llu\n",
475 sbi->write_iostat[FS_DISCARD]);
476
477 return 0;
478}
479
8ceffcb2
CY
480#define F2FS_PROC_FILE_DEF(_name) \
481static int _name##_open_fs(struct inode *inode, struct file *file) \
482{ \
483 return single_open(file, _name##_seq_show, PDE_DATA(inode)); \
484} \
485 \
486static const struct file_operations f2fs_seq_##_name##_fops = { \
487 .open = _name##_open_fs, \
488 .read = seq_read, \
489 .llseek = seq_lseek, \
490 .release = single_release, \
491};
492
493F2FS_PROC_FILE_DEF(segment_info);
494F2FS_PROC_FILE_DEF(segment_bits);
b0af6d49 495F2FS_PROC_FILE_DEF(iostat_info);
8ceffcb2 496
dc6b2055 497int __init f2fs_init_sysfs(void)
8ceffcb2 498{
bf9e697e 499 int ret;
8ceffcb2 500
bf9e697e
JK
501 kobject_set_name(&f2fs_kset.kobj, "f2fs");
502 f2fs_kset.kobj.parent = fs_kobj;
503 ret = kset_register(&f2fs_kset);
504 if (ret)
505 return ret;
506
507 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
508 NULL, "features");
509 if (ret)
510 kset_unregister(&f2fs_kset);
511 else
512 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
513 return ret;
8ceffcb2
CY
514}
515
dc6b2055 516void f2fs_exit_sysfs(void)
8ceffcb2 517{
bf9e697e
JK
518 kobject_put(&f2fs_feat);
519 kset_unregister(&f2fs_kset);
8ceffcb2 520 remove_proc_entry("fs/f2fs", NULL);
bf9e697e 521 f2fs_proc_root = NULL;
8ceffcb2
CY
522}
523
dc6b2055 524int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
8ceffcb2
CY
525{
526 struct super_block *sb = sbi->sb;
527 int err;
528
bf9e697e
JK
529 sbi->s_kobj.kset = &f2fs_kset;
530 init_completion(&sbi->s_kobj_unregister);
531 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
532 "%s", sb->s_id);
533 if (err)
534 return err;
535
8ceffcb2
CY
536 if (f2fs_proc_root)
537 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
538
539 if (sbi->s_proc) {
540 proc_create_data("segment_info", S_IRUGO, sbi->s_proc,
541 &f2fs_seq_segment_info_fops, sb);
542 proc_create_data("segment_bits", S_IRUGO, sbi->s_proc,
543 &f2fs_seq_segment_bits_fops, sb);
b0af6d49
CY
544 proc_create_data("iostat_info", S_IRUGO, sbi->s_proc,
545 &f2fs_seq_iostat_info_fops, sb);
8ceffcb2 546 }
8ceffcb2 547 return 0;
8ceffcb2
CY
548}
549
dc6b2055 550void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
8ceffcb2 551{
8ceffcb2 552 if (sbi->s_proc) {
b0af6d49 553 remove_proc_entry("iostat_info", sbi->s_proc);
8ceffcb2
CY
554 remove_proc_entry("segment_info", sbi->s_proc);
555 remove_proc_entry("segment_bits", sbi->s_proc);
556 remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
557 }
bf9e697e 558 kobject_del(&sbi->s_kobj);
8ceffcb2 559}