Skip to content

Commit b7b2a57

Browse files
LiBaokun96tytso
authored andcommitted
ext4: add new attr pointer attr_mb_order
The s_mb_best_avail_max_trim_order is of type unsigned int, and has a range of values well beyond the normal use of the mb_order. Although the mballoc code is careful enough that large numbers don't matter there, but this can mislead the sysadmin into thinking that it's normal to set such values. Hence add a new attr_id attr_mb_order with values in the range [0, 64] to avoid storing garbage values and make us more resilient to surprises in the future. Suggested-by: Jan Kara <jack@suse.cz> Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20240319113325.3110393-6-libaokun1@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 13df4d4 commit b7b2a57

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

fs/ext4/sysfs.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef enum {
3030
attr_first_error_time,
3131
attr_last_error_time,
3232
attr_clusters_in_group,
33+
attr_mb_order,
3334
attr_feature,
3435
attr_pointer_ui,
3536
attr_pointer_ul,
@@ -210,6 +211,8 @@ EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, inode_readahead,
210211
ext4_sb_info, s_inode_readahead_blks);
211212
EXT4_ATTR_OFFSET(mb_group_prealloc, 0644, clusters_in_group,
212213
ext4_sb_info, s_mb_group_prealloc);
214+
EXT4_ATTR_OFFSET(mb_best_avail_max_trim_order, 0644, mb_order,
215+
ext4_sb_info, s_mb_best_avail_max_trim_order);
213216
EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
214217
EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
215218
EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
@@ -225,7 +228,6 @@ EXT4_RW_ATTR_SBI_UI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.int
225228
EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst);
226229
EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);
227230
EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);
228-
EXT4_RW_ATTR_SBI_UI(mb_best_avail_max_trim_order, s_mb_best_avail_max_trim_order);
229231
#ifdef CONFIG_EXT4_DEBUG
230232
EXT4_RW_ATTR_SBI_UL(simulate_fail, s_simulate_fail);
231233
#endif
@@ -379,6 +381,7 @@ static ssize_t ext4_generic_attr_show(struct ext4_attr *a,
379381
switch (a->attr_id) {
380382
case attr_inode_readahead:
381383
case attr_clusters_in_group:
384+
case attr_mb_order:
382385
case attr_pointer_ui:
383386
if (a->attr_ptr == ptr_ext4_super_block_offset)
384387
return sysfs_emit(buf, "%u\n", le32_to_cpup(ptr));
@@ -458,6 +461,14 @@ static ssize_t ext4_generic_attr_store(struct ext4_attr *a,
458461
else
459462
*((unsigned int *) ptr) = t;
460463
return len;
464+
case attr_mb_order:
465+
ret = kstrtouint(skip_spaces(buf), 0, &t);
466+
if (ret)
467+
return ret;
468+
if (t > 64)
469+
return -EINVAL;
470+
*((unsigned int *) ptr) = t;
471+
return len;
461472
case attr_clusters_in_group:
462473
ret = kstrtouint(skip_spaces(buf), 0, &t);
463474
if (ret)

0 commit comments

Comments
 (0)