1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * linux/fs/ext4/sysfs.c 4 * 5 * Copyright (C) 1992, 1993, 1994, 1995 6 * Remy Card (card@masi.ibp.fr) 7 * Theodore Ts'o (tytso@mit.edu) 8 * 9 */ 10 11 #include <linux/time.h> 12 #include <linux/fs.h> 13 #include <linux/seq_file.h> 14 #include <linux/slab.h> 15 #include <linux/proc_fs.h> 16 #include <linux/part_stat.h> 17 18 #include "ext4.h" 19 #include "ext4_jbd2.h" 20 21 typedef enum { 22 attr_noop, 23 attr_delayed_allocation_blocks, 24 attr_session_write_kbytes, 25 attr_lifetime_write_kbytes, 26 attr_reserved_clusters, 27 attr_sra_exceeded_retry_limit, 28 attr_inode_readahead, 29 attr_trigger_test_error, 30 attr_first_error_time, 31 attr_last_error_time, 32 attr_clusters_in_group, 33 attr_feature, 34 attr_pointer_ui, 35 attr_pointer_ul, 36 attr_pointer_u64, 37 attr_pointer_u8, 38 attr_pointer_string, 39 attr_pointer_atomic, 40 attr_journal_task, 41 } attr_id_t; 42 43 typedef enum { 44 ptr_explicit, 45 ptr_ext4_sb_info_offset, 46 ptr_ext4_super_block_offset, 47 } attr_ptr_t; 48 49 static const char proc_dirname[] = "fs/ext4"; 50 static struct proc_dir_entry *ext4_proc_root; 51 52 struct ext4_attr { 53 struct attribute attr; 54 short attr_id; 55 short attr_ptr; 56 unsigned short attr_size; 57 union { 58 int offset; 59 void *explicit_ptr; 60 } u; 61 }; 62 63 static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf) 64 { 65 struct super_block *sb = sbi->s_buddy_cache->i_sb; 66 67 return sysfs_emit(buf, "%lu\n", 68 (part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - 69 sbi->s_sectors_written_start) >> 1); 70 } 71 72 static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf) 73 { 74 struct super_block *sb = sbi->s_buddy_cache->i_sb; 75 76 return sysfs_emit(buf, "%llu\n", 77 (unsigned long long)(sbi->s_kbytes_written + 78 ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - 79 EXT4_SB(sb)->s_sectors_written_start) >> 1))); 80 } 81 82 static ssize_t inode_readahead_blks_store(struct ext4_sb_info *sbi, 83 const char *buf, size_t count) 84 { 85 unsigned long t; 86 int ret; 87 88 ret = kstrtoul(skip_spaces(buf), 0, &t); 89 if (ret) 90 return ret; 91 92 if (t && (!is_power_of_2(t) || t > 0x40000000)) 93 return -EINVAL; 94 95 sbi->s_inode_readahead_blks = t; 96 return count; 97 } 98 99 static ssize_t reserved_clusters_store(struct ext4_sb_info *sbi, 100 const char *buf, size_t count) 101 { 102 unsigned long long val; 103 ext4_fsblk_t clusters = (ext4_blocks_count(sbi->s_es) >> 104 sbi->s_cluster_bits); 105 int ret; 106 107 ret = kstrtoull(skip_spaces(buf), 0, &val); 108 if (ret || val >= clusters || (s64)val < 0) 109 return -EINVAL; 110 111 atomic64_set(&sbi->s_resv_clusters, val); 112 return count; 113 } 114 115 static ssize_t trigger_test_error(struct ext4_sb_info *sbi, 116 const char *buf, size_t count) 117 { 118 int len = count; 119 120 if (!capable(CAP_SYS_ADMIN)) 121 return -EPERM; 122 123 if (len && buf[len-1] == '\n') 124 len--; 125 126 if (len) 127 ext4_error(sbi->s_sb, "%.*s", len, buf); 128 return count; 129 } 130 131 static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf) 132 { 133 if (!sbi->s_journal) 134 return sysfs_emit(buf, "<none>\n"); 135 return sysfs_emit(buf, "%d\n", 136 task_pid_vnr(sbi->s_journal->j_task)); 137 } 138 139 #define EXT4_ATTR(_name,_mode,_id) \ 140 static struct ext4_attr ext4_attr_##_name = { \ 141 .attr = {.name = __stringify(_name), .mode = _mode }, \ 142 .attr_id = attr_##_id, \ 143 } 144 145 #define EXT4_ATTR_FUNC(_name,_mode) EXT4_ATTR(_name,_mode,_name) 146 147 #define EXT4_ATTR_FEATURE(_name) EXT4_ATTR(_name, 0444, feature) 148 149 #define EXT4_ATTR_OFFSET(_name,_mode,_id,_struct,_elname) \ 150 static struct ext4_attr ext4_attr_##_name = { \ 151 .attr = {.name = __stringify(_name), .mode = _mode }, \ 152 .attr_id = attr_##_id, \ 153 .attr_ptr = ptr_##_struct##_offset, \ 154 .u = { \ 155 .offset = offsetof(struct _struct, _elname),\ 156 }, \ 157 } 158 159 #define EXT4_ATTR_STRING(_name,_mode,_size,_struct,_elname) \ 160 static struct ext4_attr ext4_attr_##_name = { \ 161 .attr = {.name = __stringify(_name), .mode = _mode }, \ 162 .attr_id = attr_pointer_string, \ 163 .attr_size = _size, \ 164 .attr_ptr = ptr_##_struct##_offset, \ 165 .u = { \ 166 .offset = offsetof(struct _struct, _elname),\ 167 }, \ 168 } 169 170 #define EXT4_RO_ATTR_ES_UI(_name,_elname) \ 171 EXT4_ATTR_OFFSET(_name, 0444, pointer_ui, ext4_super_block, _elname) 172 173 #define EXT4_RO_ATTR_ES_U8(_name,_elname) \ 174 EXT4_ATTR_OFFSET(_name, 0444, pointer_u8, ext4_super_block, _elname) 175 176 #define EXT4_RO_ATTR_ES_U64(_name,_elname) \ 177 EXT4_ATTR_OFFSET(_name, 0444, pointer_u64, ext4_super_block, _elname) 178 179 #define EXT4_RO_ATTR_ES_STRING(_name,_elname,_size) \ 180 EXT4_ATTR_STRING(_name, 0444, _size, ext4_super_block, _elname) 181 182 #define EXT4_RW_ATTR_SBI_UI(_name,_elname) \ 183 EXT4_ATTR_OFFSET(_name, 0644, pointer_ui, ext4_sb_info, _elname) 184 185 #define EXT4_RW_ATTR_SBI_UL(_name,_elname) \ 186 EXT4_ATTR_OFFSET(_name, 0644, pointer_ul, ext4_sb_info, _elname) 187 188 #define EXT4_RO_ATTR_SBI_ATOMIC(_name,_elname) \ 189 EXT4_ATTR_OFFSET(_name, 0444, pointer_atomic, ext4_sb_info, _elname) 190 191 #define EXT4_ATTR_PTR(_name,_mode,_id,_ptr) \ 192 static struct ext4_attr ext4_attr_##_name = { \ 193 .attr = {.name = __stringify(_name), .mode = _mode }, \ 194 .attr_id = attr_##_id, \ 195 .attr_ptr = ptr_explicit, \ 196 .u = { \ 197 .explicit_ptr = _ptr, \ 198 }, \ 199 } 200 201 #define ATTR_LIST(name) &ext4_attr_##name.attr 202 203 EXT4_ATTR_FUNC(delayed_allocation_blocks, 0444); 204 EXT4_ATTR_FUNC(session_write_kbytes, 0444); 205 EXT4_ATTR_FUNC(lifetime_write_kbytes, 0444); 206 EXT4_ATTR_FUNC(reserved_clusters, 0644); 207 EXT4_ATTR_FUNC(sra_exceeded_retry_limit, 0444); 208 209 EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, inode_readahead, 210 ext4_sb_info, s_inode_readahead_blks); 211 EXT4_ATTR_OFFSET(mb_group_prealloc, 0644, clusters_in_group, 212 ext4_sb_info, s_mb_group_prealloc); 213 EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal); 214 EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats); 215 EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan); 216 EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan); 217 EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs); 218 EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request); 219 EXT4_RW_ATTR_SBI_UI(mb_max_linear_groups, s_mb_max_linear_groups); 220 EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb); 221 EXT4_ATTR(trigger_fs_error, 0200, trigger_test_error); 222 EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval); 223 EXT4_RW_ATTR_SBI_UI(err_ratelimit_burst, s_err_ratelimit_state.burst); 224 EXT4_RW_ATTR_SBI_UI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.interval); 225 EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst); 226 EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval); 227 EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst); 228 EXT4_RW_ATTR_SBI_UI(mb_best_avail_max_trim_order, s_mb_best_avail_max_trim_order); 229 #ifdef CONFIG_EXT4_DEBUG 230 EXT4_RW_ATTR_SBI_UL(simulate_fail, s_simulate_fail); 231 #endif 232 EXT4_RO_ATTR_SBI_ATOMIC(warning_count, s_warning_count); 233 EXT4_RO_ATTR_SBI_ATOMIC(msg_count, s_msg_count); 234 EXT4_RO_ATTR_ES_UI(errors_count, s_error_count); 235 EXT4_RO_ATTR_ES_U8(first_error_errcode, s_first_error_errcode); 236 EXT4_RO_ATTR_ES_U8(last_error_errcode, s_last_error_errcode); 237 EXT4_RO_ATTR_ES_UI(first_error_ino, s_first_error_ino); 238 EXT4_RO_ATTR_ES_UI(last_error_ino, s_last_error_ino); 239 EXT4_RO_ATTR_ES_U64(first_error_block, s_first_error_block); 240 EXT4_RO_ATTR_ES_U64(last_error_block, s_last_error_block); 241 EXT4_RO_ATTR_ES_UI(first_error_line, s_first_error_line); 242 EXT4_RO_ATTR_ES_UI(last_error_line, s_last_error_line); 243 EXT4_RO_ATTR_ES_STRING(first_error_func, s_first_error_func, 32); 244 EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_func, 32); 245 EXT4_ATTR(first_error_time, 0444, first_error_time); 246 EXT4_ATTR(last_error_time, 0444, last_error_time); 247 EXT4_ATTR(journal_task, 0444, journal_task); 248 EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch); 249 EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit); 250 EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks); 251 252 static unsigned int old_bump_val = 128; 253 EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val); 254 255 static struct attribute *ext4_attrs[] = { 256 ATTR_LIST(delayed_allocation_blocks), 257 ATTR_LIST(session_write_kbytes), 258 ATTR_LIST(lifetime_write_kbytes), 259 ATTR_LIST(reserved_clusters), 260 ATTR_LIST(sra_exceeded_retry_limit), 261 ATTR_LIST(inode_readahead_blks), 262 ATTR_LIST(inode_goal), 263 ATTR_LIST(mb_stats), 264 ATTR_LIST(mb_max_to_scan), 265 ATTR_LIST(mb_min_to_scan), 266 ATTR_LIST(mb_order2_req), 267 ATTR_LIST(mb_stream_req), 268 ATTR_LIST(mb_group_prealloc), 269 ATTR_LIST(mb_max_linear_groups), 270 ATTR_LIST(max_writeback_mb_bump), 271 ATTR_LIST(extent_max_zeroout_kb), 272 ATTR_LIST(trigger_fs_error), 273 ATTR_LIST(err_ratelimit_interval_ms), 274 ATTR_LIST(err_ratelimit_burst), 275 ATTR_LIST(warning_ratelimit_interval_ms), 276 ATTR_LIST(warning_ratelimit_burst), 277 ATTR_LIST(msg_ratelimit_interval_ms), 278 ATTR_LIST(msg_ratelimit_burst), 279 ATTR_LIST(mb_best_avail_max_trim_order), 280 ATTR_LIST(errors_count), 281 ATTR_LIST(warning_count), 282 ATTR_LIST(msg_count), 283 ATTR_LIST(first_error_ino), 284 ATTR_LIST(last_error_ino), 285 ATTR_LIST(first_error_block), 286 ATTR_LIST(last_error_block), 287 ATTR_LIST(first_error_line), 288 ATTR_LIST(last_error_line), 289 ATTR_LIST(first_error_func), 290 ATTR_LIST(last_error_func), 291 ATTR_LIST(first_error_errcode), 292 ATTR_LIST(last_error_errcode), 293 ATTR_LIST(first_error_time), 294 ATTR_LIST(last_error_time), 295 ATTR_LIST(journal_task), 296 #ifdef CONFIG_EXT4_DEBUG 297 ATTR_LIST(simulate_fail), 298 #endif 299 ATTR_LIST(mb_prefetch), 300 ATTR_LIST(mb_prefetch_limit), 301 ATTR_LIST(last_trim_minblks), 302 NULL, 303 }; 304 ATTRIBUTE_GROUPS(ext4); 305 306 /* Features this copy of ext4 supports */ 307 EXT4_ATTR_FEATURE(lazy_itable_init); 308 EXT4_ATTR_FEATURE(batched_discard); 309 EXT4_ATTR_FEATURE(meta_bg_resize); 310 #ifdef CONFIG_FS_ENCRYPTION 311 EXT4_ATTR_FEATURE(encryption); 312 EXT4_ATTR_FEATURE(test_dummy_encryption_v2); 313 #endif 314 #if IS_ENABLED(CONFIG_UNICODE) 315 EXT4_ATTR_FEATURE(casefold); 316 #endif 317 #ifdef CONFIG_FS_VERITY 318 EXT4_ATTR_FEATURE(verity); 319 #endif 320 EXT4_ATTR_FEATURE(metadata_csum_seed); 321 EXT4_ATTR_FEATURE(fast_commit); 322 #if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION) 323 EXT4_ATTR_FEATURE(encrypted_casefold); 324 #endif 325 326 static struct attribute *ext4_feat_attrs[] = { 327 ATTR_LIST(lazy_itable_init), 328 ATTR_LIST(batched_discard), 329 ATTR_LIST(meta_bg_resize), 330 #ifdef CONFIG_FS_ENCRYPTION 331 ATTR_LIST(encryption), 332 ATTR_LIST(test_dummy_encryption_v2), 333 #endif 334 #if IS_ENABLED(CONFIG_UNICODE) 335 ATTR_LIST(casefold), 336 #endif 337 #ifdef CONFIG_FS_VERITY 338 ATTR_LIST(verity), 339 #endif 340 ATTR_LIST(metadata_csum_seed), 341 ATTR_LIST(fast_commit), 342 #if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION) 343 ATTR_LIST(encrypted_casefold), 344 #endif 345 NULL, 346 }; 347 ATTRIBUTE_GROUPS(ext4_feat); 348 349 static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi) 350 { 351 switch (a->attr_ptr) { 352 case ptr_explicit: 353 return a->u.explicit_ptr; 354 case ptr_ext4_sb_info_offset: 355 return (void *) (((char *) sbi) + a->u.offset); 356 case ptr_ext4_super_block_offset: 357 return (void *) (((char *) sbi->s_es) + a->u.offset); 358 } 359 return NULL; 360 } 361 362 static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi) 363 { 364 return sysfs_emit(buf, "%lld\n", 365 ((time64_t)hi << 32) + le32_to_cpu(lo)); 366 } 367 368 #define print_tstamp(buf, es, tstamp) \ 369 __print_tstamp(buf, (es)->tstamp, (es)->tstamp ## _hi) 370 371 static ssize_t ext4_attr_show(struct kobject *kobj, 372 struct attribute *attr, char *buf) 373 { 374 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 375 s_kobj); 376 struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); 377 void *ptr = calc_ptr(a, sbi); 378 379 switch (a->attr_id) { 380 case attr_delayed_allocation_blocks: 381 return sysfs_emit(buf, "%llu\n", 382 (s64) EXT4_C2B(sbi, 383 percpu_counter_sum(&sbi->s_dirtyclusters_counter))); 384 case attr_session_write_kbytes: 385 return session_write_kbytes_show(sbi, buf); 386 case attr_lifetime_write_kbytes: 387 return lifetime_write_kbytes_show(sbi, buf); 388 case attr_reserved_clusters: 389 return sysfs_emit(buf, "%llu\n", 390 (unsigned long long) 391 atomic64_read(&sbi->s_resv_clusters)); 392 case attr_sra_exceeded_retry_limit: 393 return sysfs_emit(buf, "%llu\n", 394 (unsigned long long) 395 percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit)); 396 case attr_inode_readahead: 397 case attr_clusters_in_group: 398 case attr_pointer_ui: 399 if (!ptr) 400 return 0; 401 if (a->attr_ptr == ptr_ext4_super_block_offset) 402 return sysfs_emit(buf, "%u\n", 403 le32_to_cpup(ptr)); 404 else 405 return sysfs_emit(buf, "%u\n", 406 *((unsigned int *) ptr)); 407 case attr_pointer_ul: 408 if (!ptr) 409 return 0; 410 return sysfs_emit(buf, "%lu\n", 411 *((unsigned long *) ptr)); 412 case attr_pointer_u8: 413 if (!ptr) 414 return 0; 415 return sysfs_emit(buf, "%u\n", 416 *((unsigned char *) ptr)); 417 case attr_pointer_u64: 418 if (!ptr) 419 return 0; 420 if (a->attr_ptr == ptr_ext4_super_block_offset) 421 return sysfs_emit(buf, "%llu\n", 422 le64_to_cpup(ptr)); 423 else 424 return sysfs_emit(buf, "%llu\n", 425 *((unsigned long long *) ptr)); 426 case attr_pointer_string: 427 if (!ptr) 428 return 0; 429 return sysfs_emit(buf, "%.*s\n", a->attr_size, 430 (char *) ptr); 431 case attr_pointer_atomic: 432 if (!ptr) 433 return 0; 434 return sysfs_emit(buf, "%d\n", 435 atomic_read((atomic_t *) ptr)); 436 case attr_feature: 437 return sysfs_emit(buf, "supported\n"); 438 case attr_first_error_time: 439 return print_tstamp(buf, sbi->s_es, s_first_error_time); 440 case attr_last_error_time: 441 return print_tstamp(buf, sbi->s_es, s_last_error_time); 442 case attr_journal_task: 443 return journal_task_show(sbi, buf); 444 } 445 446 return 0; 447 } 448 449 static ssize_t ext4_attr_store(struct kobject *kobj, 450 struct attribute *attr, 451 const char *buf, size_t len) 452 { 453 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 454 s_kobj); 455 struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); 456 void *ptr = calc_ptr(a, sbi); 457 unsigned int t; 458 unsigned long lt; 459 int ret; 460 461 switch (a->attr_id) { 462 case attr_reserved_clusters: 463 return reserved_clusters_store(sbi, buf, len); 464 case attr_pointer_ui: 465 if (!ptr) 466 return 0; 467 ret = kstrtouint(skip_spaces(buf), 0, &t); 468 if (ret) 469 return ret; 470 if (a->attr_ptr == ptr_ext4_super_block_offset) 471 *((__le32 *) ptr) = cpu_to_le32(t); 472 else 473 *((unsigned int *) ptr) = t; 474 return len; 475 case attr_clusters_in_group: 476 if (!ptr) 477 return 0; 478 ret = kstrtouint(skip_spaces(buf), 0, &t); 479 if (ret) 480 return ret; 481 if (t > sbi->s_clusters_per_group) 482 return -EINVAL; 483 *((unsigned int *) ptr) = t; 484 return len; 485 case attr_pointer_ul: 486 if (!ptr) 487 return 0; 488 ret = kstrtoul(skip_spaces(buf), 0, <); 489 if (ret) 490 return ret; 491 *((unsigned long *) ptr) = lt; 492 return len; 493 case attr_inode_readahead: 494 return inode_readahead_blks_store(sbi, buf, len); 495 case attr_trigger_test_error: 496 return trigger_test_error(sbi, buf, len); 497 } 498 return 0; 499 } 500 501 static void ext4_sb_release(struct kobject *kobj) 502 { 503 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 504 s_kobj); 505 complete(&sbi->s_kobj_unregister); 506 } 507 508 static void ext4_feat_release(struct kobject *kobj) 509 { 510 kfree(kobj); 511 } 512 513 static const struct sysfs_ops ext4_attr_ops = { 514 .show = ext4_attr_show, 515 .store = ext4_attr_store, 516 }; 517 518 static const struct kobj_type ext4_sb_ktype = { 519 .default_groups = ext4_groups, 520 .sysfs_ops = &ext4_attr_ops, 521 .release = ext4_sb_release, 522 }; 523 524 static const struct kobj_type ext4_feat_ktype = { 525 .default_groups = ext4_feat_groups, 526 .sysfs_ops = &ext4_attr_ops, 527 .release = ext4_feat_release, 528 }; 529 530 void ext4_notify_error_sysfs(struct ext4_sb_info *sbi) 531 { 532 sysfs_notify(&sbi->s_kobj, NULL, "errors_count"); 533 } 534 535 static struct kobject *ext4_root; 536 537 static struct kobject *ext4_feat; 538 539 int ext4_register_sysfs(struct super_block *sb) 540 { 541 struct ext4_sb_info *sbi = EXT4_SB(sb); 542 int err; 543 544 init_completion(&sbi->s_kobj_unregister); 545 err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, ext4_root, 546 "%s", sb->s_id); 547 if (err) { 548 kobject_put(&sbi->s_kobj); 549 wait_for_completion(&sbi->s_kobj_unregister); 550 return err; 551 } 552 553 if (ext4_proc_root) 554 sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); 555 if (sbi->s_proc) { 556 proc_create_single_data("options", S_IRUGO, sbi->s_proc, 557 ext4_seq_options_show, sb); 558 proc_create_single_data("es_shrinker_info", S_IRUGO, 559 sbi->s_proc, ext4_seq_es_shrinker_info_show, 560 sb); 561 proc_create_single_data("fc_info", 0444, sbi->s_proc, 562 ext4_fc_info_show, sb); 563 proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc, 564 &ext4_mb_seq_groups_ops, sb); 565 proc_create_single_data("mb_stats", 0444, sbi->s_proc, 566 ext4_seq_mb_stats_show, sb); 567 proc_create_seq_data("mb_structs_summary", 0444, sbi->s_proc, 568 &ext4_mb_seq_structs_summary_ops, sb); 569 } 570 return 0; 571 } 572 573 void ext4_unregister_sysfs(struct super_block *sb) 574 { 575 struct ext4_sb_info *sbi = EXT4_SB(sb); 576 577 if (sbi->s_proc) 578 remove_proc_subtree(sb->s_id, ext4_proc_root); 579 kobject_del(&sbi->s_kobj); 580 } 581 582 int __init ext4_init_sysfs(void) 583 { 584 int ret; 585 586 ext4_root = kobject_create_and_add("ext4", fs_kobj); 587 if (!ext4_root) 588 return -ENOMEM; 589 590 ext4_feat = kzalloc(sizeof(*ext4_feat), GFP_KERNEL); 591 if (!ext4_feat) { 592 ret = -ENOMEM; 593 goto root_err; 594 } 595 596 ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype, 597 ext4_root, "features"); 598 if (ret) 599 goto feat_err; 600 601 ext4_proc_root = proc_mkdir(proc_dirname, NULL); 602 return ret; 603 604 feat_err: 605 kobject_put(ext4_feat); 606 ext4_feat = NULL; 607 root_err: 608 kobject_put(ext4_root); 609 ext4_root = NULL; 610 return ret; 611 } 612 613 void ext4_exit_sysfs(void) 614 { 615 kobject_put(ext4_feat); 616 ext4_feat = NULL; 617 kobject_put(ext4_root); 618 ext4_root = NULL; 619 remove_proc_entry(proc_dirname, NULL); 620 ext4_proc_root = NULL; 621 } 622 623