blob: 3d6bbdb743b0d8d135bbdc9b78d405b136e9c803 [file] [log] [blame]
Chao Yu8ceffcb2017-06-14 17:39:47 +08001/*
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>
Jaegeuk Kim299aa412017-07-13 17:45:21 -070014#include <linux/seq_file.h>
Chao Yu8ceffcb2017-06-14 17:39:47 +080015
16#include "f2fs.h"
17#include "segment.h"
18#include "gc.h"
19
20static struct proc_dir_entry *f2fs_proc_root;
Chao Yu8ceffcb2017-06-14 17:39:47 +080021
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
Chao Yudaeb4332017-06-26 16:24:41 +080033 RESERVED_BLOCKS,
Chao Yu8ceffcb2017-06-14 17:39:47 +080034};
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;
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -070043 int id;
Chao Yu8ceffcb2017-06-14 17:39:47 +080044};
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);
Chao Yudaeb4332017-06-26 16:24:41 +080056 else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS)
Chao Yu8ceffcb2017-06-14 17:39:47 +080057 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
66static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
67 struct f2fs_sb_info *sbi, char *buf)
68{
69 struct super_block *sb = sbi->sb;
70
71 if (!sb->s_bdev->bd_part)
72 return snprintf(buf, PAGE_SIZE, "0\n");
73
74 return snprintf(buf, PAGE_SIZE, "%llu\n",
75 (unsigned long long)(sbi->kbytes_written +
76 BD_PART_WRITTEN(sbi)));
77}
78
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -070079static ssize_t features_show(struct f2fs_attr *a,
80 struct f2fs_sb_info *sbi, char *buf)
81{
82 struct super_block *sb = sbi->sb;
83 int len = 0;
84
85 if (!sb->s_bdev->bd_part)
86 return snprintf(buf, PAGE_SIZE, "0\n");
87
88 if (f2fs_sb_has_crypto(sb))
89 len += snprintf(buf, PAGE_SIZE - len, "%s",
90 "encryption");
91 if (f2fs_sb_mounted_blkzoned(sb))
92 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
93 len ? ", " : "", "blkzoned");
94 if (f2fs_sb_has_extra_attr(sb))
95 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
96 len ? ", " : "", "extra_attr");
97 if (f2fs_sb_has_project_quota(sb))
98 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
99 len ? ", " : "", "projquota");
100 if (f2fs_sb_has_inode_chksum(sb))
101 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
102 len ? ", " : "", "inode_checksum");
103 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
104 return len;
105}
106
Chao Yu8ceffcb2017-06-14 17:39:47 +0800107static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
108 struct f2fs_sb_info *sbi, char *buf)
109{
110 unsigned char *ptr = NULL;
111 unsigned int *ui;
112
113 ptr = __struct_ptr(sbi, a->struct_type);
114 if (!ptr)
115 return -EINVAL;
116
117 ui = (unsigned int *)(ptr + a->offset);
118
119 return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
120}
121
122static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
123 struct f2fs_sb_info *sbi,
124 const char *buf, size_t count)
125{
126 unsigned char *ptr;
127 unsigned long t;
128 unsigned int *ui;
129 ssize_t ret;
130
131 ptr = __struct_ptr(sbi, a->struct_type);
132 if (!ptr)
133 return -EINVAL;
134
135 ui = (unsigned int *)(ptr + a->offset);
136
137 ret = kstrtoul(skip_spaces(buf), 0, &t);
138 if (ret < 0)
139 return ret;
140#ifdef CONFIG_F2FS_FAULT_INJECTION
141 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
142 return -EINVAL;
143#endif
Chao Yudaeb4332017-06-26 16:24:41 +0800144 if (a->struct_type == RESERVED_BLOCKS) {
145 spin_lock(&sbi->stat_lock);
146 if ((unsigned long)sbi->total_valid_block_count + t >
147 (unsigned long)sbi->user_block_count) {
148 spin_unlock(&sbi->stat_lock);
149 return -EINVAL;
150 }
151 *ui = t;
152 spin_unlock(&sbi->stat_lock);
153 return count;
154 }
Chao Yu8ceffcb2017-06-14 17:39:47 +0800155 *ui = t;
Chao Yub0af6d42017-08-02 23:21:48 +0800156
157 if (!strcmp(a->attr.name, "iostat_enable") && *ui == 0)
158 f2fs_reset_iostat(sbi);
159
Chao Yu8ceffcb2017-06-14 17:39:47 +0800160 return count;
161}
162
163static ssize_t f2fs_attr_show(struct kobject *kobj,
164 struct attribute *attr, char *buf)
165{
166 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
167 s_kobj);
168 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
169
170 return a->show ? a->show(a, sbi, buf) : 0;
171}
172
173static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
174 const char *buf, size_t len)
175{
176 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
177 s_kobj);
178 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
179
180 return a->store ? a->store(a, sbi, buf, len) : 0;
181}
182
183static void f2fs_sb_release(struct kobject *kobj)
184{
185 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
186 s_kobj);
187 complete(&sbi->s_kobj_unregister);
188}
189
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700190enum feat_id {
191 FEAT_CRYPTO = 0,
192 FEAT_BLKZONED,
193 FEAT_ATOMIC_WRITE,
194 FEAT_EXTRA_ATTR,
195 FEAT_PROJECT_QUOTA,
196 FEAT_INODE_CHECKSUM,
197};
198
199static ssize_t f2fs_feature_show(struct f2fs_attr *a,
200 struct f2fs_sb_info *sbi, char *buf)
201{
202 switch (a->id) {
203 case FEAT_CRYPTO:
204 case FEAT_BLKZONED:
205 case FEAT_ATOMIC_WRITE:
206 case FEAT_EXTRA_ATTR:
207 case FEAT_PROJECT_QUOTA:
208 case FEAT_INODE_CHECKSUM:
209 return snprintf(buf, PAGE_SIZE, "supported\n");
210 }
211 return 0;
212}
213
Chao Yu8ceffcb2017-06-14 17:39:47 +0800214#define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
215static struct f2fs_attr f2fs_attr_##_name = { \
216 .attr = {.name = __stringify(_name), .mode = _mode }, \
217 .show = _show, \
218 .store = _store, \
219 .struct_type = _struct_type, \
220 .offset = _offset \
221}
222
223#define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
224 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
225 f2fs_sbi_show, f2fs_sbi_store, \
226 offsetof(struct struct_name, elname))
227
228#define F2FS_GENERAL_RO_ATTR(name) \
229static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
230
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700231#define F2FS_FEATURE_RO_ATTR(_name, _id) \
232static struct f2fs_attr f2fs_attr_##_name = { \
233 .attr = {.name = __stringify(_name), .mode = 0444 }, \
234 .show = f2fs_feature_show, \
235 .id = _id, \
236}
237
Chao Yu8ceffcb2017-06-14 17:39:47 +0800238F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
239F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
240F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
241F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle);
242F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
243F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
Chao Yudaeb4332017-06-26 16:24:41 +0800244F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
Chao Yu8ceffcb2017-06-14 17:39:47 +0800245F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
246F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
247F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
248F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
249F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
250F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
251F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
252F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
253F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
254F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
255F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
256F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
Chao Yub0af6d42017-08-02 23:21:48 +0800257F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
Chao Yu8ceffcb2017-06-14 17:39:47 +0800258#ifdef CONFIG_F2FS_FAULT_INJECTION
259F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
260F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
261#endif
262F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700263F2FS_GENERAL_RO_ATTR(features);
264
265#ifdef CONFIG_F2FS_FS_ENCRYPTION
266F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
267#endif
268#ifdef CONFIG_BLK_DEV_ZONED
269F2FS_FEATURE_RO_ATTR(block_zoned, FEAT_BLKZONED);
270#endif
271F2FS_FEATURE_RO_ATTR(atomic_write, FEAT_ATOMIC_WRITE);
272F2FS_FEATURE_RO_ATTR(extra_attr, FEAT_EXTRA_ATTR);
273F2FS_FEATURE_RO_ATTR(project_quota, FEAT_PROJECT_QUOTA);
274F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM);
Chao Yu8ceffcb2017-06-14 17:39:47 +0800275
276#define ATTR_LIST(name) (&f2fs_attr_##name.attr)
277static struct attribute *f2fs_attrs[] = {
278 ATTR_LIST(gc_min_sleep_time),
279 ATTR_LIST(gc_max_sleep_time),
280 ATTR_LIST(gc_no_gc_sleep_time),
281 ATTR_LIST(gc_idle),
282 ATTR_LIST(reclaim_segments),
283 ATTR_LIST(max_small_discards),
284 ATTR_LIST(batched_trim_sections),
285 ATTR_LIST(ipu_policy),
286 ATTR_LIST(min_ipu_util),
287 ATTR_LIST(min_fsync_blocks),
288 ATTR_LIST(min_hot_blocks),
289 ATTR_LIST(max_victim_search),
290 ATTR_LIST(dir_level),
291 ATTR_LIST(ram_thresh),
292 ATTR_LIST(ra_nid_pages),
293 ATTR_LIST(dirty_nats_ratio),
294 ATTR_LIST(cp_interval),
295 ATTR_LIST(idle_interval),
Chao Yub0af6d42017-08-02 23:21:48 +0800296 ATTR_LIST(iostat_enable),
Chao Yu8ceffcb2017-06-14 17:39:47 +0800297#ifdef CONFIG_F2FS_FAULT_INJECTION
298 ATTR_LIST(inject_rate),
299 ATTR_LIST(inject_type),
300#endif
301 ATTR_LIST(lifetime_write_kbytes),
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700302 ATTR_LIST(features),
Chao Yudaeb4332017-06-26 16:24:41 +0800303 ATTR_LIST(reserved_blocks),
Chao Yu8ceffcb2017-06-14 17:39:47 +0800304 NULL,
305};
306
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700307static struct attribute *f2fs_feat_attrs[] = {
308#ifdef CONFIG_F2FS_FS_ENCRYPTION
309 ATTR_LIST(encryption),
310#endif
311#ifdef CONFIG_BLK_DEV_ZONED
312 ATTR_LIST(block_zoned),
313#endif
314 ATTR_LIST(atomic_write),
315 ATTR_LIST(extra_attr),
316 ATTR_LIST(project_quota),
317 ATTR_LIST(inode_checksum),
318 NULL,
319};
320
Chao Yu8ceffcb2017-06-14 17:39:47 +0800321static const struct sysfs_ops f2fs_attr_ops = {
322 .show = f2fs_attr_show,
323 .store = f2fs_attr_store,
324};
325
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700326static struct kobj_type f2fs_sb_ktype = {
Chao Yu8ceffcb2017-06-14 17:39:47 +0800327 .default_attrs = f2fs_attrs,
328 .sysfs_ops = &f2fs_attr_ops,
329 .release = f2fs_sb_release,
330};
331
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700332static struct kobj_type f2fs_ktype = {
333 .sysfs_ops = &f2fs_attr_ops,
334};
335
336static struct kset f2fs_kset = {
337 .kobj = {.ktype = &f2fs_ktype},
338};
339
340static struct kobj_type f2fs_feat_ktype = {
341 .default_attrs = f2fs_feat_attrs,
342 .sysfs_ops = &f2fs_attr_ops,
343};
344
345static struct kobject f2fs_feat = {
346 .kset = &f2fs_kset,
347};
348
Chao Yu8ceffcb2017-06-14 17:39:47 +0800349static int segment_info_seq_show(struct seq_file *seq, void *offset)
350{
351 struct super_block *sb = seq->private;
352 struct f2fs_sb_info *sbi = F2FS_SB(sb);
353 unsigned int total_segs =
354 le32_to_cpu(sbi->raw_super->segment_count_main);
355 int i;
356
357 seq_puts(seq, "format: segment_type|valid_blocks\n"
358 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
359
360 for (i = 0; i < total_segs; i++) {
361 struct seg_entry *se = get_seg_entry(sbi, i);
362
363 if ((i % 10) == 0)
364 seq_printf(seq, "%-10d", i);
365 seq_printf(seq, "%d|%-3u", se->type,
366 get_valid_blocks(sbi, i, false));
367 if ((i % 10) == 9 || i == (total_segs - 1))
368 seq_putc(seq, '\n');
369 else
370 seq_putc(seq, ' ');
371 }
372
373 return 0;
374}
375
376static int segment_bits_seq_show(struct seq_file *seq, void *offset)
377{
378 struct super_block *sb = seq->private;
379 struct f2fs_sb_info *sbi = F2FS_SB(sb);
380 unsigned int total_segs =
381 le32_to_cpu(sbi->raw_super->segment_count_main);
382 int i, j;
383
384 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
385 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
386
387 for (i = 0; i < total_segs; i++) {
388 struct seg_entry *se = get_seg_entry(sbi, i);
389
390 seq_printf(seq, "%-10d", i);
391 seq_printf(seq, "%d|%-3u|", se->type,
392 get_valid_blocks(sbi, i, false));
393 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
394 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
395 seq_putc(seq, '\n');
396 }
397 return 0;
398}
399
Chao Yub0af6d42017-08-02 23:21:48 +0800400static int iostat_info_seq_show(struct seq_file *seq, void *offset)
401{
402 struct super_block *sb = seq->private;
403 struct f2fs_sb_info *sbi = F2FS_SB(sb);
404 time64_t now = ktime_get_real_seconds();
405
406 if (!sbi->iostat_enable)
407 return 0;
408
409 seq_printf(seq, "time: %-16llu\n", now);
410
411 /* print app IOs */
412 seq_printf(seq, "app buffered: %-16llu\n",
413 sbi->write_iostat[APP_BUFFERED_IO]);
414 seq_printf(seq, "app direct: %-16llu\n",
415 sbi->write_iostat[APP_DIRECT_IO]);
416 seq_printf(seq, "app mapped: %-16llu\n",
417 sbi->write_iostat[APP_MAPPED_IO]);
418
419 /* print fs IOs */
420 seq_printf(seq, "fs data: %-16llu\n",
421 sbi->write_iostat[FS_DATA_IO]);
422 seq_printf(seq, "fs node: %-16llu\n",
423 sbi->write_iostat[FS_NODE_IO]);
424 seq_printf(seq, "fs meta: %-16llu\n",
425 sbi->write_iostat[FS_META_IO]);
426 seq_printf(seq, "fs gc data: %-16llu\n",
427 sbi->write_iostat[FS_GC_DATA_IO]);
428 seq_printf(seq, "fs gc node: %-16llu\n",
429 sbi->write_iostat[FS_GC_NODE_IO]);
430 seq_printf(seq, "fs cp data: %-16llu\n",
431 sbi->write_iostat[FS_CP_DATA_IO]);
432 seq_printf(seq, "fs cp node: %-16llu\n",
433 sbi->write_iostat[FS_CP_NODE_IO]);
434 seq_printf(seq, "fs cp meta: %-16llu\n",
435 sbi->write_iostat[FS_CP_META_IO]);
436 seq_printf(seq, "fs discard: %-16llu\n",
437 sbi->write_iostat[FS_DISCARD]);
438
439 return 0;
440}
441
Chao Yu8ceffcb2017-06-14 17:39:47 +0800442#define F2FS_PROC_FILE_DEF(_name) \
443static int _name##_open_fs(struct inode *inode, struct file *file) \
444{ \
445 return single_open(file, _name##_seq_show, PDE_DATA(inode)); \
446} \
447 \
448static const struct file_operations f2fs_seq_##_name##_fops = { \
449 .open = _name##_open_fs, \
450 .read = seq_read, \
451 .llseek = seq_lseek, \
452 .release = single_release, \
453};
454
455F2FS_PROC_FILE_DEF(segment_info);
456F2FS_PROC_FILE_DEF(segment_bits);
Chao Yub0af6d42017-08-02 23:21:48 +0800457F2FS_PROC_FILE_DEF(iostat_info);
Chao Yu8ceffcb2017-06-14 17:39:47 +0800458
Jaegeuk Kimdc6b2052017-07-26 11:24:13 -0700459int __init f2fs_init_sysfs(void)
Chao Yu8ceffcb2017-06-14 17:39:47 +0800460{
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700461 int ret;
Chao Yu8ceffcb2017-06-14 17:39:47 +0800462
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700463 kobject_set_name(&f2fs_kset.kobj, "f2fs");
464 f2fs_kset.kobj.parent = fs_kobj;
465 ret = kset_register(&f2fs_kset);
466 if (ret)
467 return ret;
468
469 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
470 NULL, "features");
471 if (ret)
472 kset_unregister(&f2fs_kset);
473 else
474 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
475 return ret;
Chao Yu8ceffcb2017-06-14 17:39:47 +0800476}
477
Jaegeuk Kimdc6b2052017-07-26 11:24:13 -0700478void f2fs_exit_sysfs(void)
Chao Yu8ceffcb2017-06-14 17:39:47 +0800479{
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700480 kobject_put(&f2fs_feat);
481 kset_unregister(&f2fs_kset);
Chao Yu8ceffcb2017-06-14 17:39:47 +0800482 remove_proc_entry("fs/f2fs", NULL);
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700483 f2fs_proc_root = NULL;
Chao Yu8ceffcb2017-06-14 17:39:47 +0800484}
485
Jaegeuk Kimdc6b2052017-07-26 11:24:13 -0700486int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
Chao Yu8ceffcb2017-06-14 17:39:47 +0800487{
488 struct super_block *sb = sbi->sb;
489 int err;
490
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700491 sbi->s_kobj.kset = &f2fs_kset;
492 init_completion(&sbi->s_kobj_unregister);
493 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
494 "%s", sb->s_id);
495 if (err)
496 return err;
497
Chao Yu8ceffcb2017-06-14 17:39:47 +0800498 if (f2fs_proc_root)
499 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
500
501 if (sbi->s_proc) {
502 proc_create_data("segment_info", S_IRUGO, sbi->s_proc,
503 &f2fs_seq_segment_info_fops, sb);
504 proc_create_data("segment_bits", S_IRUGO, sbi->s_proc,
505 &f2fs_seq_segment_bits_fops, sb);
Chao Yub0af6d42017-08-02 23:21:48 +0800506 proc_create_data("iostat_info", S_IRUGO, sbi->s_proc,
507 &f2fs_seq_iostat_info_fops, sb);
Chao Yu8ceffcb2017-06-14 17:39:47 +0800508 }
Chao Yu8ceffcb2017-06-14 17:39:47 +0800509 return 0;
Chao Yu8ceffcb2017-06-14 17:39:47 +0800510}
511
Jaegeuk Kimdc6b2052017-07-26 11:24:13 -0700512void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
Chao Yu8ceffcb2017-06-14 17:39:47 +0800513{
Chao Yu8ceffcb2017-06-14 17:39:47 +0800514 if (sbi->s_proc) {
Chao Yub0af6d42017-08-02 23:21:48 +0800515 remove_proc_entry("iostat_info", sbi->s_proc);
Chao Yu8ceffcb2017-06-14 17:39:47 +0800516 remove_proc_entry("segment_info", sbi->s_proc);
517 remove_proc_entry("segment_bits", sbi->s_proc);
518 remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
519 }
Jaegeuk Kimbf9e6972017-07-21 17:14:09 -0700520 kobject_del(&sbi->s_kobj);
Chao Yu8ceffcb2017-06-14 17:39:47 +0800521}