hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/ext4/sysfs.c
....@@ -13,6 +13,7 @@
1313 #include <linux/seq_file.h>
1414 #include <linux/slab.h>
1515 #include <linux/proc_fs.h>
16
+#include <linux/part_stat.h>
1617
1718 #include "ext4.h"
1819 #include "ext4_jbd2.h"
....@@ -23,13 +24,19 @@
2324 attr_session_write_kbytes,
2425 attr_lifetime_write_kbytes,
2526 attr_reserved_clusters,
27
+ attr_sra_exceeded_retry_limit,
2628 attr_inode_readahead,
2729 attr_trigger_test_error,
2830 attr_first_error_time,
2931 attr_last_error_time,
3032 attr_feature,
3133 attr_pointer_ui,
34
+ attr_pointer_ul,
35
+ attr_pointer_u64,
36
+ attr_pointer_u8,
37
+ attr_pointer_string,
3238 attr_pointer_atomic,
39
+ attr_journal_task,
3340 } attr_id_t;
3441
3542 typedef enum {
....@@ -45,6 +52,7 @@
4552 struct attribute attr;
4653 short attr_id;
4754 short attr_ptr;
55
+ unsigned short attr_size;
4856 union {
4957 int offset;
5058 void *explicit_ptr;
....@@ -125,6 +133,14 @@
125133 return count;
126134 }
127135
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
+
128144 #define EXT4_ATTR(_name,_mode,_id) \
129145 static struct ext4_attr ext4_attr_##_name = { \
130146 .attr = {.name = __stringify(_name), .mode = _mode }, \
....@@ -145,11 +161,37 @@
145161 }, \
146162 }
147163
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
+
148175 #define EXT4_RO_ATTR_ES_UI(_name,_elname) \
149176 EXT4_ATTR_OFFSET(_name, 0444, pointer_ui, ext4_super_block, _elname)
150177
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
+
151187 #define EXT4_RW_ATTR_SBI_UI(_name,_elname) \
152188 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)
153195
154196 #define EXT4_ATTR_PTR(_name,_mode,_id,_ptr) \
155197 static struct ext4_attr ext4_attr_##_name = { \
....@@ -167,6 +209,7 @@
167209 EXT4_ATTR_FUNC(session_write_kbytes, 0444);
168210 EXT4_ATTR_FUNC(lifetime_write_kbytes, 0444);
169211 EXT4_ATTR_FUNC(reserved_clusters, 0644);
212
+EXT4_ATTR_FUNC(sra_exceeded_retry_limit, 0444);
170213
171214 EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, inode_readahead,
172215 ext4_sb_info, s_inode_readahead_blks);
....@@ -177,6 +220,7 @@
177220 EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
178221 EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
179222 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);
180224 EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);
181225 EXT4_ATTR(trigger_fs_error, 0200, trigger_test_error);
182226 EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);
....@@ -185,9 +229,27 @@
185229 EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst);
186230 EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);
187231 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);
188237 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);
189248 EXT4_ATTR(first_error_time, 0444, first_error_time);
190249 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);
191253
192254 static unsigned int old_bump_val = 128;
193255 EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);
....@@ -197,6 +259,7 @@
197259 ATTR_LIST(session_write_kbytes),
198260 ATTR_LIST(lifetime_write_kbytes),
199261 ATTR_LIST(reserved_clusters),
262
+ ATTR_LIST(sra_exceeded_retry_limit),
200263 ATTR_LIST(inode_readahead_blks),
201264 ATTR_LIST(inode_goal),
202265 ATTR_LIST(mb_stats),
....@@ -205,6 +268,7 @@
205268 ATTR_LIST(mb_order2_req),
206269 ATTR_LIST(mb_stream_req),
207270 ATTR_LIST(mb_group_prealloc),
271
+ ATTR_LIST(mb_max_inode_prealloc),
208272 ATTR_LIST(max_writeback_mb_bump),
209273 ATTR_LIST(extent_max_zeroout_kb),
210274 ATTR_LIST(trigger_fs_error),
....@@ -215,10 +279,29 @@
215279 ATTR_LIST(msg_ratelimit_interval_ms),
216280 ATTR_LIST(msg_ratelimit_burst),
217281 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),
218294 ATTR_LIST(first_error_time),
219295 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),
220302 NULL,
221303 };
304
+ATTRIBUTE_GROUPS(ext4);
222305
223306 /* Features this copy of ext4 supports */
224307 EXT4_ATTR_FEATURE(lazy_itable_init);
....@@ -235,6 +318,7 @@
235318 EXT4_ATTR_FEATURE(verity);
236319 #endif
237320 EXT4_ATTR_FEATURE(metadata_csum_seed);
321
+EXT4_ATTR_FEATURE(fast_commit);
238322
239323 static struct attribute *ext4_feat_attrs[] = {
240324 ATTR_LIST(lazy_itable_init),
....@@ -251,8 +335,10 @@
251335 ATTR_LIST(verity),
252336 #endif
253337 ATTR_LIST(metadata_csum_seed),
338
+ ATTR_LIST(fast_commit),
254339 NULL,
255340 };
341
+ATTRIBUTE_GROUPS(ext4_feat);
256342
257343 static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi)
258344 {
....@@ -269,7 +355,7 @@
269355
270356 static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi)
271357 {
272
- return snprintf(buf, PAGE_SIZE, "%lld",
358
+ return snprintf(buf, PAGE_SIZE, "%lld\n",
273359 ((time64_t)hi << 32) + le32_to_cpu(lo));
274360 }
275361
....@@ -297,6 +383,10 @@
297383 return snprintf(buf, PAGE_SIZE, "%llu\n",
298384 (unsigned long long)
299385 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));
300390 case attr_inode_readahead:
301391 case attr_pointer_ui:
302392 if (!ptr)
....@@ -307,6 +397,30 @@
307397 else
308398 return snprintf(buf, PAGE_SIZE, "%u\n",
309399 *((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);
310424 case attr_pointer_atomic:
311425 if (!ptr)
312426 return 0;
....@@ -318,6 +432,8 @@
318432 return print_tstamp(buf, sbi->s_es, s_first_error_time);
319433 case attr_last_error_time:
320434 return print_tstamp(buf, sbi->s_es, s_last_error_time);
435
+ case attr_journal_task:
436
+ return journal_task_show(sbi, buf);
321437 }
322438
323439 return 0;
....@@ -348,6 +464,14 @@
348464 else
349465 *((unsigned int *) ptr) = t;
350466 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;
351475 case attr_inode_readahead:
352476 return inode_readahead_blks_store(sbi, buf, len);
353477 case attr_trigger_test_error:
....@@ -363,21 +487,26 @@
363487 complete(&sbi->s_kobj_unregister);
364488 }
365489
490
+static void ext4_feat_release(struct kobject *kobj)
491
+{
492
+ kfree(kobj);
493
+}
494
+
366495 static const struct sysfs_ops ext4_attr_ops = {
367496 .show = ext4_attr_show,
368497 .store = ext4_attr_store,
369498 };
370499
371500 static struct kobj_type ext4_sb_ktype = {
372
- .default_attrs = ext4_attrs,
501
+ .default_groups = ext4_groups,
373502 .sysfs_ops = &ext4_attr_ops,
374503 .release = ext4_sb_release,
375504 };
376505
377506 static struct kobj_type ext4_feat_ktype = {
378
- .default_attrs = ext4_feat_attrs,
507
+ .default_groups = ext4_feat_groups,
379508 .sysfs_ops = &ext4_attr_ops,
380
- .release = (void (*)(struct kobject *))kfree,
509
+ .release = ext4_feat_release,
381510 };
382511
383512 static struct kobject *ext4_root;
....@@ -406,8 +535,12 @@
406535 proc_create_single_data("es_shrinker_info", S_IRUGO,
407536 sbi->s_proc, ext4_seq_es_shrinker_info_show,
408537 sb);
538
+ proc_create_single_data("fc_info", 0444, sbi->s_proc,
539
+ ext4_fc_info_show, sb);
409540 proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc,
410541 &ext4_mb_seq_groups_ops, sb);
542
+ proc_create_single_data("mb_stats", 0444, sbi->s_proc,
543
+ ext4_seq_mb_stats_show, sb);
411544 }
412545 return 0;
413546 }