sysfs.c (762f99f4f3cb41a775b5157dd761217beba65873) sysfs.c (5298d4bfe80f6ae6ae2777bcd1357b0022d98573)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/ext4/sysfs.c
4 *
5 * Copyright (C) 1992, 1993, 1994, 1995
6 * Remy Card (card@masi.ibp.fr)
7 * Theodore Ts'o (tytso@mit.edu)
8 *

--- 49 unchanged lines hidden (view full) ---

58 void *explicit_ptr;
59 } u;
60};
61
62static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
63{
64 struct super_block *sb = sbi->s_buddy_cache->i_sb;
65
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/ext4/sysfs.c
4 *
5 * Copyright (C) 1992, 1993, 1994, 1995
6 * Remy Card (card@masi.ibp.fr)
7 * Theodore Ts'o (tytso@mit.edu)
8 *

--- 49 unchanged lines hidden (view full) ---

58 void *explicit_ptr;
59 } u;
60};
61
62static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
63{
64 struct super_block *sb = sbi->s_buddy_cache->i_sb;
65
66 return snprintf(buf, PAGE_SIZE, "%lu\n",
66 return sysfs_emit(buf, "%lu\n",
67 (part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
68 sbi->s_sectors_written_start) >> 1);
69}
70
71static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
72{
73 struct super_block *sb = sbi->s_buddy_cache->i_sb;
74
67 (part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
68 sbi->s_sectors_written_start) >> 1);
69}
70
71static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
72{
73 struct super_block *sb = sbi->s_buddy_cache->i_sb;
74
75 return snprintf(buf, PAGE_SIZE, "%llu\n",
75 return sysfs_emit(buf, "%llu\n",
76 (unsigned long long)(sbi->s_kbytes_written +
77 ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
78 EXT4_SB(sb)->s_sectors_written_start) >> 1)));
79}
80
81static ssize_t inode_readahead_blks_store(struct ext4_sb_info *sbi,
82 const char *buf, size_t count)
83{

--- 41 unchanged lines hidden (view full) ---

125 if (len)
126 ext4_error(sbi->s_sb, "%.*s", len, buf);
127 return count;
128}
129
130static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf)
131{
132 if (!sbi->s_journal)
76 (unsigned long long)(sbi->s_kbytes_written +
77 ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
78 EXT4_SB(sb)->s_sectors_written_start) >> 1)));
79}
80
81static ssize_t inode_readahead_blks_store(struct ext4_sb_info *sbi,
82 const char *buf, size_t count)
83{

--- 41 unchanged lines hidden (view full) ---

125 if (len)
126 ext4_error(sbi->s_sb, "%.*s", len, buf);
127 return count;
128}
129
130static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf)
131{
132 if (!sbi->s_journal)
133 return snprintf(buf, PAGE_SIZE, "<none>\n");
134 return snprintf(buf, PAGE_SIZE, "%d\n",
133 return sysfs_emit(buf, "<none>\n");
134 return sysfs_emit(buf, "%d\n",
135 task_pid_vnr(sbi->s_journal->j_task));
136}
137
138#define EXT4_ATTR(_name,_mode,_id) \
139static struct ext4_attr ext4_attr_##_name = { \
140 .attr = {.name = __stringify(_name), .mode = _mode }, \
141 .attr_id = attr_##_id, \
142}

--- 97 unchanged lines hidden (view full) ---

240EXT4_RO_ATTR_ES_UI(last_error_line, s_last_error_line);
241EXT4_RO_ATTR_ES_STRING(first_error_func, s_first_error_func, 32);
242EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_func, 32);
243EXT4_ATTR(first_error_time, 0444, first_error_time);
244EXT4_ATTR(last_error_time, 0444, last_error_time);
245EXT4_ATTR(journal_task, 0444, journal_task);
246EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch);
247EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);
135 task_pid_vnr(sbi->s_journal->j_task));
136}
137
138#define EXT4_ATTR(_name,_mode,_id) \
139static struct ext4_attr ext4_attr_##_name = { \
140 .attr = {.name = __stringify(_name), .mode = _mode }, \
141 .attr_id = attr_##_id, \
142}

--- 97 unchanged lines hidden (view full) ---

240EXT4_RO_ATTR_ES_UI(last_error_line, s_last_error_line);
241EXT4_RO_ATTR_ES_STRING(first_error_func, s_first_error_func, 32);
242EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_func, 32);
243EXT4_ATTR(first_error_time, 0444, first_error_time);
244EXT4_ATTR(last_error_time, 0444, last_error_time);
245EXT4_ATTR(journal_task, 0444, journal_task);
246EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch);
247EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);
248EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks);
248
249static unsigned int old_bump_val = 128;
250EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);
251
252static struct attribute *ext4_attrs[] = {
253 ATTR_LIST(delayed_allocation_blocks),
254 ATTR_LIST(session_write_kbytes),
255 ATTR_LIST(lifetime_write_kbytes),

--- 34 unchanged lines hidden (view full) ---

290 ATTR_LIST(first_error_time),
291 ATTR_LIST(last_error_time),
292 ATTR_LIST(journal_task),
293#ifdef CONFIG_EXT4_DEBUG
294 ATTR_LIST(simulate_fail),
295#endif
296 ATTR_LIST(mb_prefetch),
297 ATTR_LIST(mb_prefetch_limit),
249
250static unsigned int old_bump_val = 128;
251EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);
252
253static struct attribute *ext4_attrs[] = {
254 ATTR_LIST(delayed_allocation_blocks),
255 ATTR_LIST(session_write_kbytes),
256 ATTR_LIST(lifetime_write_kbytes),

--- 34 unchanged lines hidden (view full) ---

291 ATTR_LIST(first_error_time),
292 ATTR_LIST(last_error_time),
293 ATTR_LIST(journal_task),
294#ifdef CONFIG_EXT4_DEBUG
295 ATTR_LIST(simulate_fail),
296#endif
297 ATTR_LIST(mb_prefetch),
298 ATTR_LIST(mb_prefetch_limit),
299 ATTR_LIST(last_trim_minblks),
298 NULL,
299};
300ATTRIBUTE_GROUPS(ext4);
301
302/* Features this copy of ext4 supports */
303EXT4_ATTR_FEATURE(lazy_itable_init);
304EXT4_ATTR_FEATURE(batched_discard);
305EXT4_ATTR_FEATURE(meta_bg_resize);
306#ifdef CONFIG_FS_ENCRYPTION
307EXT4_ATTR_FEATURE(encryption);
308EXT4_ATTR_FEATURE(test_dummy_encryption_v2);
309#endif
300 NULL,
301};
302ATTRIBUTE_GROUPS(ext4);
303
304/* Features this copy of ext4 supports */
305EXT4_ATTR_FEATURE(lazy_itable_init);
306EXT4_ATTR_FEATURE(batched_discard);
307EXT4_ATTR_FEATURE(meta_bg_resize);
308#ifdef CONFIG_FS_ENCRYPTION
309EXT4_ATTR_FEATURE(encryption);
310EXT4_ATTR_FEATURE(test_dummy_encryption_v2);
311#endif
310#ifdef CONFIG_UNICODE
312#if IS_ENABLED(CONFIG_UNICODE)
311EXT4_ATTR_FEATURE(casefold);
312#endif
313#ifdef CONFIG_FS_VERITY
314EXT4_ATTR_FEATURE(verity);
315#endif
316EXT4_ATTR_FEATURE(metadata_csum_seed);
317EXT4_ATTR_FEATURE(fast_commit);
313EXT4_ATTR_FEATURE(casefold);
314#endif
315#ifdef CONFIG_FS_VERITY
316EXT4_ATTR_FEATURE(verity);
317#endif
318EXT4_ATTR_FEATURE(metadata_csum_seed);
319EXT4_ATTR_FEATURE(fast_commit);
318#if defined(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION)
320#if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION)
319EXT4_ATTR_FEATURE(encrypted_casefold);
320#endif
321
322static struct attribute *ext4_feat_attrs[] = {
323 ATTR_LIST(lazy_itable_init),
324 ATTR_LIST(batched_discard),
325 ATTR_LIST(meta_bg_resize),
326#ifdef CONFIG_FS_ENCRYPTION
327 ATTR_LIST(encryption),
328 ATTR_LIST(test_dummy_encryption_v2),
329#endif
321EXT4_ATTR_FEATURE(encrypted_casefold);
322#endif
323
324static struct attribute *ext4_feat_attrs[] = {
325 ATTR_LIST(lazy_itable_init),
326 ATTR_LIST(batched_discard),
327 ATTR_LIST(meta_bg_resize),
328#ifdef CONFIG_FS_ENCRYPTION
329 ATTR_LIST(encryption),
330 ATTR_LIST(test_dummy_encryption_v2),
331#endif
330#ifdef CONFIG_UNICODE
332#if IS_ENABLED(CONFIG_UNICODE)
331 ATTR_LIST(casefold),
332#endif
333#ifdef CONFIG_FS_VERITY
334 ATTR_LIST(verity),
335#endif
336 ATTR_LIST(metadata_csum_seed),
337 ATTR_LIST(fast_commit),
333 ATTR_LIST(casefold),
334#endif
335#ifdef CONFIG_FS_VERITY
336 ATTR_LIST(verity),
337#endif
338 ATTR_LIST(metadata_csum_seed),
339 ATTR_LIST(fast_commit),
338#if defined(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION)
340#if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION)
339 ATTR_LIST(encrypted_casefold),
340#endif
341 NULL,
342};
343ATTRIBUTE_GROUPS(ext4_feat);
344
345static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi)
346{

--- 5 unchanged lines hidden (view full) ---

352 case ptr_ext4_super_block_offset:
353 return (void *) (((char *) sbi->s_es) + a->u.offset);
354 }
355 return NULL;
356}
357
358static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi)
359{
341 ATTR_LIST(encrypted_casefold),
342#endif
343 NULL,
344};
345ATTRIBUTE_GROUPS(ext4_feat);
346
347static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi)
348{

--- 5 unchanged lines hidden (view full) ---

354 case ptr_ext4_super_block_offset:
355 return (void *) (((char *) sbi->s_es) + a->u.offset);
356 }
357 return NULL;
358}
359
360static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi)
361{
360 return snprintf(buf, PAGE_SIZE, "%lld\n",
362 return sysfs_emit(buf, "%lld\n",
361 ((time64_t)hi << 32) + le32_to_cpu(lo));
362}
363
364#define print_tstamp(buf, es, tstamp) \
365 __print_tstamp(buf, (es)->tstamp, (es)->tstamp ## _hi)
366
367static ssize_t ext4_attr_show(struct kobject *kobj,
368 struct attribute *attr, char *buf)
369{
370 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
371 s_kobj);
372 struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
373 void *ptr = calc_ptr(a, sbi);
374
375 switch (a->attr_id) {
376 case attr_delayed_allocation_blocks:
363 ((time64_t)hi << 32) + le32_to_cpu(lo));
364}
365
366#define print_tstamp(buf, es, tstamp) \
367 __print_tstamp(buf, (es)->tstamp, (es)->tstamp ## _hi)
368
369static ssize_t ext4_attr_show(struct kobject *kobj,
370 struct attribute *attr, char *buf)
371{
372 struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
373 s_kobj);
374 struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
375 void *ptr = calc_ptr(a, sbi);
376
377 switch (a->attr_id) {
378 case attr_delayed_allocation_blocks:
377 return snprintf(buf, PAGE_SIZE, "%llu\n",
379 return sysfs_emit(buf, "%llu\n",
378 (s64) EXT4_C2B(sbi,
379 percpu_counter_sum(&sbi->s_dirtyclusters_counter)));
380 case attr_session_write_kbytes:
381 return session_write_kbytes_show(sbi, buf);
382 case attr_lifetime_write_kbytes:
383 return lifetime_write_kbytes_show(sbi, buf);
384 case attr_reserved_clusters:
380 (s64) EXT4_C2B(sbi,
381 percpu_counter_sum(&sbi->s_dirtyclusters_counter)));
382 case attr_session_write_kbytes:
383 return session_write_kbytes_show(sbi, buf);
384 case attr_lifetime_write_kbytes:
385 return lifetime_write_kbytes_show(sbi, buf);
386 case attr_reserved_clusters:
385 return snprintf(buf, PAGE_SIZE, "%llu\n",
387 return sysfs_emit(buf, "%llu\n",
386 (unsigned long long)
387 atomic64_read(&sbi->s_resv_clusters));
388 case attr_sra_exceeded_retry_limit:
388 (unsigned long long)
389 atomic64_read(&sbi->s_resv_clusters));
390 case attr_sra_exceeded_retry_limit:
389 return snprintf(buf, PAGE_SIZE, "%llu\n",
391 return sysfs_emit(buf, "%llu\n",
390 (unsigned long long)
391 percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit));
392 case attr_inode_readahead:
393 case attr_pointer_ui:
394 if (!ptr)
395 return 0;
396 if (a->attr_ptr == ptr_ext4_super_block_offset)
392 (unsigned long long)
393 percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit));
394 case attr_inode_readahead:
395 case attr_pointer_ui:
396 if (!ptr)
397 return 0;
398 if (a->attr_ptr == ptr_ext4_super_block_offset)
397 return snprintf(buf, PAGE_SIZE, "%u\n",
399 return sysfs_emit(buf, "%u\n",
398 le32_to_cpup(ptr));
399 else
400 le32_to_cpup(ptr));
401 else
400 return snprintf(buf, PAGE_SIZE, "%u\n",
402 return sysfs_emit(buf, "%u\n",
401 *((unsigned int *) ptr));
402 case attr_pointer_ul:
403 if (!ptr)
404 return 0;
403 *((unsigned int *) ptr));
404 case attr_pointer_ul:
405 if (!ptr)
406 return 0;
405 return snprintf(buf, PAGE_SIZE, "%lu\n",
407 return sysfs_emit(buf, "%lu\n",
406 *((unsigned long *) ptr));
407 case attr_pointer_u8:
408 if (!ptr)
409 return 0;
408 *((unsigned long *) ptr));
409 case attr_pointer_u8:
410 if (!ptr)
411 return 0;
410 return snprintf(buf, PAGE_SIZE, "%u\n",
412 return sysfs_emit(buf, "%u\n",
411 *((unsigned char *) ptr));
412 case attr_pointer_u64:
413 if (!ptr)
414 return 0;
415 if (a->attr_ptr == ptr_ext4_super_block_offset)
413 *((unsigned char *) ptr));
414 case attr_pointer_u64:
415 if (!ptr)
416 return 0;
417 if (a->attr_ptr == ptr_ext4_super_block_offset)
416 return snprintf(buf, PAGE_SIZE, "%llu\n",
418 return sysfs_emit(buf, "%llu\n",
417 le64_to_cpup(ptr));
418 else
419 le64_to_cpup(ptr));
420 else
419 return snprintf(buf, PAGE_SIZE, "%llu\n",
421 return sysfs_emit(buf, "%llu\n",
420 *((unsigned long long *) ptr));
421 case attr_pointer_string:
422 if (!ptr)
423 return 0;
422 *((unsigned long long *) ptr));
423 case attr_pointer_string:
424 if (!ptr)
425 return 0;
424 return snprintf(buf, PAGE_SIZE, "%.*s\n", a->attr_size,
426 return sysfs_emit(buf, "%.*s\n", a->attr_size,
425 (char *) ptr);
426 case attr_pointer_atomic:
427 if (!ptr)
428 return 0;
427 (char *) ptr);
428 case attr_pointer_atomic:
429 if (!ptr)
430 return 0;
429 return snprintf(buf, PAGE_SIZE, "%d\n",
431 return sysfs_emit(buf, "%d\n",
430 atomic_read((atomic_t *) ptr));
431 case attr_feature:
432 atomic_read((atomic_t *) ptr));
433 case attr_feature:
432 return snprintf(buf, PAGE_SIZE, "supported\n");
434 return sysfs_emit(buf, "supported\n");
433 case attr_first_error_time:
434 return print_tstamp(buf, sbi->s_es, s_first_error_time);
435 case attr_last_error_time:
436 return print_tstamp(buf, sbi->s_es, s_last_error_time);
437 case attr_journal_task:
438 return journal_task_show(sbi, buf);
439 }
440

--- 161 unchanged lines hidden ---
435 case attr_first_error_time:
436 return print_tstamp(buf, sbi->s_es, s_first_error_time);
437 case attr_last_error_time:
438 return print_tstamp(buf, sbi->s_es, s_last_error_time);
439 case attr_journal_task:
440 return journal_task_show(sbi, buf);
441 }
442

--- 161 unchanged lines hidden ---