Something went wrong. Try again.
(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699// SPDX-License-Identifier: GPL-2.0/* * linux/fs/ext4/sysfs.c * * Copyright (C) 1992, 1993, 1994, 1995 * Remy Card (card@masi.ibp.fr) * Theodore Ts'o (tytso@mit.edu) * */
#include <linux/time.h>#include <linux/fs.h>#include <linux/seq_file.h>#include <linux/slab.h>#include <linux/proc_fs.h>#include <linux/part_stat.h>
#include "ext4.h"#include "ext4_jbd2.h"
typedef enum { attr_noop, attr_delayed_allocation_blocks, attr_session_write_kbytes, attr_lifetime_write_kbytes, attr_reserved_clusters, attr_sra_exceeded_retry_limit, attr_inode_readahead, attr_trigger_test_error, attr_first_error_time, attr_last_error_time, attr_clusters_in_group, attr_mb_order, attr_feature, attr_pointer_pi, attr_pointer_ui, attr_pointer_ul, attr_pointer_u64, attr_pointer_u8, attr_pointer_string, attr_pointer_atomic, attr_journal_task, attr_err_report_sec,} attr_id_t;
typedef enum { ptr_explicit, ptr_ext4_sb_info_offset, ptr_ext4_super_block_offset,} attr_ptr_t;
static const char proc_dirname[] = "fs/ext4";static struct proc_dir_entry *ext4_proc_root;
struct ext4_attr { struct attribute attr; short attr_id; short attr_ptr; unsigned short attr_size; union { int offset; void *explicit_ptr; } u;};
static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf){ struct super_block *sb = sbi->s_buddy_cache->i_sb;
return sysfs_emit(buf, "%lu\n", (part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - sbi->s_sectors_written_start) >> 1);}
static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf){ struct super_block *sb = sbi->s_buddy_cache->i_sb;
return sysfs_emit(buf, "%llu\n", (unsigned long long)(sbi->s_kbytes_written + ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - EXT4_SB(sb)->s_sectors_written_start) >> 1)));}
static ssize_t inode_readahead_blks_store(struct ext4_sb_info *sbi, const char *buf, size_t count){ unsigned long t; int ret;
ret = kstrtoul(skip_spaces(buf), 0, &t); if (ret) return ret;
if (t && (!is_power_of_2(t) || t > 0x40000000)) return -EINVAL;
sbi->s_inode_readahead_blks = t; return count;}
static ssize_t reserved_clusters_store(struct ext4_sb_info *sbi, const char *buf, size_t count){ unsigned long long val; ext4_fsblk_t clusters = (ext4_blocks_count(sbi->s_es) >> sbi->s_cluster_bits); int ret;
ret = kstrtoull(skip_spaces(buf), 0, &val); if (ret || val >= clusters || (s64)val < 0) return -EINVAL;
atomic64_set(&sbi->s_resv_clusters, val); return count;}
static ssize_t trigger_test_error(struct ext4_sb_info *sbi, const char *buf, size_t count){ int len = count;
if (!capable(CAP_SYS_ADMIN)) return -EPERM;
if (len && buf[len-1] == '\n') len--;
if (len) ext4_error(sbi->s_sb, "%.*s", len, buf); return count;}
static ssize_t err_report_sec_store(struct ext4_sb_info *sbi, const char *buf, size_t count){ unsigned long t; int ret;
ret = kstrtoul(skip_spaces(buf), 0, &t); if (ret) return ret;
/*the maximum time interval must not exceed one year.*/ if (t > (365*24*60*60)) return -EINVAL;
if (sbi->s_err_report_sec == t) /*nothing to do*/ goto out; else if (!sbi->s_err_report_sec && t) { timer_setup(&sbi->s_err_report, print_daily_error_info, 0); } else if (sbi->s_err_report_sec && !t) { timer_delete_sync(&sbi->s_err_report); goto out; }
sbi->s_err_report_sec = t; mod_timer(&sbi->s_err_report, jiffies + secs_to_jiffies(sbi->s_err_report_sec));
out: return count;}
static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf){ if (!sbi->s_journal) return sysfs_emit(buf, "<none>\n"); return sysfs_emit(buf, "%d\n", task_pid_vnr(sbi->s_journal->j_task));}
#define EXT4_ATTR(_name,_mode,_id) \static struct ext4_attr ext4_attr_##_name = { \ .attr = {.name = __stringify(_name), .mode = _mode }, \ .attr_id = attr_##_id, \}
#define EXT4_ATTR_FUNC(_name,_mode) EXT4_ATTR(_name,_mode,_name)
#define EXT4_ATTR_FEATURE(_name) EXT4_ATTR(_name, 0444, feature)
#define EXT4_ATTR_OFFSET(_name,_mode,_id,_struct,_elname) \static struct ext4_attr ext4_attr_##_name = { \ .attr = {.name = __stringify(_name), .mode = _mode }, \ .attr_id = attr_##_id, \ .attr_ptr = ptr_##_struct##_offset, \ .u = { \ .offset = offsetof(struct _struct, _elname),\ }, \}
#define EXT4_ATTR_STRING(_name,_mode,_size,_struct,_elname) \static struct ext4_attr ext4_attr_##_name = { \ .attr = {.name = __stringify(_name), .mode = _mode }, \ .attr_id = attr_pointer_string, \ .attr_size = _size, \ .attr_ptr = ptr_##_struct##_offset, \ .u = { \ .offset = offsetof(struct _struct, _elname),\ }, \}
#define EXT4_RO_ATTR_ES_UI(_name,_elname) \ EXT4_ATTR_OFFSET(_name, 0444, pointer_ui, ext4_super_block, _elname)
#define EXT4_RO_ATTR_ES_U8(_name,_elname) \ EXT4_ATTR_OFFSET(_name, 0444, pointer_u8, ext4_super_block, _elname)
#define EXT4_RO_ATTR_ES_U64(_name,_elname) \ EXT4_ATTR_OFFSET(_name, 0444, pointer_u64, ext4_super_block, _elname)
#define EXT4_RO_ATTR_ES_STRING(_name,_elname,_size) \ EXT4_ATTR_STRING(_name, 0444, _size, ext4_super_block, _elname)
#define EXT4_RW_ATTR_SBI_PI(_name,_elname) \ EXT4_ATTR_OFFSET(_name, 0644, pointer_pi, ext4_sb_info, _elname)
#define EXT4_RW_ATTR_SBI_UI(_name,_elname) \ EXT4_ATTR_OFFSET(_name, 0644, pointer_ui, ext4_sb_info, _elname)
#define EXT4_RW_ATTR_SBI_UL(_name,_elname) \ EXT4_ATTR_OFFSET(_name, 0644, pointer_ul, ext4_sb_info, _elname)
#define EXT4_RO_ATTR_SBI_ATOMIC(_name,_elname) \ EXT4_ATTR_OFFSET(_name, 0444, pointer_atomic, ext4_sb_info, _elname)
#define EXT4_ATTR_PTR(_name,_mode,_id,_ptr) \static struct ext4_attr ext4_attr_##_name = { \ .attr = {.name = __stringify(_name), .mode = _mode }, \ .attr_id = attr_##_id, \ .attr_ptr = ptr_explicit, \ .u = { \ .explicit_ptr = _ptr, \ }, \}
#define ATTR_LIST(name) &ext4_attr_##name.attr
EXT4_ATTR_FUNC(delayed_allocation_blocks, 0444);EXT4_ATTR_FUNC(session_write_kbytes, 0444);EXT4_ATTR_FUNC(lifetime_write_kbytes, 0444);EXT4_ATTR_FUNC(reserved_clusters, 0644);EXT4_ATTR_FUNC(sra_exceeded_retry_limit, 0444);
EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, inode_readahead, ext4_sb_info, s_inode_readahead_blks);EXT4_ATTR_OFFSET(mb_group_prealloc, 0644, clusters_in_group, ext4_sb_info, s_mb_group_prealloc);EXT4_ATTR_OFFSET(mb_best_avail_max_trim_order, 0644, mb_order, ext4_sb_info, s_mb_best_avail_max_trim_order);EXT4_ATTR_OFFSET(err_report_sec, 0644, err_report_sec, ext4_sb_info, s_err_report_sec);EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);EXT4_RW_ATTR_SBI_UI(mb_max_linear_groups, s_mb_max_linear_groups);EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);EXT4_ATTR(trigger_fs_error, 0200, trigger_test_error);EXT4_RW_ATTR_SBI_PI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);EXT4_RW_ATTR_SBI_PI(err_ratelimit_burst, s_err_ratelimit_state.burst);EXT4_RW_ATTR_SBI_PI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.interval);EXT4_RW_ATTR_SBI_PI(warning_ratelimit_burst, s_warning_ratelimit_state.burst);EXT4_RW_ATTR_SBI_PI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);EXT4_RW_ATTR_SBI_PI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);#ifdef CONFIG_EXT4_DEBUGEXT4_RW_ATTR_SBI_UL(simulate_fail, s_simulate_fail);#endifEXT4_RO_ATTR_SBI_ATOMIC(warning_count, s_warning_count);EXT4_RO_ATTR_SBI_ATOMIC(msg_count, s_msg_count);EXT4_RO_ATTR_ES_UI(errors_count, s_error_count);EXT4_RO_ATTR_ES_U8(first_error_errcode, s_first_error_errcode);EXT4_RO_ATTR_ES_U8(last_error_errcode, s_last_error_errcode);EXT4_RO_ATTR_ES_UI(first_error_ino, s_first_error_ino);EXT4_RO_ATTR_ES_UI(last_error_ino, s_last_error_ino);EXT4_RO_ATTR_ES_U64(first_error_block, s_first_error_block);EXT4_RO_ATTR_ES_U64(last_error_block, s_last_error_block);EXT4_RO_ATTR_ES_UI(first_error_line, s_first_error_line);EXT4_RO_ATTR_ES_UI(last_error_line, s_last_error_line);EXT4_RO_ATTR_ES_STRING(first_error_func, s_first_error_func, 32);EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_func, 32);EXT4_ATTR(first_error_time, 0444, first_error_time);EXT4_ATTR(last_error_time, 0444, last_error_time);EXT4_ATTR(journal_task, 0444, journal_task);EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch);EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks);EXT4_RW_ATTR_SBI_UI(sb_update_sec, s_sb_update_sec);EXT4_RW_ATTR_SBI_UI(sb_update_kb, s_sb_update_kb);
static unsigned int old_bump_val = 128;EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);
static struct attribute *ext4_attrs[] = { ATTR_LIST(delayed_allocation_blocks), ATTR_LIST(session_write_kbytes), ATTR_LIST(lifetime_write_kbytes), ATTR_LIST(reserved_clusters), ATTR_LIST(sra_exceeded_retry_limit), ATTR_LIST(inode_readahead_blks), ATTR_LIST(inode_goal), ATTR_LIST(mb_stats), ATTR_LIST(mb_max_to_scan), ATTR_LIST(mb_min_to_scan), ATTR_LIST(mb_order2_req), ATTR_LIST(mb_stream_req), ATTR_LIST(mb_group_prealloc), ATTR_LIST(mb_max_linear_groups), ATTR_LIST(max_writeback_mb_bump), ATTR_LIST(extent_max_zeroout_kb), ATTR_LIST(trigger_fs_error), ATTR_LIST(err_ratelimit_interval_ms), ATTR_LIST(err_ratelimit_burst), ATTR_LIST(warning_ratelimit_interval_ms), ATTR_LIST(warning_ratelimit_burst), ATTR_LIST(msg_ratelimit_interval_ms), ATTR_LIST(msg_ratelimit_burst), ATTR_LIST(mb_best_avail_max_trim_order), ATTR_LIST(errors_count), ATTR_LIST(warning_count), ATTR_LIST(msg_count), ATTR_LIST(first_error_ino), ATTR_LIST(last_error_ino), ATTR_LIST(first_error_block), ATTR_LIST(last_error_block), ATTR_LIST(first_error_line), ATTR_LIST(last_error_line), ATTR_LIST(first_error_func), ATTR_LIST(last_error_func), ATTR_LIST(first_error_errcode), ATTR_LIST(last_error_errcode), ATTR_LIST(first_error_time), ATTR_LIST(last_error_time), ATTR_LIST(journal_task),#ifdef CONFIG_EXT4_DEBUG ATTR_LIST(simulate_fail),#endif ATTR_LIST(mb_prefetch), ATTR_LIST(mb_prefetch_limit), ATTR_LIST(last_trim_minblks), ATTR_LIST(sb_update_sec), ATTR_LIST(sb_update_kb), ATTR_LIST(err_report_sec), NULL,};ATTRIBUTE_GROUPS(ext4);
/* Features this copy of ext4 supports */EXT4_ATTR_FEATURE(lazy_itable_init);EXT4_ATTR_FEATURE(batched_discard);EXT4_ATTR_FEATURE(meta_bg_resize);#ifdef CONFIG_FS_ENCRYPTIONEXT4_ATTR_FEATURE(encryption);EXT4_ATTR_FEATURE(test_dummy_encryption_v2);#endif#if IS_ENABLED(CONFIG_UNICODE)EXT4_ATTR_FEATURE(casefold);#endif#ifdef CONFIG_FS_VERITYEXT4_ATTR_FEATURE(verity);#endifEXT4_ATTR_FEATURE(metadata_csum_seed);EXT4_ATTR_FEATURE(fast_commit);#if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION)EXT4_ATTR_FEATURE(encrypted_casefold);#endif#ifdef CONFIG_TRANSPARENT_HUGEPAGEEXT4_ATTR_FEATURE(blocksize_gt_pagesize);#endif
static struct attribute *ext4_feat_attrs[] = { ATTR_LIST(lazy_itable_init), ATTR_LIST(batched_discard), ATTR_LIST(meta_bg_resize),#ifdef CONFIG_FS_ENCRYPTION ATTR_LIST(encryption), ATTR_LIST(test_dummy_encryption_v2),#endif#if IS_ENABLED(CONFIG_UNICODE) ATTR_LIST(casefold),#endif#ifdef CONFIG_FS_VERITY ATTR_LIST(verity),#endif ATTR_LIST(metadata_csum_seed), ATTR_LIST(fast_commit),#if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION) ATTR_LIST(encrypted_casefold),#endif#ifdef CONFIG_TRANSPARENT_HUGEPAGE ATTR_LIST(blocksize_gt_pagesize),#endif NULL,};ATTRIBUTE_GROUPS(ext4_feat);
static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi){ switch (a->attr_ptr) { case ptr_explicit: return a->u.explicit_ptr; case ptr_ext4_sb_info_offset: return (void *) (((char *) sbi) + a->u.offset); case ptr_ext4_super_block_offset: return (void *) (((char *) sbi->s_es) + a->u.offset); } return NULL;}
static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi){ return sysfs_emit(buf, "%lld\n", ((time64_t)hi << 32) + le32_to_cpu(lo));}
#define print_tstamp(buf, es, tstamp) \ __print_tstamp(buf, (es)->tstamp, (es)->tstamp ## _hi)
static ssize_t ext4_generic_attr_show(struct ext4_attr *a, struct ext4_sb_info *sbi, char *buf){ void *ptr = calc_ptr(a, sbi);
if (!ptr) return 0;
switch (a->attr_id) { case attr_inode_readahead: case attr_clusters_in_group: case attr_mb_order: case attr_pointer_pi: case attr_pointer_ui: if (a->attr_ptr == ptr_ext4_super_block_offset) return sysfs_emit(buf, "%u\n", le32_to_cpup(ptr)); return sysfs_emit(buf, "%u\n", *((unsigned int *) ptr)); case attr_pointer_ul: case attr_err_report_sec: return sysfs_emit(buf, "%lu\n", *((unsigned long *) ptr)); case attr_pointer_u8: return sysfs_emit(buf, "%u\n", *((unsigned char *) ptr)); case attr_pointer_u64: if (a->attr_ptr == ptr_ext4_super_block_offset) return sysfs_emit(buf, "%llu\n", le64_to_cpup(ptr)); return sysfs_emit(buf, "%llu\n", *((unsigned long long *) ptr)); case attr_pointer_string: return sysfs_emit(buf, "%.*s\n", a->attr_size, (char *) ptr); case attr_pointer_atomic: return sysfs_emit(buf, "%d\n", atomic_read((atomic_t *) ptr)); } return 0;}
static ssize_t ext4_attr_show(struct kobject *kobj, struct attribute *attr, char *buf){ struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, s_kobj); struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
switch (a->attr_id) { case attr_delayed_allocation_blocks: return sysfs_emit(buf, "%llu\n", (s64) EXT4_C2B(sbi, percpu_counter_sum(&sbi->s_dirtyclusters_counter))); case attr_session_write_kbytes: return session_write_kbytes_show(sbi, buf); case attr_lifetime_write_kbytes: return lifetime_write_kbytes_show(sbi, buf); case attr_reserved_clusters: return sysfs_emit(buf, "%llu\n", (unsigned long long) atomic64_read(&sbi->s_resv_clusters)); case attr_sra_exceeded_retry_limit: return sysfs_emit(buf, "%llu\n", (unsigned long long) percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit)); case attr_feature: return sysfs_emit(buf, "supported\n"); case attr_first_error_time: return print_tstamp(buf, sbi->s_es, s_first_error_time); case attr_last_error_time: return print_tstamp(buf, sbi->s_es, s_last_error_time); case attr_journal_task: return journal_task_show(sbi, buf); default: return ext4_generic_attr_show(a, sbi, buf); }}
static ssize_t ext4_generic_attr_store(struct ext4_attr *a, struct ext4_sb_info *sbi, const char *buf, size_t len){ int ret; unsigned int t; unsigned long lt; void *ptr = calc_ptr(a, sbi);
if (!ptr) return 0;
switch (a->attr_id) { case attr_pointer_pi: ret = kstrtouint(skip_spaces(buf), 0, &t); if (ret) return ret; if ((int)t < 0) return -EINVAL; *((unsigned int *) ptr) = t; return len; case attr_pointer_ui: ret = kstrtouint(skip_spaces(buf), 0, &t); if (ret) return ret; if (a->attr_ptr == ptr_ext4_super_block_offset) *((__le32 *) ptr) = cpu_to_le32(t); else *((unsigned int *) ptr) = t; return len; case attr_mb_order: ret = kstrtouint(skip_spaces(buf), 0, &t); if (ret) return ret; if (t > 64) return -EINVAL; *((unsigned int *) ptr) = t; return len; case attr_clusters_in_group: ret = kstrtouint(skip_spaces(buf), 0, &t); if (ret) return ret; if (t > sbi->s_clusters_per_group) return -EINVAL; *((unsigned int *) ptr) = t; return len; case attr_pointer_ul: ret = kstrtoul(skip_spaces(buf), 0, <); if (ret) return ret; *((unsigned long *) ptr) = lt; return len; } return 0;}
static ssize_t ext4_attr_store(struct kobject *kobj, struct attribute *attr, const char *buf, size_t len){ struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, s_kobj); struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
switch (a->attr_id) { case attr_reserved_clusters: return reserved_clusters_store(sbi, buf, len); case attr_inode_readahead: return inode_readahead_blks_store(sbi, buf, len); case attr_trigger_test_error: return trigger_test_error(sbi, buf, len); case attr_err_report_sec: return err_report_sec_store(sbi, buf, len); default: return ext4_generic_attr_store(a, sbi, buf, len); }}
static void ext4_sb_release(struct kobject *kobj){ struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, s_kobj); complete(&sbi->s_kobj_unregister);}
static void ext4_feat_release(struct kobject *kobj){ kfree(kobj);}
static const struct sysfs_ops ext4_attr_ops = { .show = ext4_attr_show, .store = ext4_attr_store,};
static const struct kobj_type ext4_sb_ktype = { .default_groups = ext4_groups, .sysfs_ops = &ext4_attr_ops, .release = ext4_sb_release,};
static const struct kobj_type ext4_feat_ktype = { .default_groups = ext4_feat_groups, .sysfs_ops = &ext4_attr_ops, .release = ext4_feat_release,};
void ext4_notify_error_sysfs(struct ext4_sb_info *sbi){ mutex_lock(&sbi->s_error_notify_mutex); if (sbi->s_kobj.state_in_sysfs) sysfs_notify(&sbi->s_kobj, NULL, "errors_count"); mutex_unlock(&sbi->s_error_notify_mutex);}
static struct kobject *ext4_root;
static struct kobject *ext4_feat;
int ext4_register_sysfs(struct super_block *sb){ struct ext4_sb_info *sbi = EXT4_SB(sb); int err;
init_completion(&sbi->s_kobj_unregister); mutex_lock(&sbi->s_error_notify_mutex); err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, ext4_root, "%s", sb->s_id); mutex_unlock(&sbi->s_error_notify_mutex); if (err) { kobject_put(&sbi->s_kobj); wait_for_completion(&sbi->s_kobj_unregister); return err; }
if (ext4_proc_root) sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); if (sbi->s_proc) { proc_create_single_data("options", S_IRUGO, sbi->s_proc, ext4_seq_options_show, sb); proc_create_single_data("es_shrinker_info", S_IRUGO, sbi->s_proc, ext4_seq_es_shrinker_info_show, sb); proc_create_single_data("fc_info", 0444, sbi->s_proc, ext4_fc_info_show, sb); proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc, &ext4_mb_seq_groups_ops, sb); proc_create_single_data("mb_stats", 0444, sbi->s_proc, ext4_seq_mb_stats_show, sb); proc_create_seq_data("mb_structs_summary", 0444, sbi->s_proc, &ext4_mb_seq_structs_summary_ops, sb); } return 0;}
void ext4_unregister_sysfs(struct super_block *sb){ struct ext4_sb_info *sbi = EXT4_SB(sb);
if (sbi->s_proc) remove_proc_subtree(sb->s_id, ext4_proc_root);
mutex_lock(&sbi->s_error_notify_mutex); kobject_del(&sbi->s_kobj); mutex_unlock(&sbi->s_error_notify_mutex);}
int __init ext4_init_sysfs(void){ int ret;
ext4_root = kobject_create_and_add("ext4", fs_kobj); if (!ext4_root) return -ENOMEM;
ext4_feat = kzalloc_obj(*ext4_feat); if (!ext4_feat) { ret = -ENOMEM; goto root_err; }
ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype, ext4_root, "features"); if (ret) goto feat_err;
ext4_proc_root = proc_mkdir(proc_dirname, NULL); return ret;
feat_err: kobject_put(ext4_feat); ext4_feat = NULL;root_err: kobject_put(ext4_root); ext4_root = NULL; return ret;}
void ext4_exit_sysfs(void){ kobject_put(ext4_feat); ext4_feat = NULL; kobject_put(ext4_root); ext4_root = NULL; remove_proc_entry(proc_dirname, NULL); ext4_proc_root = NULL;}