| .. | .. |
|---|
| 13 | 13 | #include <linux/seq_file.h> |
|---|
| 14 | 14 | #include <linux/slab.h> |
|---|
| 15 | 15 | #include <linux/proc_fs.h> |
|---|
| 16 | +#include <linux/part_stat.h> |
|---|
| 16 | 17 | |
|---|
| 17 | 18 | #include "ext4.h" |
|---|
| 18 | 19 | #include "ext4_jbd2.h" |
|---|
| .. | .. |
|---|
| 23 | 24 | attr_session_write_kbytes, |
|---|
| 24 | 25 | attr_lifetime_write_kbytes, |
|---|
| 25 | 26 | attr_reserved_clusters, |
|---|
| 27 | + attr_sra_exceeded_retry_limit, |
|---|
| 26 | 28 | attr_inode_readahead, |
|---|
| 27 | 29 | attr_trigger_test_error, |
|---|
| 28 | 30 | attr_first_error_time, |
|---|
| 29 | 31 | attr_last_error_time, |
|---|
| 30 | 32 | attr_feature, |
|---|
| 31 | 33 | attr_pointer_ui, |
|---|
| 34 | + attr_pointer_ul, |
|---|
| 35 | + attr_pointer_u64, |
|---|
| 36 | + attr_pointer_u8, |
|---|
| 37 | + attr_pointer_string, |
|---|
| 32 | 38 | attr_pointer_atomic, |
|---|
| 39 | + attr_journal_task, |
|---|
| 33 | 40 | } attr_id_t; |
|---|
| 34 | 41 | |
|---|
| 35 | 42 | typedef enum { |
|---|
| .. | .. |
|---|
| 45 | 52 | struct attribute attr; |
|---|
| 46 | 53 | short attr_id; |
|---|
| 47 | 54 | short attr_ptr; |
|---|
| 55 | + unsigned short attr_size; |
|---|
| 48 | 56 | union { |
|---|
| 49 | 57 | int offset; |
|---|
| 50 | 58 | void *explicit_ptr; |
|---|
| .. | .. |
|---|
| 125 | 133 | return count; |
|---|
| 126 | 134 | } |
|---|
| 127 | 135 | |
|---|
| 136 | +static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf) |
|---|
| 137 | +{ |
|---|
| 138 | + if (!sbi->s_journal) |
|---|
| 139 | + return snprintf(buf, PAGE_SIZE, "<none>\n"); |
|---|
| 140 | + return snprintf(buf, PAGE_SIZE, "%d\n", |
|---|
| 141 | + task_pid_vnr(sbi->s_journal->j_task)); |
|---|
| 142 | +} |
|---|
| 143 | + |
|---|
| 128 | 144 | #define EXT4_ATTR(_name,_mode,_id) \ |
|---|
| 129 | 145 | static struct ext4_attr ext4_attr_##_name = { \ |
|---|
| 130 | 146 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
|---|
| .. | .. |
|---|
| 145 | 161 | }, \ |
|---|
| 146 | 162 | } |
|---|
| 147 | 163 | |
|---|
| 164 | +#define EXT4_ATTR_STRING(_name,_mode,_size,_struct,_elname) \ |
|---|
| 165 | +static struct ext4_attr ext4_attr_##_name = { \ |
|---|
| 166 | + .attr = {.name = __stringify(_name), .mode = _mode }, \ |
|---|
| 167 | + .attr_id = attr_pointer_string, \ |
|---|
| 168 | + .attr_size = _size, \ |
|---|
| 169 | + .attr_ptr = ptr_##_struct##_offset, \ |
|---|
| 170 | + .u = { \ |
|---|
| 171 | + .offset = offsetof(struct _struct, _elname),\ |
|---|
| 172 | + }, \ |
|---|
| 173 | +} |
|---|
| 174 | + |
|---|
| 148 | 175 | #define EXT4_RO_ATTR_ES_UI(_name,_elname) \ |
|---|
| 149 | 176 | EXT4_ATTR_OFFSET(_name, 0444, pointer_ui, ext4_super_block, _elname) |
|---|
| 150 | 177 | |
|---|
| 178 | +#define EXT4_RO_ATTR_ES_U8(_name,_elname) \ |
|---|
| 179 | + EXT4_ATTR_OFFSET(_name, 0444, pointer_u8, ext4_super_block, _elname) |
|---|
| 180 | + |
|---|
| 181 | +#define EXT4_RO_ATTR_ES_U64(_name,_elname) \ |
|---|
| 182 | + EXT4_ATTR_OFFSET(_name, 0444, pointer_u64, ext4_super_block, _elname) |
|---|
| 183 | + |
|---|
| 184 | +#define EXT4_RO_ATTR_ES_STRING(_name,_elname,_size) \ |
|---|
| 185 | + EXT4_ATTR_STRING(_name, 0444, _size, ext4_super_block, _elname) |
|---|
| 186 | + |
|---|
| 151 | 187 | #define EXT4_RW_ATTR_SBI_UI(_name,_elname) \ |
|---|
| 152 | 188 | EXT4_ATTR_OFFSET(_name, 0644, pointer_ui, ext4_sb_info, _elname) |
|---|
| 189 | + |
|---|
| 190 | +#define EXT4_RW_ATTR_SBI_UL(_name,_elname) \ |
|---|
| 191 | + EXT4_ATTR_OFFSET(_name, 0644, pointer_ul, ext4_sb_info, _elname) |
|---|
| 192 | + |
|---|
| 193 | +#define EXT4_RO_ATTR_SBI_ATOMIC(_name,_elname) \ |
|---|
| 194 | + EXT4_ATTR_OFFSET(_name, 0444, pointer_atomic, ext4_sb_info, _elname) |
|---|
| 153 | 195 | |
|---|
| 154 | 196 | #define EXT4_ATTR_PTR(_name,_mode,_id,_ptr) \ |
|---|
| 155 | 197 | static struct ext4_attr ext4_attr_##_name = { \ |
|---|
| .. | .. |
|---|
| 167 | 209 | EXT4_ATTR_FUNC(session_write_kbytes, 0444); |
|---|
| 168 | 210 | EXT4_ATTR_FUNC(lifetime_write_kbytes, 0444); |
|---|
| 169 | 211 | EXT4_ATTR_FUNC(reserved_clusters, 0644); |
|---|
| 212 | +EXT4_ATTR_FUNC(sra_exceeded_retry_limit, 0444); |
|---|
| 170 | 213 | |
|---|
| 171 | 214 | EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, inode_readahead, |
|---|
| 172 | 215 | ext4_sb_info, s_inode_readahead_blks); |
|---|
| .. | .. |
|---|
| 177 | 220 | EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs); |
|---|
| 178 | 221 | EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request); |
|---|
| 179 | 222 | EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc); |
|---|
| 223 | +EXT4_RW_ATTR_SBI_UI(mb_max_inode_prealloc, s_mb_max_inode_prealloc); |
|---|
| 180 | 224 | EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb); |
|---|
| 181 | 225 | EXT4_ATTR(trigger_fs_error, 0200, trigger_test_error); |
|---|
| 182 | 226 | EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval); |
|---|
| .. | .. |
|---|
| 185 | 229 | EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst); |
|---|
| 186 | 230 | EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval); |
|---|
| 187 | 231 | EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst); |
|---|
| 232 | +#ifdef CONFIG_EXT4_DEBUG |
|---|
| 233 | +EXT4_RW_ATTR_SBI_UL(simulate_fail, s_simulate_fail); |
|---|
| 234 | +#endif |
|---|
| 235 | +EXT4_RO_ATTR_SBI_ATOMIC(warning_count, s_warning_count); |
|---|
| 236 | +EXT4_RO_ATTR_SBI_ATOMIC(msg_count, s_msg_count); |
|---|
| 188 | 237 | EXT4_RO_ATTR_ES_UI(errors_count, s_error_count); |
|---|
| 238 | +EXT4_RO_ATTR_ES_U8(first_error_errcode, s_first_error_errcode); |
|---|
| 239 | +EXT4_RO_ATTR_ES_U8(last_error_errcode, s_last_error_errcode); |
|---|
| 240 | +EXT4_RO_ATTR_ES_UI(first_error_ino, s_first_error_ino); |
|---|
| 241 | +EXT4_RO_ATTR_ES_UI(last_error_ino, s_last_error_ino); |
|---|
| 242 | +EXT4_RO_ATTR_ES_U64(first_error_block, s_first_error_block); |
|---|
| 243 | +EXT4_RO_ATTR_ES_U64(last_error_block, s_last_error_block); |
|---|
| 244 | +EXT4_RO_ATTR_ES_UI(first_error_line, s_first_error_line); |
|---|
| 245 | +EXT4_RO_ATTR_ES_UI(last_error_line, s_last_error_line); |
|---|
| 246 | +EXT4_RO_ATTR_ES_STRING(first_error_func, s_first_error_func, 32); |
|---|
| 247 | +EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_func, 32); |
|---|
| 189 | 248 | EXT4_ATTR(first_error_time, 0444, first_error_time); |
|---|
| 190 | 249 | EXT4_ATTR(last_error_time, 0444, last_error_time); |
|---|
| 250 | +EXT4_ATTR(journal_task, 0444, journal_task); |
|---|
| 251 | +EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch); |
|---|
| 252 | +EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit); |
|---|
| 191 | 253 | |
|---|
| 192 | 254 | static unsigned int old_bump_val = 128; |
|---|
| 193 | 255 | EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val); |
|---|
| .. | .. |
|---|
| 197 | 259 | ATTR_LIST(session_write_kbytes), |
|---|
| 198 | 260 | ATTR_LIST(lifetime_write_kbytes), |
|---|
| 199 | 261 | ATTR_LIST(reserved_clusters), |
|---|
| 262 | + ATTR_LIST(sra_exceeded_retry_limit), |
|---|
| 200 | 263 | ATTR_LIST(inode_readahead_blks), |
|---|
| 201 | 264 | ATTR_LIST(inode_goal), |
|---|
| 202 | 265 | ATTR_LIST(mb_stats), |
|---|
| .. | .. |
|---|
| 205 | 268 | ATTR_LIST(mb_order2_req), |
|---|
| 206 | 269 | ATTR_LIST(mb_stream_req), |
|---|
| 207 | 270 | ATTR_LIST(mb_group_prealloc), |
|---|
| 271 | + ATTR_LIST(mb_max_inode_prealloc), |
|---|
| 208 | 272 | ATTR_LIST(max_writeback_mb_bump), |
|---|
| 209 | 273 | ATTR_LIST(extent_max_zeroout_kb), |
|---|
| 210 | 274 | ATTR_LIST(trigger_fs_error), |
|---|
| .. | .. |
|---|
| 215 | 279 | ATTR_LIST(msg_ratelimit_interval_ms), |
|---|
| 216 | 280 | ATTR_LIST(msg_ratelimit_burst), |
|---|
| 217 | 281 | ATTR_LIST(errors_count), |
|---|
| 282 | + ATTR_LIST(warning_count), |
|---|
| 283 | + ATTR_LIST(msg_count), |
|---|
| 284 | + ATTR_LIST(first_error_ino), |
|---|
| 285 | + ATTR_LIST(last_error_ino), |
|---|
| 286 | + ATTR_LIST(first_error_block), |
|---|
| 287 | + ATTR_LIST(last_error_block), |
|---|
| 288 | + ATTR_LIST(first_error_line), |
|---|
| 289 | + ATTR_LIST(last_error_line), |
|---|
| 290 | + ATTR_LIST(first_error_func), |
|---|
| 291 | + ATTR_LIST(last_error_func), |
|---|
| 292 | + ATTR_LIST(first_error_errcode), |
|---|
| 293 | + ATTR_LIST(last_error_errcode), |
|---|
| 218 | 294 | ATTR_LIST(first_error_time), |
|---|
| 219 | 295 | ATTR_LIST(last_error_time), |
|---|
| 296 | + ATTR_LIST(journal_task), |
|---|
| 297 | +#ifdef CONFIG_EXT4_DEBUG |
|---|
| 298 | + ATTR_LIST(simulate_fail), |
|---|
| 299 | +#endif |
|---|
| 300 | + ATTR_LIST(mb_prefetch), |
|---|
| 301 | + ATTR_LIST(mb_prefetch_limit), |
|---|
| 220 | 302 | NULL, |
|---|
| 221 | 303 | }; |
|---|
| 304 | +ATTRIBUTE_GROUPS(ext4); |
|---|
| 222 | 305 | |
|---|
| 223 | 306 | /* Features this copy of ext4 supports */ |
|---|
| 224 | 307 | EXT4_ATTR_FEATURE(lazy_itable_init); |
|---|
| .. | .. |
|---|
| 235 | 318 | EXT4_ATTR_FEATURE(verity); |
|---|
| 236 | 319 | #endif |
|---|
| 237 | 320 | EXT4_ATTR_FEATURE(metadata_csum_seed); |
|---|
| 321 | +EXT4_ATTR_FEATURE(fast_commit); |
|---|
| 238 | 322 | |
|---|
| 239 | 323 | static struct attribute *ext4_feat_attrs[] = { |
|---|
| 240 | 324 | ATTR_LIST(lazy_itable_init), |
|---|
| .. | .. |
|---|
| 251 | 335 | ATTR_LIST(verity), |
|---|
| 252 | 336 | #endif |
|---|
| 253 | 337 | ATTR_LIST(metadata_csum_seed), |
|---|
| 338 | + ATTR_LIST(fast_commit), |
|---|
| 254 | 339 | NULL, |
|---|
| 255 | 340 | }; |
|---|
| 341 | +ATTRIBUTE_GROUPS(ext4_feat); |
|---|
| 256 | 342 | |
|---|
| 257 | 343 | static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi) |
|---|
| 258 | 344 | { |
|---|
| .. | .. |
|---|
| 269 | 355 | |
|---|
| 270 | 356 | static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi) |
|---|
| 271 | 357 | { |
|---|
| 272 | | - return snprintf(buf, PAGE_SIZE, "%lld", |
|---|
| 358 | + return snprintf(buf, PAGE_SIZE, "%lld\n", |
|---|
| 273 | 359 | ((time64_t)hi << 32) + le32_to_cpu(lo)); |
|---|
| 274 | 360 | } |
|---|
| 275 | 361 | |
|---|
| .. | .. |
|---|
| 297 | 383 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
|---|
| 298 | 384 | (unsigned long long) |
|---|
| 299 | 385 | atomic64_read(&sbi->s_resv_clusters)); |
|---|
| 386 | + case attr_sra_exceeded_retry_limit: |
|---|
| 387 | + return snprintf(buf, PAGE_SIZE, "%llu\n", |
|---|
| 388 | + (unsigned long long) |
|---|
| 389 | + percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit)); |
|---|
| 300 | 390 | case attr_inode_readahead: |
|---|
| 301 | 391 | case attr_pointer_ui: |
|---|
| 302 | 392 | if (!ptr) |
|---|
| .. | .. |
|---|
| 307 | 397 | else |
|---|
| 308 | 398 | return snprintf(buf, PAGE_SIZE, "%u\n", |
|---|
| 309 | 399 | *((unsigned int *) ptr)); |
|---|
| 400 | + case attr_pointer_ul: |
|---|
| 401 | + if (!ptr) |
|---|
| 402 | + return 0; |
|---|
| 403 | + return snprintf(buf, PAGE_SIZE, "%lu\n", |
|---|
| 404 | + *((unsigned long *) ptr)); |
|---|
| 405 | + case attr_pointer_u8: |
|---|
| 406 | + if (!ptr) |
|---|
| 407 | + return 0; |
|---|
| 408 | + return snprintf(buf, PAGE_SIZE, "%u\n", |
|---|
| 409 | + *((unsigned char *) ptr)); |
|---|
| 410 | + case attr_pointer_u64: |
|---|
| 411 | + if (!ptr) |
|---|
| 412 | + return 0; |
|---|
| 413 | + if (a->attr_ptr == ptr_ext4_super_block_offset) |
|---|
| 414 | + return snprintf(buf, PAGE_SIZE, "%llu\n", |
|---|
| 415 | + le64_to_cpup(ptr)); |
|---|
| 416 | + else |
|---|
| 417 | + return snprintf(buf, PAGE_SIZE, "%llu\n", |
|---|
| 418 | + *((unsigned long long *) ptr)); |
|---|
| 419 | + case attr_pointer_string: |
|---|
| 420 | + if (!ptr) |
|---|
| 421 | + return 0; |
|---|
| 422 | + return snprintf(buf, PAGE_SIZE, "%.*s\n", a->attr_size, |
|---|
| 423 | + (char *) ptr); |
|---|
| 310 | 424 | case attr_pointer_atomic: |
|---|
| 311 | 425 | if (!ptr) |
|---|
| 312 | 426 | return 0; |
|---|
| .. | .. |
|---|
| 318 | 432 | return print_tstamp(buf, sbi->s_es, s_first_error_time); |
|---|
| 319 | 433 | case attr_last_error_time: |
|---|
| 320 | 434 | return print_tstamp(buf, sbi->s_es, s_last_error_time); |
|---|
| 435 | + case attr_journal_task: |
|---|
| 436 | + return journal_task_show(sbi, buf); |
|---|
| 321 | 437 | } |
|---|
| 322 | 438 | |
|---|
| 323 | 439 | return 0; |
|---|
| .. | .. |
|---|
| 348 | 464 | else |
|---|
| 349 | 465 | *((unsigned int *) ptr) = t; |
|---|
| 350 | 466 | return len; |
|---|
| 467 | + case attr_pointer_ul: |
|---|
| 468 | + if (!ptr) |
|---|
| 469 | + return 0; |
|---|
| 470 | + ret = kstrtoul(skip_spaces(buf), 0, &t); |
|---|
| 471 | + if (ret) |
|---|
| 472 | + return ret; |
|---|
| 473 | + *((unsigned long *) ptr) = t; |
|---|
| 474 | + return len; |
|---|
| 351 | 475 | case attr_inode_readahead: |
|---|
| 352 | 476 | return inode_readahead_blks_store(sbi, buf, len); |
|---|
| 353 | 477 | case attr_trigger_test_error: |
|---|
| .. | .. |
|---|
| 363 | 487 | complete(&sbi->s_kobj_unregister); |
|---|
| 364 | 488 | } |
|---|
| 365 | 489 | |
|---|
| 490 | +static void ext4_feat_release(struct kobject *kobj) |
|---|
| 491 | +{ |
|---|
| 492 | + kfree(kobj); |
|---|
| 493 | +} |
|---|
| 494 | + |
|---|
| 366 | 495 | static const struct sysfs_ops ext4_attr_ops = { |
|---|
| 367 | 496 | .show = ext4_attr_show, |
|---|
| 368 | 497 | .store = ext4_attr_store, |
|---|
| 369 | 498 | }; |
|---|
| 370 | 499 | |
|---|
| 371 | 500 | static struct kobj_type ext4_sb_ktype = { |
|---|
| 372 | | - .default_attrs = ext4_attrs, |
|---|
| 501 | + .default_groups = ext4_groups, |
|---|
| 373 | 502 | .sysfs_ops = &ext4_attr_ops, |
|---|
| 374 | 503 | .release = ext4_sb_release, |
|---|
| 375 | 504 | }; |
|---|
| 376 | 505 | |
|---|
| 377 | 506 | static struct kobj_type ext4_feat_ktype = { |
|---|
| 378 | | - .default_attrs = ext4_feat_attrs, |
|---|
| 507 | + .default_groups = ext4_feat_groups, |
|---|
| 379 | 508 | .sysfs_ops = &ext4_attr_ops, |
|---|
| 380 | | - .release = (void (*)(struct kobject *))kfree, |
|---|
| 509 | + .release = ext4_feat_release, |
|---|
| 381 | 510 | }; |
|---|
| 382 | 511 | |
|---|
| 383 | 512 | static struct kobject *ext4_root; |
|---|
| .. | .. |
|---|
| 406 | 535 | proc_create_single_data("es_shrinker_info", S_IRUGO, |
|---|
| 407 | 536 | sbi->s_proc, ext4_seq_es_shrinker_info_show, |
|---|
| 408 | 537 | sb); |
|---|
| 538 | + proc_create_single_data("fc_info", 0444, sbi->s_proc, |
|---|
| 539 | + ext4_fc_info_show, sb); |
|---|
| 409 | 540 | proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc, |
|---|
| 410 | 541 | &ext4_mb_seq_groups_ops, sb); |
|---|
| 542 | + proc_create_single_data("mb_stats", 0444, sbi->s_proc, |
|---|
| 543 | + ext4_seq_mb_stats_show, sb); |
|---|
| 411 | 544 | } |
|---|
| 412 | 545 | return 0; |
|---|
| 413 | 546 | } |
|---|