sysfs.c 15 KB

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