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