1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2b5799018STheodore Ts'o /* 3b5799018STheodore Ts'o * linux/fs/ext4/sysfs.c 4b5799018STheodore Ts'o * 5b5799018STheodore Ts'o * Copyright (C) 1992, 1993, 1994, 1995 6b5799018STheodore Ts'o * Remy Card (card@masi.ibp.fr) 7b5799018STheodore Ts'o * Theodore Ts'o (tytso@mit.edu) 8b5799018STheodore Ts'o * 9b5799018STheodore Ts'o */ 10b5799018STheodore Ts'o 11b5799018STheodore Ts'o #include <linux/time.h> 12b5799018STheodore Ts'o #include <linux/fs.h> 13b5799018STheodore Ts'o #include <linux/seq_file.h> 14b99fee58SRiccardo Schirone #include <linux/slab.h> 15b5799018STheodore Ts'o #include <linux/proc_fs.h> 16b5799018STheodore Ts'o 17b5799018STheodore Ts'o #include "ext4.h" 18b5799018STheodore Ts'o #include "ext4_jbd2.h" 19b5799018STheodore Ts'o 2076d33bcaSTheodore Ts'o typedef enum { 2176d33bcaSTheodore Ts'o attr_noop, 2276d33bcaSTheodore Ts'o attr_delayed_allocation_blocks, 2376d33bcaSTheodore Ts'o attr_session_write_kbytes, 2476d33bcaSTheodore Ts'o attr_lifetime_write_kbytes, 2576d33bcaSTheodore Ts'o attr_reserved_clusters, 2676d33bcaSTheodore Ts'o attr_inode_readahead, 2776d33bcaSTheodore Ts'o attr_trigger_test_error, 286a0678a7SArnd Bergmann attr_first_error_time, 296a0678a7SArnd Bergmann attr_last_error_time, 3076d33bcaSTheodore Ts'o attr_feature, 3176d33bcaSTheodore Ts'o attr_pointer_ui, 3276d33bcaSTheodore Ts'o attr_pointer_atomic, 33bc1d69d6SKonstantin Khlebnikov attr_journal_task, 3476d33bcaSTheodore Ts'o } attr_id_t; 3576d33bcaSTheodore Ts'o 3676d33bcaSTheodore Ts'o typedef enum { 3776d33bcaSTheodore Ts'o ptr_explicit, 3876d33bcaSTheodore Ts'o ptr_ext4_sb_info_offset, 3976d33bcaSTheodore Ts'o ptr_ext4_super_block_offset, 4076d33bcaSTheodore Ts'o } attr_ptr_t; 4176d33bcaSTheodore Ts'o 42d6006186SEric Biggers static const char proc_dirname[] = "fs/ext4"; 43ebd173beSTheodore Ts'o static struct proc_dir_entry *ext4_proc_root; 44ebd173beSTheodore Ts'o 45b5799018STheodore Ts'o struct ext4_attr { 46b5799018STheodore Ts'o struct attribute attr; 4776d33bcaSTheodore Ts'o short attr_id; 4876d33bcaSTheodore Ts'o short attr_ptr; 49b5799018STheodore Ts'o union { 50b5799018STheodore Ts'o int offset; 5176d33bcaSTheodore Ts'o void *explicit_ptr; 52b5799018STheodore Ts'o } u; 53b5799018STheodore Ts'o }; 54b5799018STheodore Ts'o 556ca06829STyson Nottingham static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf) 56b5799018STheodore Ts'o { 57b5799018STheodore Ts'o struct super_block *sb = sbi->s_buddy_cache->i_sb; 58b5799018STheodore Ts'o 59b5799018STheodore Ts'o if (!sb->s_bdev->bd_part) 60b5799018STheodore Ts'o return snprintf(buf, PAGE_SIZE, "0\n"); 61b5799018STheodore Ts'o return snprintf(buf, PAGE_SIZE, "%lu\n", 62dbae2c55SMichael Callahan (part_stat_read(sb->s_bdev->bd_part, 63dbae2c55SMichael Callahan sectors[STAT_WRITE]) - 64b5799018STheodore Ts'o sbi->s_sectors_written_start) >> 1); 65b5799018STheodore Ts'o } 66b5799018STheodore Ts'o 676ca06829STyson Nottingham static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf) 68b5799018STheodore Ts'o { 69b5799018STheodore Ts'o struct super_block *sb = sbi->s_buddy_cache->i_sb; 70b5799018STheodore Ts'o 71b5799018STheodore Ts'o if (!sb->s_bdev->bd_part) 72b5799018STheodore Ts'o return snprintf(buf, PAGE_SIZE, "0\n"); 73b5799018STheodore Ts'o return snprintf(buf, PAGE_SIZE, "%llu\n", 74b5799018STheodore Ts'o (unsigned long long)(sbi->s_kbytes_written + 75dbae2c55SMichael Callahan ((part_stat_read(sb->s_bdev->bd_part, 76dbae2c55SMichael Callahan sectors[STAT_WRITE]) - 77b5799018STheodore Ts'o EXT4_SB(sb)->s_sectors_written_start) >> 1))); 78b5799018STheodore Ts'o } 79b5799018STheodore Ts'o 806ca06829STyson Nottingham static ssize_t inode_readahead_blks_store(struct ext4_sb_info *sbi, 81b5799018STheodore Ts'o const char *buf, size_t count) 82b5799018STheodore Ts'o { 83b5799018STheodore Ts'o unsigned long t; 84b5799018STheodore Ts'o int ret; 85b5799018STheodore Ts'o 86b5799018STheodore Ts'o ret = kstrtoul(skip_spaces(buf), 0, &t); 87b5799018STheodore Ts'o if (ret) 88b5799018STheodore Ts'o return ret; 89b5799018STheodore Ts'o 90b5799018STheodore Ts'o if (t && (!is_power_of_2(t) || t > 0x40000000)) 91b5799018STheodore Ts'o return -EINVAL; 92b5799018STheodore Ts'o 93b5799018STheodore Ts'o sbi->s_inode_readahead_blks = t; 94b5799018STheodore Ts'o return count; 95b5799018STheodore Ts'o } 96b5799018STheodore Ts'o 976ca06829STyson Nottingham static ssize_t reserved_clusters_store(struct ext4_sb_info *sbi, 98b5799018STheodore Ts'o const char *buf, size_t count) 99b5799018STheodore Ts'o { 100b5799018STheodore Ts'o unsigned long long val; 101b5799018STheodore Ts'o ext4_fsblk_t clusters = (ext4_blocks_count(sbi->s_es) >> 102b5799018STheodore Ts'o sbi->s_cluster_bits); 10376d33bcaSTheodore Ts'o int ret; 104b5799018STheodore Ts'o 10576d33bcaSTheodore Ts'o ret = kstrtoull(skip_spaces(buf), 0, &val); 1061ea1516fSChao Yu if (ret || val >= clusters) 107b5799018STheodore Ts'o return -EINVAL; 108b5799018STheodore Ts'o 109b5799018STheodore Ts'o atomic64_set(&sbi->s_resv_clusters, val); 110b5799018STheodore Ts'o return count; 111b5799018STheodore Ts'o } 112b5799018STheodore Ts'o 1136ca06829STyson Nottingham static ssize_t trigger_test_error(struct ext4_sb_info *sbi, 114b5799018STheodore Ts'o const char *buf, size_t count) 115b5799018STheodore Ts'o { 116b5799018STheodore Ts'o int len = count; 117b5799018STheodore Ts'o 118b5799018STheodore Ts'o if (!capable(CAP_SYS_ADMIN)) 119b5799018STheodore Ts'o return -EPERM; 120b5799018STheodore Ts'o 121b5799018STheodore Ts'o if (len && buf[len-1] == '\n') 122b5799018STheodore Ts'o len--; 123b5799018STheodore Ts'o 124b5799018STheodore Ts'o if (len) 125b5799018STheodore Ts'o ext4_error(sbi->s_sb, "%.*s", len, buf); 126b5799018STheodore Ts'o return count; 127b5799018STheodore Ts'o } 128b5799018STheodore Ts'o 129bc1d69d6SKonstantin Khlebnikov static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf) 130bc1d69d6SKonstantin Khlebnikov { 131bc1d69d6SKonstantin Khlebnikov if (!sbi->s_journal) 132bc1d69d6SKonstantin Khlebnikov return snprintf(buf, PAGE_SIZE, "<none>\n"); 133bc1d69d6SKonstantin Khlebnikov return snprintf(buf, PAGE_SIZE, "%d\n", 134bc1d69d6SKonstantin Khlebnikov task_pid_vnr(sbi->s_journal->j_task)); 135bc1d69d6SKonstantin Khlebnikov } 136bc1d69d6SKonstantin Khlebnikov 13776d33bcaSTheodore Ts'o #define EXT4_ATTR(_name,_mode,_id) \ 138b5799018STheodore Ts'o static struct ext4_attr ext4_attr_##_name = { \ 139b5799018STheodore Ts'o .attr = {.name = __stringify(_name), .mode = _mode }, \ 14076d33bcaSTheodore Ts'o .attr_id = attr_##_id, \ 14176d33bcaSTheodore Ts'o } 14276d33bcaSTheodore Ts'o 14376d33bcaSTheodore Ts'o #define EXT4_ATTR_FUNC(_name,_mode) EXT4_ATTR(_name,_mode,_name) 14476d33bcaSTheodore Ts'o 14576d33bcaSTheodore Ts'o #define EXT4_ATTR_FEATURE(_name) EXT4_ATTR(_name, 0444, feature) 14676d33bcaSTheodore Ts'o 14776d33bcaSTheodore Ts'o #define EXT4_ATTR_OFFSET(_name,_mode,_id,_struct,_elname) \ 14876d33bcaSTheodore Ts'o static struct ext4_attr ext4_attr_##_name = { \ 14976d33bcaSTheodore Ts'o .attr = {.name = __stringify(_name), .mode = _mode }, \ 15076d33bcaSTheodore Ts'o .attr_id = attr_##_id, \ 15176d33bcaSTheodore Ts'o .attr_ptr = ptr_##_struct##_offset, \ 152b5799018STheodore Ts'o .u = { \ 15376d33bcaSTheodore Ts'o .offset = offsetof(struct _struct, _elname),\ 154b5799018STheodore Ts'o }, \ 155b5799018STheodore Ts'o } 156b5799018STheodore Ts'o 15776d33bcaSTheodore Ts'o #define EXT4_RO_ATTR_ES_UI(_name,_elname) \ 15876d33bcaSTheodore Ts'o EXT4_ATTR_OFFSET(_name, 0444, pointer_ui, ext4_super_block, _elname) 15976d33bcaSTheodore Ts'o 16076d33bcaSTheodore Ts'o #define EXT4_RW_ATTR_SBI_UI(_name,_elname) \ 16176d33bcaSTheodore Ts'o EXT4_ATTR_OFFSET(_name, 0644, pointer_ui, ext4_sb_info, _elname) 16276d33bcaSTheodore Ts'o 16376d33bcaSTheodore Ts'o #define EXT4_ATTR_PTR(_name,_mode,_id,_ptr) \ 164b5799018STheodore Ts'o static struct ext4_attr ext4_attr_##_name = { \ 165b5799018STheodore Ts'o .attr = {.name = __stringify(_name), .mode = _mode }, \ 16676d33bcaSTheodore Ts'o .attr_id = attr_##_id, \ 16776d33bcaSTheodore Ts'o .attr_ptr = ptr_explicit, \ 168b5799018STheodore Ts'o .u = { \ 16976d33bcaSTheodore Ts'o .explicit_ptr = _ptr, \ 170b5799018STheodore Ts'o }, \ 171b5799018STheodore Ts'o } 172b5799018STheodore Ts'o 173b5799018STheodore Ts'o #define ATTR_LIST(name) &ext4_attr_##name.attr 174b5799018STheodore Ts'o 17576d33bcaSTheodore Ts'o EXT4_ATTR_FUNC(delayed_allocation_blocks, 0444); 17676d33bcaSTheodore Ts'o EXT4_ATTR_FUNC(session_write_kbytes, 0444); 17776d33bcaSTheodore Ts'o EXT4_ATTR_FUNC(lifetime_write_kbytes, 0444); 17876d33bcaSTheodore Ts'o EXT4_ATTR_FUNC(reserved_clusters, 0644); 17976d33bcaSTheodore Ts'o 18076d33bcaSTheodore Ts'o EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, inode_readahead, 18176d33bcaSTheodore Ts'o ext4_sb_info, s_inode_readahead_blks); 182b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal); 183b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats); 184b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan); 185b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan); 186b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs); 187b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request); 188b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc); 189b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb); 19076d33bcaSTheodore Ts'o EXT4_ATTR(trigger_fs_error, 0200, trigger_test_error); 191b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval); 192b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(err_ratelimit_burst, s_err_ratelimit_state.burst); 193b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.interval); 194b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst); 195b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval); 196b5799018STheodore Ts'o EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst); 197b5799018STheodore Ts'o EXT4_RO_ATTR_ES_UI(errors_count, s_error_count); 1986a0678a7SArnd Bergmann EXT4_ATTR(first_error_time, 0444, first_error_time); 1996a0678a7SArnd Bergmann EXT4_ATTR(last_error_time, 0444, last_error_time); 200bc1d69d6SKonstantin Khlebnikov EXT4_ATTR(journal_task, 0444, journal_task); 201b5799018STheodore Ts'o 20276d33bcaSTheodore Ts'o static unsigned int old_bump_val = 128; 20376d33bcaSTheodore Ts'o EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val); 20476d33bcaSTheodore Ts'o 205b5799018STheodore Ts'o static struct attribute *ext4_attrs[] = { 206b5799018STheodore Ts'o ATTR_LIST(delayed_allocation_blocks), 207b5799018STheodore Ts'o ATTR_LIST(session_write_kbytes), 208b5799018STheodore Ts'o ATTR_LIST(lifetime_write_kbytes), 209b5799018STheodore Ts'o ATTR_LIST(reserved_clusters), 210b5799018STheodore Ts'o ATTR_LIST(inode_readahead_blks), 211b5799018STheodore Ts'o ATTR_LIST(inode_goal), 212b5799018STheodore Ts'o ATTR_LIST(mb_stats), 213b5799018STheodore Ts'o ATTR_LIST(mb_max_to_scan), 214b5799018STheodore Ts'o ATTR_LIST(mb_min_to_scan), 215b5799018STheodore Ts'o ATTR_LIST(mb_order2_req), 216b5799018STheodore Ts'o ATTR_LIST(mb_stream_req), 217b5799018STheodore Ts'o ATTR_LIST(mb_group_prealloc), 218b5799018STheodore Ts'o ATTR_LIST(max_writeback_mb_bump), 219b5799018STheodore Ts'o ATTR_LIST(extent_max_zeroout_kb), 220b5799018STheodore Ts'o ATTR_LIST(trigger_fs_error), 221b5799018STheodore Ts'o ATTR_LIST(err_ratelimit_interval_ms), 222b5799018STheodore Ts'o ATTR_LIST(err_ratelimit_burst), 223b5799018STheodore Ts'o ATTR_LIST(warning_ratelimit_interval_ms), 224b5799018STheodore Ts'o ATTR_LIST(warning_ratelimit_burst), 225b5799018STheodore Ts'o ATTR_LIST(msg_ratelimit_interval_ms), 226b5799018STheodore Ts'o ATTR_LIST(msg_ratelimit_burst), 227b5799018STheodore Ts'o ATTR_LIST(errors_count), 228b5799018STheodore Ts'o ATTR_LIST(first_error_time), 229b5799018STheodore Ts'o ATTR_LIST(last_error_time), 230bc1d69d6SKonstantin Khlebnikov ATTR_LIST(journal_task), 231b5799018STheodore Ts'o NULL, 232b5799018STheodore Ts'o }; 233b5799018STheodore Ts'o 234b5799018STheodore Ts'o /* Features this copy of ext4 supports */ 23576d33bcaSTheodore Ts'o EXT4_ATTR_FEATURE(lazy_itable_init); 23676d33bcaSTheodore Ts'o EXT4_ATTR_FEATURE(batched_discard); 23776d33bcaSTheodore Ts'o EXT4_ATTR_FEATURE(meta_bg_resize); 238643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 23976d33bcaSTheodore Ts'o EXT4_ATTR_FEATURE(encryption); 240c4704a4fSEric Biggers #endif 241db90f419STheodore Ts'o #ifdef CONFIG_UNICODE 242db90f419STheodore Ts'o EXT4_ATTR_FEATURE(casefold); 243db90f419STheodore Ts'o #endif 2448c81bd8fSDarrick J. Wong EXT4_ATTR_FEATURE(metadata_csum_seed); 245b5799018STheodore Ts'o 246b5799018STheodore Ts'o static struct attribute *ext4_feat_attrs[] = { 247b5799018STheodore Ts'o ATTR_LIST(lazy_itable_init), 248b5799018STheodore Ts'o ATTR_LIST(batched_discard), 249b5799018STheodore Ts'o ATTR_LIST(meta_bg_resize), 250643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 251b5799018STheodore Ts'o ATTR_LIST(encryption), 252c4704a4fSEric Biggers #endif 253db90f419STheodore Ts'o #ifdef CONFIG_UNICODE 254db90f419STheodore Ts'o ATTR_LIST(casefold), 255db90f419STheodore Ts'o #endif 2568c81bd8fSDarrick J. Wong ATTR_LIST(metadata_csum_seed), 257b5799018STheodore Ts'o NULL, 258b5799018STheodore Ts'o }; 259b5799018STheodore Ts'o 26076d33bcaSTheodore Ts'o static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi) 26176d33bcaSTheodore Ts'o { 26276d33bcaSTheodore Ts'o switch (a->attr_ptr) { 26376d33bcaSTheodore Ts'o case ptr_explicit: 26476d33bcaSTheodore Ts'o return a->u.explicit_ptr; 26576d33bcaSTheodore Ts'o case ptr_ext4_sb_info_offset: 26676d33bcaSTheodore Ts'o return (void *) (((char *) sbi) + a->u.offset); 26776d33bcaSTheodore Ts'o case ptr_ext4_super_block_offset: 26876d33bcaSTheodore Ts'o return (void *) (((char *) sbi->s_es) + a->u.offset); 26976d33bcaSTheodore Ts'o } 27076d33bcaSTheodore Ts'o return NULL; 27176d33bcaSTheodore Ts'o } 27276d33bcaSTheodore Ts'o 2736a0678a7SArnd Bergmann static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi) 2746a0678a7SArnd Bergmann { 2756a0678a7SArnd Bergmann return snprintf(buf, PAGE_SIZE, "%lld", 2766a0678a7SArnd Bergmann ((time64_t)hi << 32) + le32_to_cpu(lo)); 2776a0678a7SArnd Bergmann } 2786a0678a7SArnd Bergmann 2796a0678a7SArnd Bergmann #define print_tstamp(buf, es, tstamp) \ 2806a0678a7SArnd Bergmann __print_tstamp(buf, (es)->tstamp, (es)->tstamp ## _hi) 2816a0678a7SArnd Bergmann 282b5799018STheodore Ts'o static ssize_t ext4_attr_show(struct kobject *kobj, 283b5799018STheodore Ts'o struct attribute *attr, char *buf) 284b5799018STheodore Ts'o { 285b5799018STheodore Ts'o struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 286b5799018STheodore Ts'o s_kobj); 287b5799018STheodore Ts'o struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); 28876d33bcaSTheodore Ts'o void *ptr = calc_ptr(a, sbi); 289b5799018STheodore Ts'o 29076d33bcaSTheodore Ts'o switch (a->attr_id) { 29176d33bcaSTheodore Ts'o case attr_delayed_allocation_blocks: 29276d33bcaSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%llu\n", 29376d33bcaSTheodore Ts'o (s64) EXT4_C2B(sbi, 29476d33bcaSTheodore Ts'o percpu_counter_sum(&sbi->s_dirtyclusters_counter))); 29576d33bcaSTheodore Ts'o case attr_session_write_kbytes: 2966ca06829STyson Nottingham return session_write_kbytes_show(sbi, buf); 29776d33bcaSTheodore Ts'o case attr_lifetime_write_kbytes: 2986ca06829STyson Nottingham return lifetime_write_kbytes_show(sbi, buf); 29976d33bcaSTheodore Ts'o case attr_reserved_clusters: 30076d33bcaSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%llu\n", 30176d33bcaSTheodore Ts'o (unsigned long long) 30276d33bcaSTheodore Ts'o atomic64_read(&sbi->s_resv_clusters)); 30376d33bcaSTheodore Ts'o case attr_inode_readahead: 30476d33bcaSTheodore Ts'o case attr_pointer_ui: 30576d33bcaSTheodore Ts'o if (!ptr) 30676d33bcaSTheodore Ts'o return 0; 307a4d2aadcSArnd Bergmann if (a->attr_ptr == ptr_ext4_super_block_offset) 308a4d2aadcSArnd Bergmann return snprintf(buf, PAGE_SIZE, "%u\n", 309a4d2aadcSArnd Bergmann le32_to_cpup(ptr)); 310a4d2aadcSArnd Bergmann else 31176d33bcaSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%u\n", 31276d33bcaSTheodore Ts'o *((unsigned int *) ptr)); 31376d33bcaSTheodore Ts'o case attr_pointer_atomic: 31476d33bcaSTheodore Ts'o if (!ptr) 31576d33bcaSTheodore Ts'o return 0; 31676d33bcaSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "%d\n", 31776d33bcaSTheodore Ts'o atomic_read((atomic_t *) ptr)); 31876d33bcaSTheodore Ts'o case attr_feature: 31976d33bcaSTheodore Ts'o return snprintf(buf, PAGE_SIZE, "supported\n"); 3206a0678a7SArnd Bergmann case attr_first_error_time: 3216a0678a7SArnd Bergmann return print_tstamp(buf, sbi->s_es, s_first_error_time); 3226a0678a7SArnd Bergmann case attr_last_error_time: 3236a0678a7SArnd Bergmann return print_tstamp(buf, sbi->s_es, s_last_error_time); 324bc1d69d6SKonstantin Khlebnikov case attr_journal_task: 325bc1d69d6SKonstantin Khlebnikov return journal_task_show(sbi, buf); 32676d33bcaSTheodore Ts'o } 32776d33bcaSTheodore Ts'o 32876d33bcaSTheodore Ts'o return 0; 329b5799018STheodore Ts'o } 330b5799018STheodore Ts'o 331b5799018STheodore Ts'o static ssize_t ext4_attr_store(struct kobject *kobj, 332b5799018STheodore Ts'o struct attribute *attr, 333b5799018STheodore Ts'o const char *buf, size_t len) 334b5799018STheodore Ts'o { 335b5799018STheodore Ts'o struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 336b5799018STheodore Ts'o s_kobj); 337b5799018STheodore Ts'o struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); 33876d33bcaSTheodore Ts'o void *ptr = calc_ptr(a, sbi); 33976d33bcaSTheodore Ts'o unsigned long t; 34076d33bcaSTheodore Ts'o int ret; 341b5799018STheodore Ts'o 34276d33bcaSTheodore Ts'o switch (a->attr_id) { 34376d33bcaSTheodore Ts'o case attr_reserved_clusters: 3446ca06829STyson Nottingham return reserved_clusters_store(sbi, buf, len); 34576d33bcaSTheodore Ts'o case attr_pointer_ui: 34676d33bcaSTheodore Ts'o if (!ptr) 34776d33bcaSTheodore Ts'o return 0; 34876d33bcaSTheodore Ts'o ret = kstrtoul(skip_spaces(buf), 0, &t); 34976d33bcaSTheodore Ts'o if (ret) 35076d33bcaSTheodore Ts'o return ret; 351a4d2aadcSArnd Bergmann if (a->attr_ptr == ptr_ext4_super_block_offset) 352a4d2aadcSArnd Bergmann *((__le32 *) ptr) = cpu_to_le32(t); 353a4d2aadcSArnd Bergmann else 35476d33bcaSTheodore Ts'o *((unsigned int *) ptr) = t; 35576d33bcaSTheodore Ts'o return len; 35676d33bcaSTheodore Ts'o case attr_inode_readahead: 3576ca06829STyson Nottingham return inode_readahead_blks_store(sbi, buf, len); 35876d33bcaSTheodore Ts'o case attr_trigger_test_error: 3596ca06829STyson Nottingham return trigger_test_error(sbi, buf, len); 36076d33bcaSTheodore Ts'o } 36176d33bcaSTheodore Ts'o return 0; 362b5799018STheodore Ts'o } 363b5799018STheodore Ts'o 364b5799018STheodore Ts'o static void ext4_sb_release(struct kobject *kobj) 365b5799018STheodore Ts'o { 366b5799018STheodore Ts'o struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, 367b5799018STheodore Ts'o s_kobj); 368b5799018STheodore Ts'o complete(&sbi->s_kobj_unregister); 369b5799018STheodore Ts'o } 370b5799018STheodore Ts'o 371b5799018STheodore Ts'o static const struct sysfs_ops ext4_attr_ops = { 372b5799018STheodore Ts'o .show = ext4_attr_show, 373b5799018STheodore Ts'o .store = ext4_attr_store, 374b5799018STheodore Ts'o }; 375b5799018STheodore Ts'o 376b5799018STheodore Ts'o static struct kobj_type ext4_sb_ktype = { 377b5799018STheodore Ts'o .default_attrs = ext4_attrs, 378b5799018STheodore Ts'o .sysfs_ops = &ext4_attr_ops, 379b5799018STheodore Ts'o .release = ext4_sb_release, 380b5799018STheodore Ts'o }; 381b5799018STheodore Ts'o 382b5799018STheodore Ts'o static struct kobj_type ext4_feat_ktype = { 383b5799018STheodore Ts'o .default_attrs = ext4_feat_attrs, 38476d33bcaSTheodore Ts'o .sysfs_ops = &ext4_attr_ops, 385b99fee58SRiccardo Schirone .release = (void (*)(struct kobject *))kfree, 386b5799018STheodore Ts'o }; 387b5799018STheodore Ts'o 388bc1420aeSTyson Nottingham static struct kobject *ext4_root; 389bc1420aeSTyson Nottingham 390b99fee58SRiccardo Schirone static struct kobject *ext4_feat; 391b5799018STheodore Ts'o 392b5799018STheodore Ts'o int ext4_register_sysfs(struct super_block *sb) 393b5799018STheodore Ts'o { 394b5799018STheodore Ts'o struct ext4_sb_info *sbi = EXT4_SB(sb); 395ebd173beSTheodore Ts'o int err; 396b5799018STheodore Ts'o 397b5799018STheodore Ts'o init_completion(&sbi->s_kobj_unregister); 398bc1420aeSTyson Nottingham err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, ext4_root, 399b5799018STheodore Ts'o "%s", sb->s_id); 40095c4df02SRiccardo Schirone if (err) { 40195c4df02SRiccardo Schirone kobject_put(&sbi->s_kobj); 40295c4df02SRiccardo Schirone wait_for_completion(&sbi->s_kobj_unregister); 403ebd173beSTheodore Ts'o return err; 40495c4df02SRiccardo Schirone } 405ebd173beSTheodore Ts'o 406ebd173beSTheodore Ts'o if (ext4_proc_root) 407ebd173beSTheodore Ts'o sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); 408ebd173beSTheodore Ts'o if (sbi->s_proc) { 409247dbed8SChristoph Hellwig proc_create_single_data("options", S_IRUGO, sbi->s_proc, 410247dbed8SChristoph Hellwig ext4_seq_options_show, sb); 411247dbed8SChristoph Hellwig proc_create_single_data("es_shrinker_info", S_IRUGO, 412247dbed8SChristoph Hellwig sbi->s_proc, ext4_seq_es_shrinker_info_show, 413247dbed8SChristoph Hellwig sb); 414247dbed8SChristoph Hellwig proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc, 415247dbed8SChristoph Hellwig &ext4_mb_seq_groups_ops, sb); 416ebd173beSTheodore Ts'o } 417ebd173beSTheodore Ts'o return 0; 418ebd173beSTheodore Ts'o } 419ebd173beSTheodore Ts'o 420ebd173beSTheodore Ts'o void ext4_unregister_sysfs(struct super_block *sb) 421ebd173beSTheodore Ts'o { 422ebd173beSTheodore Ts'o struct ext4_sb_info *sbi = EXT4_SB(sb); 423ebd173beSTheodore Ts'o 424247dbed8SChristoph Hellwig if (sbi->s_proc) 425247dbed8SChristoph Hellwig remove_proc_subtree(sb->s_id, ext4_proc_root); 426ebd173beSTheodore Ts'o kobject_del(&sbi->s_kobj); 427b5799018STheodore Ts'o } 428b5799018STheodore Ts'o 429b5799018STheodore Ts'o int __init ext4_init_sysfs(void) 430b5799018STheodore Ts'o { 431b5799018STheodore Ts'o int ret; 432b5799018STheodore Ts'o 433bc1420aeSTyson Nottingham ext4_root = kobject_create_and_add("ext4", fs_kobj); 434bc1420aeSTyson Nottingham if (!ext4_root) 4355dc39711SRiccardo Schirone return -ENOMEM; 4365dc39711SRiccardo Schirone 437b99fee58SRiccardo Schirone ext4_feat = kzalloc(sizeof(*ext4_feat), GFP_KERNEL); 438b99fee58SRiccardo Schirone if (!ext4_feat) { 439b99fee58SRiccardo Schirone ret = -ENOMEM; 440bc1420aeSTyson Nottingham goto root_err; 44195c4df02SRiccardo Schirone } 442b99fee58SRiccardo Schirone 443b99fee58SRiccardo Schirone ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype, 444bc1420aeSTyson Nottingham ext4_root, "features"); 445b99fee58SRiccardo Schirone if (ret) 446b99fee58SRiccardo Schirone goto feat_err; 447b99fee58SRiccardo Schirone 448b99fee58SRiccardo Schirone ext4_proc_root = proc_mkdir(proc_dirname, NULL); 449b99fee58SRiccardo Schirone return ret; 450b99fee58SRiccardo Schirone 451b99fee58SRiccardo Schirone feat_err: 452b99fee58SRiccardo Schirone kobject_put(ext4_feat); 453c2e5df76STyson Nottingham ext4_feat = NULL; 454bc1420aeSTyson Nottingham root_err: 455bc1420aeSTyson Nottingham kobject_put(ext4_root); 456bc1420aeSTyson Nottingham ext4_root = NULL; 457b5799018STheodore Ts'o return ret; 458b5799018STheodore Ts'o } 459b5799018STheodore Ts'o 460b5799018STheodore Ts'o void ext4_exit_sysfs(void) 461b5799018STheodore Ts'o { 462b99fee58SRiccardo Schirone kobject_put(ext4_feat); 463c2e5df76STyson Nottingham ext4_feat = NULL; 464bc1420aeSTyson Nottingham kobject_put(ext4_root); 465bc1420aeSTyson Nottingham ext4_root = NULL; 466ebd173beSTheodore Ts'o remove_proc_entry(proc_dirname, NULL); 467ebd173beSTheodore Ts'o ext4_proc_root = NULL; 468b5799018STheodore Ts'o } 469b5799018STheodore Ts'o 470