0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/time.h>
0012 #include <linux/fs.h>
0013 #include <linux/seq_file.h>
0014 #include <linux/slab.h>
0015 #include <linux/proc_fs.h>
0016 #include <linux/part_stat.h>
0017
0018 #include "ext4.h"
0019 #include "ext4_jbd2.h"
0020
0021 typedef enum {
0022 attr_noop,
0023 attr_delayed_allocation_blocks,
0024 attr_session_write_kbytes,
0025 attr_lifetime_write_kbytes,
0026 attr_reserved_clusters,
0027 attr_sra_exceeded_retry_limit,
0028 attr_inode_readahead,
0029 attr_trigger_test_error,
0030 attr_first_error_time,
0031 attr_last_error_time,
0032 attr_feature,
0033 attr_pointer_ui,
0034 attr_pointer_ul,
0035 attr_pointer_u64,
0036 attr_pointer_u8,
0037 attr_pointer_string,
0038 attr_pointer_atomic,
0039 attr_journal_task,
0040 } attr_id_t;
0041
0042 typedef enum {
0043 ptr_explicit,
0044 ptr_ext4_sb_info_offset,
0045 ptr_ext4_super_block_offset,
0046 } attr_ptr_t;
0047
0048 static const char proc_dirname[] = "fs/ext4";
0049 static struct proc_dir_entry *ext4_proc_root;
0050
0051 struct ext4_attr {
0052 struct attribute attr;
0053 short attr_id;
0054 short attr_ptr;
0055 unsigned short attr_size;
0056 union {
0057 int offset;
0058 void *explicit_ptr;
0059 } u;
0060 };
0061
0062 static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
0063 {
0064 struct super_block *sb = sbi->s_buddy_cache->i_sb;
0065
0066 return sysfs_emit(buf, "%lu\n",
0067 (part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
0068 sbi->s_sectors_written_start) >> 1);
0069 }
0070
0071 static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
0072 {
0073 struct super_block *sb = sbi->s_buddy_cache->i_sb;
0074
0075 return sysfs_emit(buf, "%llu\n",
0076 (unsigned long long)(sbi->s_kbytes_written +
0077 ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
0078 EXT4_SB(sb)->s_sectors_written_start) >> 1)));
0079 }
0080
0081 static ssize_t inode_readahead_blks_store(struct ext4_sb_info *sbi,
0082 const char *buf, size_t count)
0083 {
0084 unsigned long t;
0085 int ret;
0086
0087 ret = kstrtoul(skip_spaces(buf), 0, &t);
0088 if (ret)
0089 return ret;
0090
0091 if (t && (!is_power_of_2(t) || t > 0x40000000))
0092 return -EINVAL;
0093
0094 sbi->s_inode_readahead_blks = t;
0095 return count;
0096 }
0097
0098 static ssize_t reserved_clusters_store(struct ext4_sb_info *sbi,
0099 const char *buf, size_t count)
0100 {
0101 unsigned long long val;
0102 ext4_fsblk_t clusters = (ext4_blocks_count(sbi->s_es) >>
0103 sbi->s_cluster_bits);
0104 int ret;
0105
0106 ret = kstrtoull(skip_spaces(buf), 0, &val);
0107 if (ret || val >= clusters)
0108 return -EINVAL;
0109
0110 atomic64_set(&sbi->s_resv_clusters, val);
0111 return count;
0112 }
0113
0114 static ssize_t trigger_test_error(struct ext4_sb_info *sbi,
0115 const char *buf, size_t count)
0116 {
0117 int len = count;
0118
0119 if (!capable(CAP_SYS_ADMIN))
0120 return -EPERM;
0121
0122 if (len && buf[len-1] == '\n')
0123 len--;
0124
0125 if (len)
0126 ext4_error(sbi->s_sb, "%.*s", len, buf);
0127 return count;
0128 }
0129
0130 static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf)
0131 {
0132 if (!sbi->s_journal)
0133 return sysfs_emit(buf, "<none>\n");
0134 return sysfs_emit(buf, "%d\n",
0135 task_pid_vnr(sbi->s_journal->j_task));
0136 }
0137
0138 #define EXT4_ATTR(_name,_mode,_id) \
0139 static struct ext4_attr ext4_attr_##_name = { \
0140 .attr = {.name = __stringify(_name), .mode = _mode }, \
0141 .attr_id = attr_##_id, \
0142 }
0143
0144 #define EXT4_ATTR_FUNC(_name,_mode) EXT4_ATTR(_name,_mode,_name)
0145
0146 #define EXT4_ATTR_FEATURE(_name) EXT4_ATTR(_name, 0444, feature)
0147
0148 #define EXT4_ATTR_OFFSET(_name,_mode,_id,_struct,_elname) \
0149 static struct ext4_attr ext4_attr_##_name = { \
0150 .attr = {.name = __stringify(_name), .mode = _mode }, \
0151 .attr_id = attr_##_id, \
0152 .attr_ptr = ptr_##_struct##_offset, \
0153 .u = { \
0154 .offset = offsetof(struct _struct, _elname),\
0155 }, \
0156 }
0157
0158 #define EXT4_ATTR_STRING(_name,_mode,_size,_struct,_elname) \
0159 static struct ext4_attr ext4_attr_##_name = { \
0160 .attr = {.name = __stringify(_name), .mode = _mode }, \
0161 .attr_id = attr_pointer_string, \
0162 .attr_size = _size, \
0163 .attr_ptr = ptr_##_struct##_offset, \
0164 .u = { \
0165 .offset = offsetof(struct _struct, _elname),\
0166 }, \
0167 }
0168
0169 #define EXT4_RO_ATTR_ES_UI(_name,_elname) \
0170 EXT4_ATTR_OFFSET(_name, 0444, pointer_ui, ext4_super_block, _elname)
0171
0172 #define EXT4_RO_ATTR_ES_U8(_name,_elname) \
0173 EXT4_ATTR_OFFSET(_name, 0444, pointer_u8, ext4_super_block, _elname)
0174
0175 #define EXT4_RO_ATTR_ES_U64(_name,_elname) \
0176 EXT4_ATTR_OFFSET(_name, 0444, pointer_u64, ext4_super_block, _elname)
0177
0178 #define EXT4_RO_ATTR_ES_STRING(_name,_elname,_size) \
0179 EXT4_ATTR_STRING(_name, 0444, _size, ext4_super_block, _elname)
0180
0181 #define EXT4_RW_ATTR_SBI_UI(_name,_elname) \
0182 EXT4_ATTR_OFFSET(_name, 0644, pointer_ui, ext4_sb_info, _elname)
0183
0184 #define EXT4_RW_ATTR_SBI_UL(_name,_elname) \
0185 EXT4_ATTR_OFFSET(_name, 0644, pointer_ul, ext4_sb_info, _elname)
0186
0187 #define EXT4_RO_ATTR_SBI_ATOMIC(_name,_elname) \
0188 EXT4_ATTR_OFFSET(_name, 0444, pointer_atomic, ext4_sb_info, _elname)
0189
0190 #define EXT4_ATTR_PTR(_name,_mode,_id,_ptr) \
0191 static struct ext4_attr ext4_attr_##_name = { \
0192 .attr = {.name = __stringify(_name), .mode = _mode }, \
0193 .attr_id = attr_##_id, \
0194 .attr_ptr = ptr_explicit, \
0195 .u = { \
0196 .explicit_ptr = _ptr, \
0197 }, \
0198 }
0199
0200 #define ATTR_LIST(name) &ext4_attr_##name.attr
0201
0202 EXT4_ATTR_FUNC(delayed_allocation_blocks, 0444);
0203 EXT4_ATTR_FUNC(session_write_kbytes, 0444);
0204 EXT4_ATTR_FUNC(lifetime_write_kbytes, 0444);
0205 EXT4_ATTR_FUNC(reserved_clusters, 0644);
0206 EXT4_ATTR_FUNC(sra_exceeded_retry_limit, 0444);
0207
0208 EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, inode_readahead,
0209 ext4_sb_info, s_inode_readahead_blks);
0210 EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
0211 EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
0212 EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
0213 EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
0214 EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
0215 EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
0216 EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
0217 EXT4_RW_ATTR_SBI_UI(mb_max_inode_prealloc, s_mb_max_inode_prealloc);
0218 EXT4_RW_ATTR_SBI_UI(mb_max_linear_groups, s_mb_max_linear_groups);
0219 EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);
0220 EXT4_ATTR(trigger_fs_error, 0200, trigger_test_error);
0221 EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);
0222 EXT4_RW_ATTR_SBI_UI(err_ratelimit_burst, s_err_ratelimit_state.burst);
0223 EXT4_RW_ATTR_SBI_UI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.interval);
0224 EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst);
0225 EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);
0226 EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);
0227 #ifdef CONFIG_EXT4_DEBUG
0228 EXT4_RW_ATTR_SBI_UL(simulate_fail, s_simulate_fail);
0229 #endif
0230 EXT4_RO_ATTR_SBI_ATOMIC(warning_count, s_warning_count);
0231 EXT4_RO_ATTR_SBI_ATOMIC(msg_count, s_msg_count);
0232 EXT4_RO_ATTR_ES_UI(errors_count, s_error_count);
0233 EXT4_RO_ATTR_ES_U8(first_error_errcode, s_first_error_errcode);
0234 EXT4_RO_ATTR_ES_U8(last_error_errcode, s_last_error_errcode);
0235 EXT4_RO_ATTR_ES_UI(first_error_ino, s_first_error_ino);
0236 EXT4_RO_ATTR_ES_UI(last_error_ino, s_last_error_ino);
0237 EXT4_RO_ATTR_ES_U64(first_error_block, s_first_error_block);
0238 EXT4_RO_ATTR_ES_U64(last_error_block, s_last_error_block);
0239 EXT4_RO_ATTR_ES_UI(first_error_line, s_first_error_line);
0240 EXT4_RO_ATTR_ES_UI(last_error_line, s_last_error_line);
0241 EXT4_RO_ATTR_ES_STRING(first_error_func, s_first_error_func, 32);
0242 EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_func, 32);
0243 EXT4_ATTR(first_error_time, 0444, first_error_time);
0244 EXT4_ATTR(last_error_time, 0444, last_error_time);
0245 EXT4_ATTR(journal_task, 0444, journal_task);
0246 EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch);
0247 EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);
0248 EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks);
0249
0250 static unsigned int old_bump_val = 128;
0251 EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);
0252
0253 static struct attribute *ext4_attrs[] = {
0254 ATTR_LIST(delayed_allocation_blocks),
0255 ATTR_LIST(session_write_kbytes),
0256 ATTR_LIST(lifetime_write_kbytes),
0257 ATTR_LIST(reserved_clusters),
0258 ATTR_LIST(sra_exceeded_retry_limit),
0259 ATTR_LIST(inode_readahead_blks),
0260 ATTR_LIST(inode_goal),
0261 ATTR_LIST(mb_stats),
0262 ATTR_LIST(mb_max_to_scan),
0263 ATTR_LIST(mb_min_to_scan),
0264 ATTR_LIST(mb_order2_req),
0265 ATTR_LIST(mb_stream_req),
0266 ATTR_LIST(mb_group_prealloc),
0267 ATTR_LIST(mb_max_inode_prealloc),
0268 ATTR_LIST(mb_max_linear_groups),
0269 ATTR_LIST(max_writeback_mb_bump),
0270 ATTR_LIST(extent_max_zeroout_kb),
0271 ATTR_LIST(trigger_fs_error),
0272 ATTR_LIST(err_ratelimit_interval_ms),
0273 ATTR_LIST(err_ratelimit_burst),
0274 ATTR_LIST(warning_ratelimit_interval_ms),
0275 ATTR_LIST(warning_ratelimit_burst),
0276 ATTR_LIST(msg_ratelimit_interval_ms),
0277 ATTR_LIST(msg_ratelimit_burst),
0278 ATTR_LIST(errors_count),
0279 ATTR_LIST(warning_count),
0280 ATTR_LIST(msg_count),
0281 ATTR_LIST(first_error_ino),
0282 ATTR_LIST(last_error_ino),
0283 ATTR_LIST(first_error_block),
0284 ATTR_LIST(last_error_block),
0285 ATTR_LIST(first_error_line),
0286 ATTR_LIST(last_error_line),
0287 ATTR_LIST(first_error_func),
0288 ATTR_LIST(last_error_func),
0289 ATTR_LIST(first_error_errcode),
0290 ATTR_LIST(last_error_errcode),
0291 ATTR_LIST(first_error_time),
0292 ATTR_LIST(last_error_time),
0293 ATTR_LIST(journal_task),
0294 #ifdef CONFIG_EXT4_DEBUG
0295 ATTR_LIST(simulate_fail),
0296 #endif
0297 ATTR_LIST(mb_prefetch),
0298 ATTR_LIST(mb_prefetch_limit),
0299 ATTR_LIST(last_trim_minblks),
0300 NULL,
0301 };
0302 ATTRIBUTE_GROUPS(ext4);
0303
0304
0305 EXT4_ATTR_FEATURE(lazy_itable_init);
0306 EXT4_ATTR_FEATURE(batched_discard);
0307 EXT4_ATTR_FEATURE(meta_bg_resize);
0308 #ifdef CONFIG_FS_ENCRYPTION
0309 EXT4_ATTR_FEATURE(encryption);
0310 EXT4_ATTR_FEATURE(test_dummy_encryption_v2);
0311 #endif
0312 #if IS_ENABLED(CONFIG_UNICODE)
0313 EXT4_ATTR_FEATURE(casefold);
0314 #endif
0315 #ifdef CONFIG_FS_VERITY
0316 EXT4_ATTR_FEATURE(verity);
0317 #endif
0318 EXT4_ATTR_FEATURE(metadata_csum_seed);
0319 EXT4_ATTR_FEATURE(fast_commit);
0320 #if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION)
0321 EXT4_ATTR_FEATURE(encrypted_casefold);
0322 #endif
0323
0324 static struct attribute *ext4_feat_attrs[] = {
0325 ATTR_LIST(lazy_itable_init),
0326 ATTR_LIST(batched_discard),
0327 ATTR_LIST(meta_bg_resize),
0328 #ifdef CONFIG_FS_ENCRYPTION
0329 ATTR_LIST(encryption),
0330 ATTR_LIST(test_dummy_encryption_v2),
0331 #endif
0332 #if IS_ENABLED(CONFIG_UNICODE)
0333 ATTR_LIST(casefold),
0334 #endif
0335 #ifdef CONFIG_FS_VERITY
0336 ATTR_LIST(verity),
0337 #endif
0338 ATTR_LIST(metadata_csum_seed),
0339 ATTR_LIST(fast_commit),
0340 #if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION)
0341 ATTR_LIST(encrypted_casefold),
0342 #endif
0343 NULL,
0344 };
0345 ATTRIBUTE_GROUPS(ext4_feat);
0346
0347 static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi)
0348 {
0349 switch (a->attr_ptr) {
0350 case ptr_explicit:
0351 return a->u.explicit_ptr;
0352 case ptr_ext4_sb_info_offset:
0353 return (void *) (((char *) sbi) + a->u.offset);
0354 case ptr_ext4_super_block_offset:
0355 return (void *) (((char *) sbi->s_es) + a->u.offset);
0356 }
0357 return NULL;
0358 }
0359
0360 static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi)
0361 {
0362 return sysfs_emit(buf, "%lld\n",
0363 ((time64_t)hi << 32) + le32_to_cpu(lo));
0364 }
0365
0366 #define print_tstamp(buf, es, tstamp) \
0367 __print_tstamp(buf, (es)->tstamp, (es)->tstamp ## _hi)
0368
0369 static ssize_t ext4_attr_show(struct kobject *kobj,
0370 struct attribute *attr, char *buf)
0371 {
0372 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
0373 s_kobj);
0374 struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
0375 void *ptr = calc_ptr(a, sbi);
0376
0377 switch (a->attr_id) {
0378 case attr_delayed_allocation_blocks:
0379 return sysfs_emit(buf, "%llu\n",
0380 (s64) EXT4_C2B(sbi,
0381 percpu_counter_sum(&sbi->s_dirtyclusters_counter)));
0382 case attr_session_write_kbytes:
0383 return session_write_kbytes_show(sbi, buf);
0384 case attr_lifetime_write_kbytes:
0385 return lifetime_write_kbytes_show(sbi, buf);
0386 case attr_reserved_clusters:
0387 return sysfs_emit(buf, "%llu\n",
0388 (unsigned long long)
0389 atomic64_read(&sbi->s_resv_clusters));
0390 case attr_sra_exceeded_retry_limit:
0391 return sysfs_emit(buf, "%llu\n",
0392 (unsigned long long)
0393 percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit));
0394 case attr_inode_readahead:
0395 case attr_pointer_ui:
0396 if (!ptr)
0397 return 0;
0398 if (a->attr_ptr == ptr_ext4_super_block_offset)
0399 return sysfs_emit(buf, "%u\n",
0400 le32_to_cpup(ptr));
0401 else
0402 return sysfs_emit(buf, "%u\n",
0403 *((unsigned int *) ptr));
0404 case attr_pointer_ul:
0405 if (!ptr)
0406 return 0;
0407 return sysfs_emit(buf, "%lu\n",
0408 *((unsigned long *) ptr));
0409 case attr_pointer_u8:
0410 if (!ptr)
0411 return 0;
0412 return sysfs_emit(buf, "%u\n",
0413 *((unsigned char *) ptr));
0414 case attr_pointer_u64:
0415 if (!ptr)
0416 return 0;
0417 if (a->attr_ptr == ptr_ext4_super_block_offset)
0418 return sysfs_emit(buf, "%llu\n",
0419 le64_to_cpup(ptr));
0420 else
0421 return sysfs_emit(buf, "%llu\n",
0422 *((unsigned long long *) ptr));
0423 case attr_pointer_string:
0424 if (!ptr)
0425 return 0;
0426 return sysfs_emit(buf, "%.*s\n", a->attr_size,
0427 (char *) ptr);
0428 case attr_pointer_atomic:
0429 if (!ptr)
0430 return 0;
0431 return sysfs_emit(buf, "%d\n",
0432 atomic_read((atomic_t *) ptr));
0433 case attr_feature:
0434 return sysfs_emit(buf, "supported\n");
0435 case attr_first_error_time:
0436 return print_tstamp(buf, sbi->s_es, s_first_error_time);
0437 case attr_last_error_time:
0438 return print_tstamp(buf, sbi->s_es, s_last_error_time);
0439 case attr_journal_task:
0440 return journal_task_show(sbi, buf);
0441 }
0442
0443 return 0;
0444 }
0445
0446 static ssize_t ext4_attr_store(struct kobject *kobj,
0447 struct attribute *attr,
0448 const char *buf, size_t len)
0449 {
0450 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
0451 s_kobj);
0452 struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
0453 void *ptr = calc_ptr(a, sbi);
0454 unsigned long t;
0455 int ret;
0456
0457 switch (a->attr_id) {
0458 case attr_reserved_clusters:
0459 return reserved_clusters_store(sbi, buf, len);
0460 case attr_pointer_ui:
0461 if (!ptr)
0462 return 0;
0463 ret = kstrtoul(skip_spaces(buf), 0, &t);
0464 if (ret)
0465 return ret;
0466 if (a->attr_ptr == ptr_ext4_super_block_offset)
0467 *((__le32 *) ptr) = cpu_to_le32(t);
0468 else
0469 *((unsigned int *) ptr) = t;
0470 return len;
0471 case attr_pointer_ul:
0472 if (!ptr)
0473 return 0;
0474 ret = kstrtoul(skip_spaces(buf), 0, &t);
0475 if (ret)
0476 return ret;
0477 *((unsigned long *) ptr) = t;
0478 return len;
0479 case attr_inode_readahead:
0480 return inode_readahead_blks_store(sbi, buf, len);
0481 case attr_trigger_test_error:
0482 return trigger_test_error(sbi, buf, len);
0483 }
0484 return 0;
0485 }
0486
0487 static void ext4_sb_release(struct kobject *kobj)
0488 {
0489 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
0490 s_kobj);
0491 complete(&sbi->s_kobj_unregister);
0492 }
0493
0494 static const struct sysfs_ops ext4_attr_ops = {
0495 .show = ext4_attr_show,
0496 .store = ext4_attr_store,
0497 };
0498
0499 static struct kobj_type ext4_sb_ktype = {
0500 .default_groups = ext4_groups,
0501 .sysfs_ops = &ext4_attr_ops,
0502 .release = ext4_sb_release,
0503 };
0504
0505 static struct kobj_type ext4_feat_ktype = {
0506 .default_groups = ext4_feat_groups,
0507 .sysfs_ops = &ext4_attr_ops,
0508 .release = (void (*)(struct kobject *))kfree,
0509 };
0510
0511 void ext4_notify_error_sysfs(struct ext4_sb_info *sbi)
0512 {
0513 sysfs_notify(&sbi->s_kobj, NULL, "errors_count");
0514 }
0515
0516 static struct kobject *ext4_root;
0517
0518 static struct kobject *ext4_feat;
0519
0520 int ext4_register_sysfs(struct super_block *sb)
0521 {
0522 struct ext4_sb_info *sbi = EXT4_SB(sb);
0523 int err;
0524
0525 init_completion(&sbi->s_kobj_unregister);
0526 err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, ext4_root,
0527 "%s", sb->s_id);
0528 if (err) {
0529 kobject_put(&sbi->s_kobj);
0530 wait_for_completion(&sbi->s_kobj_unregister);
0531 return err;
0532 }
0533
0534 if (ext4_proc_root)
0535 sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
0536 if (sbi->s_proc) {
0537 proc_create_single_data("options", S_IRUGO, sbi->s_proc,
0538 ext4_seq_options_show, sb);
0539 proc_create_single_data("es_shrinker_info", S_IRUGO,
0540 sbi->s_proc, ext4_seq_es_shrinker_info_show,
0541 sb);
0542 proc_create_single_data("fc_info", 0444, sbi->s_proc,
0543 ext4_fc_info_show, sb);
0544 proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc,
0545 &ext4_mb_seq_groups_ops, sb);
0546 proc_create_single_data("mb_stats", 0444, sbi->s_proc,
0547 ext4_seq_mb_stats_show, sb);
0548 proc_create_seq_data("mb_structs_summary", 0444, sbi->s_proc,
0549 &ext4_mb_seq_structs_summary_ops, sb);
0550 }
0551 return 0;
0552 }
0553
0554 void ext4_unregister_sysfs(struct super_block *sb)
0555 {
0556 struct ext4_sb_info *sbi = EXT4_SB(sb);
0557
0558 if (sbi->s_proc)
0559 remove_proc_subtree(sb->s_id, ext4_proc_root);
0560 kobject_del(&sbi->s_kobj);
0561 }
0562
0563 int __init ext4_init_sysfs(void)
0564 {
0565 int ret;
0566
0567 ext4_root = kobject_create_and_add("ext4", fs_kobj);
0568 if (!ext4_root)
0569 return -ENOMEM;
0570
0571 ext4_feat = kzalloc(sizeof(*ext4_feat), GFP_KERNEL);
0572 if (!ext4_feat) {
0573 ret = -ENOMEM;
0574 goto root_err;
0575 }
0576
0577 ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype,
0578 ext4_root, "features");
0579 if (ret)
0580 goto feat_err;
0581
0582 ext4_proc_root = proc_mkdir(proc_dirname, NULL);
0583 return ret;
0584
0585 feat_err:
0586 kobject_put(ext4_feat);
0587 ext4_feat = NULL;
0588 root_err:
0589 kobject_put(ext4_root);
0590 ext4_root = NULL;
0591 return ret;
0592 }
0593
0594 void ext4_exit_sysfs(void)
0595 {
0596 kobject_put(ext4_feat);
0597 ext4_feat = NULL;
0598 kobject_put(ext4_root);
0599 ext4_root = NULL;
0600 remove_proc_entry(proc_dirname, NULL);
0601 ext4_proc_root = NULL;
0602 }
0603