FILE
sysfs.c
File preview with syntax highlighting.
linux-6.19.14/fs/f2fs/sysfs.c
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * f2fs sysfs interface 4 * 5 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 6 * http://www.samsung.com/ 7 * Copyright (c) 2017 Chao Yu <chao@kernel.org> 8 */ 9#include <linux/compiler.h> 10#include <linux/proc_fs.h> 11#include <linux/f2fs_fs.h> 12#include <linux/seq_file.h> 13#include <linux/unicode.h> 14#include <linux/ioprio.h> 15#include <linux/sysfs.h> 16 17#include "f2fs.h" 18#include "segment.h" 19#include "gc.h" 20#include "iostat.h" 21#include <trace/events/f2fs.h> 22 23static struct proc_dir_entry *f2fs_proc_root; 24 25/* Sysfs support for f2fs */ 26enum { 27 GC_THREAD, /* struct f2fs_gc_thread */ 28 SM_INFO, /* struct f2fs_sm_info */ 29 DCC_INFO, /* struct discard_cmd_control */ 30 NM_INFO, /* struct f2fs_nm_info */ 31 F2FS_SBI, /* struct f2fs_sb_info */ 32#ifdef CONFIG_F2FS_STAT_FS 33 STAT_INFO, /* struct f2fs_stat_info */ 34#endif 35#ifdef CONFIG_F2FS_FAULT_INJECTION 36 FAULT_INFO_RATE, /* struct f2fs_fault_info */ 37 FAULT_INFO_TYPE, /* struct f2fs_fault_info */ 38#endif 39 RESERVED_BLOCKS, /* struct f2fs_sb_info */ 40 CPRC_INFO, /* struct ckpt_req_control */ 41 ATGC_INFO, /* struct atgc_management */ 42}; 43 44static const char *gc_mode_names[MAX_GC_MODE] = { 45 "GC_NORMAL", 46 "GC_IDLE_CB", 47 "GC_IDLE_GREEDY", 48 "GC_IDLE_AT", 49 "GC_URGENT_HIGH", 50 "GC_URGENT_LOW", 51 "GC_URGENT_MID" 52}; 53 54struct f2fs_attr { 55 struct attribute attr; 56 ssize_t (*show)(struct f2fs_attr *a, struct f2fs_sb_info *sbi, char *buf); 57 ssize_t (*store)(struct f2fs_attr *a, struct f2fs_sb_info *sbi, 58 const char *buf, size_t len); 59 int struct_type; 60 int offset; 61 int size; 62 int id; 63}; 64 65struct f2fs_base_attr { 66 struct attribute attr; 67 ssize_t (*show)(struct f2fs_base_attr *a, char *buf); 68 ssize_t (*store)(struct f2fs_base_attr *a, const char *buf, size_t len); 69}; 70 71static ssize_t f2fs_sbi_show(struct f2fs_attr *a, 72 struct f2fs_sb_info *sbi, char *buf); 73 74static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type) 75{ 76 if (struct_type == GC_THREAD) 77 return (unsigned char *)sbi->gc_thread; 78 else if (struct_type == SM_INFO) 79 return (unsigned char *)SM_I(sbi); 80 else if (struct_type == DCC_INFO) 81 return (unsigned char *)SM_I(sbi)->dcc_info; 82 else if (struct_type == NM_INFO) 83 return (unsigned char *)NM_I(sbi); 84 else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS) 85 return (unsigned char *)sbi; 86#ifdef CONFIG_F2FS_FAULT_INJECTION 87 else if (struct_type == FAULT_INFO_RATE || 88 struct_type == FAULT_INFO_TYPE) 89 return (unsigned char *)&F2FS_OPTION(sbi).fault_info; 90#endif 91#ifdef CONFIG_F2FS_STAT_FS 92 else if (struct_type == STAT_INFO) 93 return (unsigned char *)F2FS_STAT(sbi); 94#endif 95 else if (struct_type == CPRC_INFO) 96 return (unsigned char *)&sbi->cprc_info; 97 else if (struct_type == ATGC_INFO) 98 return (unsigned char *)&sbi->am; 99 return NULL; 100} 101 102static ssize_t dirty_segments_show(struct f2fs_attr *a, 103 struct f2fs_sb_info *sbi, char *buf) 104{ 105 return sysfs_emit(buf, "%llu\n", 106 (unsigned long long)(dirty_segments(sbi))); 107} 108 109static ssize_t free_segments_show(struct f2fs_attr *a, 110 struct f2fs_sb_info *sbi, char *buf) 111{ 112 return sysfs_emit(buf, "%llu\n", 113 (unsigned long long)(free_segments(sbi))); 114} 115 116static ssize_t ovp_segments_show(struct f2fs_attr *a, 117 struct f2fs_sb_info *sbi, char *buf) 118{ 119 return sysfs_emit(buf, "%llu\n", 120 (unsigned long long)(overprovision_segments(sbi))); 121} 122 123static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a, 124 struct f2fs_sb_info *sbi, char *buf) 125{ 126 return sysfs_emit(buf, "%llu\n", 127 (unsigned long long)(sbi->kbytes_written + 128 ((f2fs_get_sectors_written(sbi) - 129 sbi->sectors_written_start) >> 1))); 130} 131 132static ssize_t sb_status_show(struct f2fs_attr *a, 133 struct f2fs_sb_info *sbi, char *buf) 134{ 135 return sysfs_emit(buf, "%lx\n", sbi->s_flag); 136} 137 138static ssize_t cp_status_show(struct f2fs_attr *a, 139 struct f2fs_sb_info *sbi, char *buf) 140{ 141 return sysfs_emit(buf, "%x\n", le32_to_cpu(F2FS_CKPT(sbi)->ckpt_flags)); 142} 143 144static ssize_t pending_discard_show(struct f2fs_attr *a, 145 struct f2fs_sb_info *sbi, char *buf) 146{ 147 if (!SM_I(sbi)->dcc_info) 148 return -EINVAL; 149 return sysfs_emit(buf, "%llu\n", (unsigned long long)atomic_read( 150 &SM_I(sbi)->dcc_info->discard_cmd_cnt)); 151} 152 153static ssize_t issued_discard_show(struct f2fs_attr *a, 154 struct f2fs_sb_info *sbi, char *buf) 155{ 156 if (!SM_I(sbi)->dcc_info) 157 return -EINVAL; 158 return sysfs_emit(buf, "%llu\n", (unsigned long long)atomic_read( 159 &SM_I(sbi)->dcc_info->issued_discard)); 160} 161 162static ssize_t queued_discard_show(struct f2fs_attr *a, 163 struct f2fs_sb_info *sbi, char *buf) 164{ 165 if (!SM_I(sbi)->dcc_info) 166 return -EINVAL; 167 return sysfs_emit(buf, "%llu\n", (unsigned long long)atomic_read( 168 &SM_I(sbi)->dcc_info->queued_discard)); 169} 170 171static ssize_t undiscard_blks_show(struct f2fs_attr *a, 172 struct f2fs_sb_info *sbi, char *buf) 173{ 174 if (!SM_I(sbi)->dcc_info) 175 return -EINVAL; 176 return sysfs_emit(buf, "%u\n", 177 SM_I(sbi)->dcc_info->undiscard_blks); 178} 179 180static ssize_t atgc_enabled_show(struct f2fs_attr *a, 181 struct f2fs_sb_info *sbi, char *buf) 182{ 183 return sysfs_emit(buf, "%d\n", sbi->am.atgc_enabled ? 1 : 0); 184} 185 186static ssize_t gc_mode_show(struct f2fs_attr *a, 187 struct f2fs_sb_info *sbi, char *buf) 188{ 189 return sysfs_emit(buf, "%s\n", gc_mode_names[sbi->gc_mode]); 190} 191 192static ssize_t features_show(struct f2fs_attr *a, 193 struct f2fs_sb_info *sbi, char *buf) 194{ 195 int len = 0; 196 197 if (f2fs_sb_has_encrypt(sbi)) 198 len += sysfs_emit_at(buf, len, "%s", 199 "encryption"); 200 if (f2fs_sb_has_blkzoned(sbi)) 201 len += sysfs_emit_at(buf, len, "%s%s", 202 len ? ", " : "", "blkzoned"); 203 if (f2fs_sb_has_extra_attr(sbi)) 204 len += sysfs_emit_at(buf, len, "%s%s", 205 len ? ", " : "", "extra_attr"); 206 if (f2fs_sb_has_project_quota(sbi)) 207 len += sysfs_emit_at(buf, len, "%s%s", 208 len ? ", " : "", "projquota"); 209 if (f2fs_sb_has_inode_chksum(sbi)) 210 len += sysfs_emit_at(buf, len, "%s%s", 211 len ? ", " : "", "inode_checksum"); 212 if (f2fs_sb_has_flexible_inline_xattr(sbi)) 213 len += sysfs_emit_at(buf, len, "%s%s", 214 len ? ", " : "", "flexible_inline_xattr"); 215 if (f2fs_sb_has_quota_ino(sbi)) 216 len += sysfs_emit_at(buf, len, "%s%s", 217 len ? ", " : "", "quota_ino"); 218 if (f2fs_sb_has_inode_crtime(sbi)) 219 len += sysfs_emit_at(buf, len, "%s%s", 220 len ? ", " : "", "inode_crtime"); 221 if (f2fs_sb_has_lost_found(sbi)) 222 len += sysfs_emit_at(buf, len, "%s%s", 223 len ? ", " : "", "lost_found"); 224 if (f2fs_sb_has_verity(sbi)) 225 len += sysfs_emit_at(buf, len, "%s%s", 226 len ? ", " : "", "verity"); 227 if (f2fs_sb_has_sb_chksum(sbi)) 228 len += sysfs_emit_at(buf, len, "%s%s", 229 len ? ", " : "", "sb_checksum"); 230 if (f2fs_sb_has_casefold(sbi)) 231 len += sysfs_emit_at(buf, len, "%s%s", 232 len ? ", " : "", "casefold"); 233 if (f2fs_sb_has_readonly(sbi)) 234 len += sysfs_emit_at(buf, len, "%s%s", 235 len ? ", " : "", "readonly"); 236 if (f2fs_sb_has_compression(sbi)) 237 len += sysfs_emit_at(buf, len, "%s%s", 238 len ? ", " : "", "compression"); 239 if (f2fs_sb_has_packed_ssa(sbi)) 240 len += sysfs_emit_at(buf, len, "%s%s", 241 len ? ", " : "", "packed_ssa"); 242 len += sysfs_emit_at(buf, len, "%s%s", 243 len ? ", " : "", "pin_file"); 244 len += sysfs_emit_at(buf, len, "\n"); 245 return len; 246} 247 248static ssize_t current_reserved_blocks_show(struct f2fs_attr *a, 249 struct f2fs_sb_info *sbi, char *buf) 250{ 251 return sysfs_emit(buf, "%u\n", sbi->current_reserved_blocks); 252} 253 254static ssize_t unusable_show(struct f2fs_attr *a, 255 struct f2fs_sb_info *sbi, char *buf) 256{ 257 block_t unusable; 258 259 if (test_opt(sbi, DISABLE_CHECKPOINT)) 260 unusable = sbi->unusable_block_count; 261 else 262 unusable = f2fs_get_unusable_blocks(sbi); 263 return sysfs_emit(buf, "%llu\n", (unsigned long long)unusable); 264} 265 266static ssize_t encoding_show(struct f2fs_attr *a, 267 struct f2fs_sb_info *sbi, char *buf) 268{ 269#if IS_ENABLED(CONFIG_UNICODE) 270 struct super_block *sb = sbi->sb; 271 272 if (f2fs_sb_has_casefold(sbi)) 273 return sysfs_emit(buf, "UTF-8 (%d.%d.%d)\n", 274 (sb->s_encoding->version >> 16) & 0xff, 275 (sb->s_encoding->version >> 8) & 0xff, 276 sb->s_encoding->version & 0xff); 277#endif 278 return sysfs_emit(buf, "(none)\n"); 279} 280 281static ssize_t encoding_flags_show(struct f2fs_attr *a, 282 struct f2fs_sb_info *sbi, char *buf) 283{ 284 return sysfs_emit(buf, "%x\n", 285 le16_to_cpu(F2FS_RAW_SUPER(sbi)->s_encoding_flags)); 286} 287 288static ssize_t effective_lookup_mode_show(struct f2fs_attr *a, 289 struct f2fs_sb_info *sbi, char *buf) 290{ 291 switch (F2FS_OPTION(sbi).lookup_mode) { 292 case LOOKUP_PERF: 293 return sysfs_emit(buf, "perf\n"); 294 case LOOKUP_COMPAT: 295 return sysfs_emit(buf, "compat\n"); 296 case LOOKUP_AUTO: 297 if (sb_no_casefold_compat_fallback(sbi->sb)) 298 return sysfs_emit(buf, "auto:perf\n"); 299 return sysfs_emit(buf, "auto:compat\n"); 300 } 301 return 0; 302} 303 304static ssize_t mounted_time_sec_show(struct f2fs_attr *a, 305 struct f2fs_sb_info *sbi, char *buf) 306{ 307 return sysfs_emit(buf, "%llu\n", SIT_I(sbi)->mounted_time); 308} 309 310#ifdef CONFIG_F2FS_STAT_FS 311static ssize_t moved_blocks_foreground_show(struct f2fs_attr *a, 312 struct f2fs_sb_info *sbi, char *buf) 313{ 314 struct f2fs_stat_info *si = F2FS_STAT(sbi); 315 316 return sysfs_emit(buf, "%llu\n", 317 (unsigned long long)(si->tot_blks - 318 (si->bg_data_blks + si->bg_node_blks))); 319} 320 321static ssize_t moved_blocks_background_show(struct f2fs_attr *a, 322 struct f2fs_sb_info *sbi, char *buf) 323{ 324 struct f2fs_stat_info *si = F2FS_STAT(sbi); 325 326 return sysfs_emit(buf, "%llu\n", 327 (unsigned long long)(si->bg_data_blks + si->bg_node_blks)); 328} 329 330static ssize_t avg_vblocks_show(struct f2fs_attr *a, 331 struct f2fs_sb_info *sbi, char *buf) 332{ 333 struct f2fs_stat_info *si = F2FS_STAT(sbi); 334 335 si->dirty_count = dirty_segments(sbi); 336 f2fs_update_sit_info(sbi); 337 return sysfs_emit(buf, "%llu\n", (unsigned long long)(si->avg_vblocks)); 338} 339#endif 340 341static ssize_t main_blkaddr_show(struct f2fs_attr *a, 342 struct f2fs_sb_info *sbi, char *buf) 343{ 344 return sysfs_emit(buf, "%llu\n", 345 (unsigned long long)MAIN_BLKADDR(sbi)); 346} 347 348static ssize_t __sbi_show_value(struct f2fs_attr *a, 349 struct f2fs_sb_info *sbi, char *buf, 350 unsigned char *value) 351{ 352 switch (a->size) { 353 case 1: 354 return sysfs_emit(buf, "%u\n", *(u8 *)value); 355 case 2: 356 return sysfs_emit(buf, "%u\n", *(u16 *)value); 357 case 4: 358 return sysfs_emit(buf, "%u\n", *(u32 *)value); 359 case 8: 360 return sysfs_emit(buf, "%llu\n", *(u64 *)value); 361 default: 362 f2fs_bug_on(sbi, 1); 363 return sysfs_emit(buf, 364 "show sysfs node value with wrong type\n"); 365 } 366} 367 368static ssize_t f2fs_sbi_show(struct f2fs_attr *a, 369 struct f2fs_sb_info *sbi, char *buf) 370{ 371 unsigned char *ptr = NULL; 372 373 ptr = __struct_ptr(sbi, a->struct_type); 374 if (!ptr) 375 return -EINVAL; 376 377 if (!strcmp(a->attr.name, "extension_list")) { 378 __u8 (*extlist)[F2FS_EXTENSION_LEN] = 379 sbi->raw_super->extension_list; 380 int cold_count = le32_to_cpu(sbi->raw_super->extension_count); 381 int hot_count = sbi->raw_super->hot_ext_count; 382 int len = 0, i; 383 384 len += sysfs_emit_at(buf, len, "cold file extension:\n"); 385 for (i = 0; i < cold_count; i++) 386 len += sysfs_emit_at(buf, len, "%s\n", extlist[i]); 387 388 len += sysfs_emit_at(buf, len, "hot file extension:\n"); 389 for (i = cold_count; i < cold_count + hot_count; i++) 390 len += sysfs_emit_at(buf, len, "%s\n", extlist[i]); 391 392 return len; 393 } 394 395 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) { 396 struct ckpt_req_control *cprc = &sbi->cprc_info; 397 int class = IOPRIO_PRIO_CLASS(cprc->ckpt_thread_ioprio); 398 int level = IOPRIO_PRIO_LEVEL(cprc->ckpt_thread_ioprio); 399 400 if (class != IOPRIO_CLASS_RT && class != IOPRIO_CLASS_BE) 401 return -EINVAL; 402 403 return sysfs_emit(buf, "%s,%d\n", 404 class == IOPRIO_CLASS_RT ? "rt" : "be", level); 405 } 406 407#ifdef CONFIG_F2FS_FS_COMPRESSION 408 if (!strcmp(a->attr.name, "compr_written_block")) 409 return sysfs_emit(buf, "%llu\n", sbi->compr_written_block); 410 411 if (!strcmp(a->attr.name, "compr_saved_block")) 412 return sysfs_emit(buf, "%llu\n", sbi->compr_saved_block); 413 414 if (!strcmp(a->attr.name, "compr_new_inode")) 415 return sysfs_emit(buf, "%u\n", sbi->compr_new_inode); 416#endif 417 418 if (!strcmp(a->attr.name, "gc_segment_mode")) 419 return sysfs_emit(buf, "%u\n", sbi->gc_segment_mode); 420 421 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) { 422 return sysfs_emit(buf, "%u\n", 423 sbi->gc_reclaimed_segs[sbi->gc_segment_mode]); 424 } 425 426 if (!strcmp(a->attr.name, "current_atomic_write")) { 427 s64 current_write = atomic64_read(&sbi->current_atomic_write); 428 429 return sysfs_emit(buf, "%lld\n", current_write); 430 } 431 432 if (!strcmp(a->attr.name, "peak_atomic_write")) 433 return sysfs_emit(buf, "%lld\n", sbi->peak_atomic_write); 434 435 if (!strcmp(a->attr.name, "committed_atomic_block")) 436 return sysfs_emit(buf, "%llu\n", sbi->committed_atomic_block); 437 438 if (!strcmp(a->attr.name, "revoked_atomic_block")) 439 return sysfs_emit(buf, "%llu\n", sbi->revoked_atomic_block); 440 441#ifdef CONFIG_F2FS_STAT_FS 442 if (!strcmp(a->attr.name, "cp_foreground_calls")) 443 return sysfs_emit(buf, "%d\n", 444 atomic_read(&sbi->cp_call_count[TOTAL_CALL]) - 445 atomic_read(&sbi->cp_call_count[BACKGROUND])); 446 if (!strcmp(a->attr.name, "cp_background_calls")) 447 return sysfs_emit(buf, "%d\n", 448 atomic_read(&sbi->cp_call_count[BACKGROUND])); 449#endif 450 451 return __sbi_show_value(a, sbi, buf, ptr + a->offset); 452} 453 454static void __sbi_store_value(struct f2fs_attr *a, 455 struct f2fs_sb_info *sbi, 456 unsigned char *ui, unsigned long value) 457{ 458 switch (a->size) { 459 case 1: 460 *(u8 *)ui = value; 461 break; 462 case 2: 463 *(u16 *)ui = value; 464 break; 465 case 4: 466 *(u32 *)ui = value; 467 break; 468 case 8: 469 *(u64 *)ui = value; 470 break; 471 default: 472 f2fs_bug_on(sbi, 1); 473 f2fs_err(sbi, "store sysfs node value with wrong type"); 474 } 475} 476 477static ssize_t __sbi_store(struct f2fs_attr *a, 478 struct f2fs_sb_info *sbi, 479 const char *buf, size_t count) 480{ 481 unsigned char *ptr; 482 unsigned long t; 483 unsigned int *ui; 484 ssize_t ret; 485 486 ptr = __struct_ptr(sbi, a->struct_type); 487 if (!ptr) 488 return -EINVAL; 489 490 if (!strcmp(a->attr.name, "extension_list")) { 491 const char *name = strim((char *)buf); 492 bool set = true, hot; 493 494 if (!strncmp(name, "[h]", 3)) 495 hot = true; 496 else if (!strncmp(name, "[c]", 3)) 497 hot = false; 498 else 499 return -EINVAL; 500 501 name += 3; 502 503 if (*name == '!') { 504 name++; 505 set = false; 506 } 507 508 if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN) 509 return -EINVAL; 510 511 f2fs_down_write(&sbi->sb_lock); 512 513 ret = f2fs_update_extension_list(sbi, name, hot, set); 514 if (ret) 515 goto out; 516 517 ret = f2fs_commit_super(sbi, false); 518 if (ret) 519 f2fs_update_extension_list(sbi, name, hot, !set); 520out: 521 f2fs_up_write(&sbi->sb_lock); 522 return ret ? ret : count; 523 } 524 525 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) { 526 const char *name = strim((char *)buf); 527 struct ckpt_req_control *cprc = &sbi->cprc_info; 528 int class; 529 long level; 530 int ret; 531 532 if (!strncmp(name, "rt,", 3)) 533 class = IOPRIO_CLASS_RT; 534 else if (!strncmp(name, "be,", 3)) 535 class = IOPRIO_CLASS_BE; 536 else 537 return -EINVAL; 538 539 name += 3; 540 ret = kstrtol(name, 10, &level); 541 if (ret) 542 return ret; 543 if (level >= IOPRIO_NR_LEVELS || level < 0) 544 return -EINVAL; 545 546 cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, level); 547 if (test_opt(sbi, MERGE_CHECKPOINT)) { 548 ret = set_task_ioprio(cprc->f2fs_issue_ckpt, 549 cprc->ckpt_thread_ioprio); 550 if (ret) 551 return ret; 552 } 553 554 return count; 555 } 556 557 ui = (unsigned int *)(ptr + a->offset); 558 559 ret = kstrtoul(skip_spaces(buf), 0, &t); 560 if (ret < 0) 561 return ret; 562#ifdef CONFIG_F2FS_FAULT_INJECTION 563 if (a->struct_type == FAULT_INFO_TYPE) { 564 if (f2fs_build_fault_attr(sbi, 0, t, FAULT_TYPE)) 565 return -EINVAL; 566 return count; 567 } 568 if (a->struct_type == FAULT_INFO_RATE) { 569 if (f2fs_build_fault_attr(sbi, t, 0, FAULT_RATE)) 570 return -EINVAL; 571 return count; 572 } 573#endif 574 if (a->struct_type == RESERVED_BLOCKS) { 575 spin_lock(&sbi->stat_lock); 576 if (t > (unsigned long)(sbi->user_block_count - 577 F2FS_OPTION(sbi).root_reserved_blocks)) { 578 spin_unlock(&sbi->stat_lock); 579 return -EINVAL; 580 } 581 *ui = t; 582 sbi->current_reserved_blocks = min(sbi->reserved_blocks, 583 sbi->user_block_count - valid_user_blocks(sbi)); 584 spin_unlock(&sbi->stat_lock); 585 return count; 586 } 587 588 if (!strcmp(a->attr.name, "discard_io_aware_gran")) { 589 if (t > MAX_PLIST_NUM) 590 return -EINVAL; 591 if (!f2fs_block_unit_discard(sbi)) 592 return -EINVAL; 593 if (t == *ui) 594 return count; 595 *ui = t; 596 return count; 597 } 598 599 if (!strcmp(a->attr.name, "discard_granularity")) { 600 if (t == 0 || t > MAX_PLIST_NUM) 601 return -EINVAL; 602 if (!f2fs_block_unit_discard(sbi)) 603 return -EINVAL; 604 if (t == *ui) 605 return count; 606 *ui = t; 607 return count; 608 } 609 610 if (!strcmp(a->attr.name, "max_ordered_discard")) { 611 if (t == 0 || t > MAX_PLIST_NUM) 612 return -EINVAL; 613 if (!f2fs_block_unit_discard(sbi)) 614 return -EINVAL; 615 *ui = t; 616 return count; 617 } 618 619 if (!strcmp(a->attr.name, "discard_urgent_util")) { 620 if (t > 100) 621 return -EINVAL; 622 *ui = t; 623 return count; 624 } 625 626 if (!strcmp(a->attr.name, "discard_io_aware")) { 627 if (t >= DPOLICY_IO_AWARE_MAX) 628 return -EINVAL; 629 *ui = t; 630 return count; 631 } 632 633 if (!strcmp(a->attr.name, "migration_granularity")) { 634 if (t == 0 || t > SEGS_PER_SEC(sbi)) 635 return -EINVAL; 636 } 637 638 if (!strcmp(a->attr.name, "migration_window_granularity")) { 639 if (t == 0 || t > SEGS_PER_SEC(sbi)) 640 return -EINVAL; 641 } 642 643 if (!strcmp(a->attr.name, "gc_urgent")) { 644 if (t == 0) { 645 sbi->gc_mode = GC_NORMAL; 646 } else if (t == 1) { 647 sbi->gc_mode = GC_URGENT_HIGH; 648 if (sbi->gc_thread) { 649 sbi->gc_thread->gc_wake = true; 650 wake_up_interruptible_all( 651 &sbi->gc_thread->gc_wait_queue_head); 652 wake_up_discard_thread(sbi, true); 653 } 654 } else if (t == 2) { 655 sbi->gc_mode = GC_URGENT_LOW; 656 } else if (t == 3) { 657 sbi->gc_mode = GC_URGENT_MID; 658 if (sbi->gc_thread) { 659 sbi->gc_thread->gc_wake = true; 660 wake_up_interruptible_all( 661 &sbi->gc_thread->gc_wait_queue_head); 662 } 663 } else { 664 return -EINVAL; 665 } 666 return count; 667 } 668 if (!strcmp(a->attr.name, "gc_idle")) { 669 if (t == GC_IDLE_CB) { 670 sbi->gc_mode = GC_IDLE_CB; 671 } else if (t == GC_IDLE_GREEDY) { 672 sbi->gc_mode = GC_IDLE_GREEDY; 673 } else if (t == GC_IDLE_AT) { 674 if (!sbi->am.atgc_enabled) 675 return -EINVAL; 676 sbi->gc_mode = GC_IDLE_AT; 677 } else { 678 sbi->gc_mode = GC_NORMAL; 679 } 680 return count; 681 } 682 683 if (!strcmp(a->attr.name, "gc_remaining_trials")) { 684 spin_lock(&sbi->gc_remaining_trials_lock); 685 sbi->gc_remaining_trials = t; 686 spin_unlock(&sbi->gc_remaining_trials_lock); 687 688 return count; 689 } 690 691 if (!strcmp(a->attr.name, "gc_no_zoned_gc_percent")) { 692 if (t > 100) 693 return -EINVAL; 694 *ui = (unsigned int)t; 695 return count; 696 } 697 698 if (!strcmp(a->attr.name, "gc_boost_zoned_gc_percent")) { 699 if (t > 100) 700 return -EINVAL; 701 *ui = (unsigned int)t; 702 return count; 703 } 704 705 if (!strcmp(a->attr.name, "gc_valid_thresh_ratio")) { 706 if (t > 100) 707 return -EINVAL; 708 *ui = (unsigned int)t; 709 return count; 710 } 711 712#ifdef CONFIG_F2FS_IOSTAT 713 if (!strcmp(a->attr.name, "iostat_enable")) { 714 sbi->iostat_enable = !!t; 715 if (!sbi->iostat_enable) 716 f2fs_reset_iostat(sbi); 717 return count; 718 } 719 720 if (!strcmp(a->attr.name, "iostat_period_ms")) { 721 if (t < MIN_IOSTAT_PERIOD_MS || t > MAX_IOSTAT_PERIOD_MS) 722 return -EINVAL; 723 spin_lock_irq(&sbi->iostat_lock); 724 sbi->iostat_period_ms = (unsigned int)t; 725 spin_unlock_irq(&sbi->iostat_lock); 726 return count; 727 } 728#endif 729 730#ifdef CONFIG_BLK_DEV_ZONED 731 if (!strcmp(a->attr.name, "blkzone_alloc_policy")) { 732 if (t < BLKZONE_ALLOC_PRIOR_SEQ || t > BLKZONE_ALLOC_PRIOR_CONV) 733 return -EINVAL; 734 sbi->blkzone_alloc_policy = t; 735 return count; 736 } 737#endif 738 739#ifdef CONFIG_F2FS_FS_COMPRESSION 740 if (!strcmp(a->attr.name, "compr_written_block") || 741 !strcmp(a->attr.name, "compr_saved_block")) { 742 if (t != 0) 743 return -EINVAL; 744 sbi->compr_written_block = 0; 745 sbi->compr_saved_block = 0; 746 return count; 747 } 748 749 if (!strcmp(a->attr.name, "compr_new_inode")) { 750 if (t != 0) 751 return -EINVAL; 752 sbi->compr_new_inode = 0; 753 return count; 754 } 755 756 if (!strcmp(a->attr.name, "compress_percent")) { 757 if (t == 0 || t > 100) 758 return -EINVAL; 759 *ui = t; 760 return count; 761 } 762 763 if (!strcmp(a->attr.name, "compress_watermark")) { 764 if (t == 0 || t > 100) 765 return -EINVAL; 766 *ui = t; 767 return count; 768 } 769#endif 770 771 if (!strcmp(a->attr.name, "atgc_candidate_ratio")) { 772 if (t > 100) 773 return -EINVAL; 774 sbi->am.candidate_ratio = t; 775 return count; 776 } 777 778 if (!strcmp(a->attr.name, "atgc_age_weight")) { 779 if (t > 100) 780 return -EINVAL; 781 sbi->am.age_weight = t; 782 return count; 783 } 784 785 if (!strcmp(a->attr.name, "gc_segment_mode")) { 786 if (t < MAX_GC_MODE) 787 sbi->gc_segment_mode = t; 788 else 789 return -EINVAL; 790 return count; 791 } 792 793 if (!strcmp(a->attr.name, "gc_pin_file_thresh")) { 794 if (t > MAX_GC_FAILED_PINNED_FILES) 795 return -EINVAL; 796 sbi->gc_pin_file_threshold = t; 797 return count; 798 } 799 800 if (!strcmp(a->attr.name, "gc_reclaimed_segments")) { 801 if (t != 0) 802 return -EINVAL; 803 sbi->gc_reclaimed_segs[sbi->gc_segment_mode] = 0; 804 return count; 805 } 806 807 if (!strcmp(a->attr.name, "seq_file_ra_mul")) { 808 if (t >= MIN_RA_MUL && t <= MAX_RA_MUL) 809 sbi->seq_file_ra_mul = t; 810 else 811 return -EINVAL; 812 return count; 813 } 814 815 if (!strcmp(a->attr.name, "max_fragment_chunk")) { 816 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE) 817 sbi->max_fragment_chunk = t; 818 else 819 return -EINVAL; 820 return count; 821 } 822 823 if (!strcmp(a->attr.name, "max_fragment_hole")) { 824 if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE) 825 sbi->max_fragment_hole = t; 826 else 827 return -EINVAL; 828 return count; 829 } 830 831 if (!strcmp(a->attr.name, "peak_atomic_write")) { 832 if (t != 0) 833 return -EINVAL; 834 sbi->peak_atomic_write = 0; 835 return count; 836 } 837 838 if (!strcmp(a->attr.name, "committed_atomic_block")) { 839 if (t != 0) 840 return -EINVAL; 841 sbi->committed_atomic_block = 0; 842 return count; 843 } 844 845 if (!strcmp(a->attr.name, "revoked_atomic_block")) { 846 if (t != 0) 847 return -EINVAL; 848 sbi->revoked_atomic_block = 0; 849 return count; 850 } 851 852 if (!strcmp(a->attr.name, "readdir_ra")) { 853 sbi->readdir_ra = !!t; 854 return count; 855 } 856 857 if (!strcmp(a->attr.name, "hot_data_age_threshold")) { 858 if (t == 0 || t >= sbi->warm_data_age_threshold) 859 return -EINVAL; 860 if (t == *ui) 861 return count; 862 *ui = (unsigned int)t; 863 return count; 864 } 865 866 if (!strcmp(a->attr.name, "warm_data_age_threshold")) { 867 if (t <= sbi->hot_data_age_threshold) 868 return -EINVAL; 869 if (t == *ui) 870 return count; 871 *ui = (unsigned int)t; 872 return count; 873 } 874 875 if (!strcmp(a->attr.name, "last_age_weight")) { 876 if (t > 100) 877 return -EINVAL; 878 if (t == *ui) 879 return count; 880 *ui = (unsigned int)t; 881 return count; 882 } 883 884 if (!strcmp(a->attr.name, "max_read_extent_count")) { 885 if (t > UINT_MAX) 886 return -EINVAL; 887 *ui = (unsigned int)t; 888 return count; 889 } 890 891 if (!strcmp(a->attr.name, "ipu_policy")) { 892 if (t >= BIT(F2FS_IPU_MAX)) 893 return -EINVAL; 894 /* allow F2FS_IPU_NOCACHE only for IPU in the pinned file */ 895 if (f2fs_lfs_mode(sbi) && (t & ~BIT(F2FS_IPU_NOCACHE))) 896 return -EINVAL; 897 SM_I(sbi)->ipu_policy = (unsigned int)t; 898 return count; 899 } 900 901 if (!strcmp(a->attr.name, "dir_level")) { 902 if (t > MAX_DIR_HASH_DEPTH) 903 return -EINVAL; 904 sbi->dir_level = t; 905 return count; 906 } 907 908 if (!strcmp(a->attr.name, "reserved_pin_section")) { 909 if (t > GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi))) 910 return -EINVAL; 911 *ui = (unsigned int)t; 912 return count; 913 } 914 915 if (!strcmp(a->attr.name, "gc_boost_gc_multiple")) { 916 if (t < 1 || t > SEGS_PER_SEC(sbi)) 917 return -EINVAL; 918 sbi->gc_thread->boost_gc_multiple = (unsigned int)t; 919 return count; 920 } 921 922 if (!strcmp(a->attr.name, "gc_boost_gc_greedy")) { 923 if (t > GC_GREEDY) 924 return -EINVAL; 925 sbi->gc_thread->boost_gc_greedy = (unsigned int)t; 926 return count; 927 } 928 929 if (!strcmp(a->attr.name, "bggc_io_aware")) { 930 if (t < AWARE_ALL_IO || t > AWARE_NONE) 931 return -EINVAL; 932 sbi->bggc_io_aware = t; 933 return count; 934 } 935 936 if (!strcmp(a->attr.name, "allocate_section_hint")) { 937 if (t < 0 || t > MAIN_SECS(sbi)) 938 return -EINVAL; 939 sbi->allocate_section_hint = t; 940 return count; 941 } 942 943 if (!strcmp(a->attr.name, "allocate_section_policy")) { 944 if (t < ALLOCATE_FORWARD_NOHINT || t > ALLOCATE_FORWARD_FROM_HINT) 945 return -EINVAL; 946 sbi->allocate_section_policy = t; 947 return count; 948 } 949 950 __sbi_store_value(a, sbi, ptr + a->offset, t); 951 952 return count; 953} 954 955static ssize_t f2fs_sbi_store(struct f2fs_attr *a, 956 struct f2fs_sb_info *sbi, 957 const char *buf, size_t count) 958{ 959 ssize_t ret; 960 bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") || 961 a->struct_type == GC_THREAD); 962 963 if (gc_entry) { 964 if (!down_read_trylock(&sbi->sb->s_umount)) 965 return -EAGAIN; 966 } 967 ret = __sbi_store(a, sbi, buf, count); 968 if (gc_entry) 969 up_read(&sbi->sb->s_umount); 970 971 return ret; 972} 973 974static ssize_t f2fs_attr_show(struct kobject *kobj, 975 struct attribute *attr, char *buf) 976{ 977 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 978 s_kobj); 979 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); 980 981 return a->show ? a->show(a, sbi, buf) : 0; 982} 983 984static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr, 985 const char *buf, size_t len) 986{ 987 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 988 s_kobj); 989 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); 990 991 return a->store ? a->store(a, sbi, buf, len) : 0; 992} 993 994static void f2fs_sb_release(struct kobject *kobj) 995{ 996 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 997 s_kobj); 998 complete(&sbi->s_kobj_unregister); 999} 1000 1001static ssize_t f2fs_base_attr_show(struct kobject *kobj, 1002 struct attribute *attr, char *buf) 1003{ 1004 struct f2fs_base_attr *a = container_of(attr, 1005 struct f2fs_base_attr, attr); 1006 1007 return a->show ? a->show(a, buf) : 0; 1008} 1009 1010static ssize_t f2fs_base_attr_store(struct kobject *kobj, 1011 struct attribute *attr, 1012 const char *buf, size_t len) 1013{ 1014 struct f2fs_base_attr *a = container_of(attr, 1015 struct f2fs_base_attr, attr); 1016 1017 return a->store ? a->store(a, buf, len) : 0; 1018} 1019 1020/* 1021 * Note that there are three feature list entries: 1022 * 1) /sys/fs/f2fs/features 1023 * : shows runtime features supported by in-kernel f2fs along with Kconfig. 1024 * - ref. F2FS_FEATURE_RO_ATTR() 1025 * 1026 * 2) /sys/fs/f2fs/$s_id/features <deprecated> 1027 * : shows on-disk features enabled by mkfs.f2fs, used for old kernels. This 1028 * won't add new feature anymore, and thus, users should check entries in 3) 1029 * instead of this 2). 1030 * 1031 * 3) /sys/fs/f2fs/$s_id/feature_list 1032 * : shows on-disk features enabled by mkfs.f2fs per instance, which follows 1033 * sysfs entry rule where each entry should expose single value. 1034 * This list covers old feature list provided by 2) and beyond. Therefore, 1035 * please add new on-disk feature in this list only. 1036 * - ref. F2FS_SB_FEATURE_RO_ATTR() 1037 */ 1038static ssize_t f2fs_feature_show(struct f2fs_base_attr *a, char *buf) 1039{ 1040 return sysfs_emit(buf, "supported\n"); 1041} 1042 1043#define F2FS_FEATURE_RO_ATTR(_name) \ 1044static struct f2fs_base_attr f2fs_base_attr_##_name = { \ 1045 .attr = {.name = __stringify(_name), .mode = 0444 }, \ 1046 .show = f2fs_feature_show, \ 1047} 1048 1049static ssize_t f2fs_tune_show(struct f2fs_base_attr *a, char *buf) 1050{ 1051 unsigned int res = 0; 1052 1053 if (!strcmp(a->attr.name, "reclaim_caches_kb")) 1054 res = f2fs_donate_files(); 1055 1056 return sysfs_emit(buf, "%u\n", res); 1057} 1058 1059static ssize_t f2fs_tune_store(struct f2fs_base_attr *a, 1060 const char *buf, size_t count) 1061{ 1062 unsigned long t; 1063 int ret; 1064 1065 ret = kstrtoul(skip_spaces(buf), 0, &t); 1066 if (ret) 1067 return ret; 1068 1069 if (!strcmp(a->attr.name, "reclaim_caches_kb")) 1070 f2fs_reclaim_caches(t); 1071 1072 return count; 1073} 1074 1075#define F2FS_TUNE_RW_ATTR(_name) \ 1076static struct f2fs_base_attr f2fs_base_attr_##_name = { \ 1077 .attr = {.name = __stringify(_name), .mode = 0644 }, \ 1078 .show = f2fs_tune_show, \ 1079 .store = f2fs_tune_store, \ 1080} 1081 1082static ssize_t f2fs_sb_feature_show(struct f2fs_attr *a, 1083 struct f2fs_sb_info *sbi, char *buf) 1084{ 1085 if (F2FS_HAS_FEATURE(sbi, a->id)) 1086 return sysfs_emit(buf, "supported\n"); 1087 return sysfs_emit(buf, "unsupported\n"); 1088} 1089 1090#define F2FS_SB_FEATURE_RO_ATTR(_name, _feat) \ 1091static struct f2fs_attr f2fs_attr_sb_##_name = { \ 1092 .attr = {.name = __stringify(_name), .mode = 0444 }, \ 1093 .show = f2fs_sb_feature_show, \ 1094 .id = F2FS_FEATURE_##_feat, \ 1095} 1096 1097#define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset, _size) \ 1098static struct f2fs_attr f2fs_attr_##_name = { \ 1099 .attr = {.name = __stringify(_name), .mode = _mode }, \ 1100 .show = _show, \ 1101 .store = _store, \ 1102 .struct_type = _struct_type, \ 1103 .offset = _offset, \ 1104 .size = _size \ 1105} 1106 1107#define F2FS_RO_ATTR(struct_type, struct_name, name, elname) \ 1108 F2FS_ATTR_OFFSET(struct_type, name, 0444, \ 1109 f2fs_sbi_show, NULL, \ 1110 offsetof(struct struct_name, elname), \ 1111 sizeof_field(struct struct_name, elname)) 1112 1113#define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \ 1114 F2FS_ATTR_OFFSET(struct_type, name, 0644, \ 1115 f2fs_sbi_show, f2fs_sbi_store, \ 1116 offsetof(struct struct_name, elname), \ 1117 sizeof_field(struct struct_name, elname)) 1118 1119#define F2FS_GENERAL_RO_ATTR(name) \ 1120static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL) 1121 1122#ifdef CONFIG_F2FS_STAT_FS 1123#define STAT_INFO_RO_ATTR(name, elname) \ 1124 F2FS_RO_ATTR(STAT_INFO, f2fs_stat_info, name, elname) 1125#endif 1126 1127#define GC_THREAD_RW_ATTR(name, elname) \ 1128 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, name, elname) 1129 1130#define SM_INFO_RW_ATTR(name, elname) \ 1131 F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, name, elname) 1132 1133#define SM_INFO_GENERAL_RW_ATTR(elname) \ 1134 SM_INFO_RW_ATTR(elname, elname) 1135 1136#define DCC_INFO_RW_ATTR(name, elname) \ 1137 F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, name, elname) 1138 1139#define DCC_INFO_GENERAL_RW_ATTR(elname) \ 1140 DCC_INFO_RW_ATTR(elname, elname) 1141 1142#define NM_INFO_RW_ATTR(name, elname) \ 1143 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, name, elname) 1144 1145#define NM_INFO_GENERAL_RW_ATTR(elname) \ 1146 NM_INFO_RW_ATTR(elname, elname) 1147 1148#define F2FS_SBI_RW_ATTR(name, elname) \ 1149 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, name, elname) 1150 1151#define F2FS_SBI_GENERAL_RW_ATTR(elname) \ 1152 F2FS_SBI_RW_ATTR(elname, elname) 1153 1154#define F2FS_SBI_GENERAL_RO_ATTR(elname) \ 1155 F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, elname, elname) 1156 1157#ifdef CONFIG_F2FS_FAULT_INJECTION 1158#define FAULT_INFO_GENERAL_RW_ATTR(type, elname) \ 1159 F2FS_RW_ATTR(type, f2fs_fault_info, elname, elname) 1160#endif 1161 1162#define RESERVED_BLOCKS_GENERAL_RW_ATTR(elname) \ 1163 F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, elname, elname) 1164 1165#define CPRC_INFO_GENERAL_RW_ATTR(elname) \ 1166 F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, elname, elname) 1167 1168#define ATGC_INFO_RW_ATTR(name, elname) \ 1169 F2FS_RW_ATTR(ATGC_INFO, atgc_management, name, elname) 1170 1171/* GC_THREAD ATTR */ 1172GC_THREAD_RW_ATTR(gc_urgent_sleep_time, urgent_sleep_time); 1173GC_THREAD_RW_ATTR(gc_min_sleep_time, min_sleep_time); 1174GC_THREAD_RW_ATTR(gc_max_sleep_time, max_sleep_time); 1175GC_THREAD_RW_ATTR(gc_no_gc_sleep_time, no_gc_sleep_time); 1176GC_THREAD_RW_ATTR(gc_no_zoned_gc_percent, no_zoned_gc_percent); 1177GC_THREAD_RW_ATTR(gc_boost_zoned_gc_percent, boost_zoned_gc_percent); 1178GC_THREAD_RW_ATTR(gc_valid_thresh_ratio, valid_thresh_ratio); 1179GC_THREAD_RW_ATTR(gc_boost_gc_multiple, boost_gc_multiple); 1180GC_THREAD_RW_ATTR(gc_boost_gc_greedy, boost_gc_greedy); 1181 1182/* SM_INFO ATTR */ 1183SM_INFO_RW_ATTR(reclaim_segments, rec_prefree_segments); 1184SM_INFO_GENERAL_RW_ATTR(ipu_policy); 1185SM_INFO_GENERAL_RW_ATTR(min_ipu_util); 1186SM_INFO_GENERAL_RW_ATTR(min_fsync_blocks); 1187SM_INFO_GENERAL_RW_ATTR(min_seq_blocks); 1188SM_INFO_GENERAL_RW_ATTR(min_hot_blocks); 1189SM_INFO_GENERAL_RW_ATTR(min_ssr_sections); 1190SM_INFO_GENERAL_RW_ATTR(reserved_segments); 1191 1192/* DCC_INFO ATTR */ 1193DCC_INFO_RW_ATTR(max_small_discards, max_discards); 1194DCC_INFO_GENERAL_RW_ATTR(max_discard_request); 1195DCC_INFO_GENERAL_RW_ATTR(min_discard_issue_time); 1196DCC_INFO_GENERAL_RW_ATTR(mid_discard_issue_time); 1197DCC_INFO_GENERAL_RW_ATTR(max_discard_issue_time); 1198DCC_INFO_GENERAL_RW_ATTR(discard_io_aware_gran); 1199DCC_INFO_GENERAL_RW_ATTR(discard_urgent_util); 1200DCC_INFO_GENERAL_RW_ATTR(discard_granularity); 1201DCC_INFO_GENERAL_RW_ATTR(max_ordered_discard); 1202DCC_INFO_GENERAL_RW_ATTR(discard_io_aware); 1203 1204/* NM_INFO ATTR */ 1205NM_INFO_RW_ATTR(max_roll_forward_node_blocks, max_rf_node_blocks); 1206NM_INFO_GENERAL_RW_ATTR(ram_thresh); 1207NM_INFO_GENERAL_RW_ATTR(ra_nid_pages); 1208NM_INFO_GENERAL_RW_ATTR(dirty_nats_ratio); 1209 1210/* F2FS_SBI ATTR */ 1211F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list); 1212F2FS_SBI_RW_ATTR(gc_idle, gc_mode); 1213F2FS_SBI_RW_ATTR(gc_urgent, gc_mode); 1214F2FS_SBI_RW_ATTR(cp_interval, interval_time[CP_TIME]); 1215F2FS_SBI_RW_ATTR(idle_interval, interval_time[REQ_TIME]); 1216F2FS_SBI_RW_ATTR(discard_idle_interval, interval_time[DISCARD_TIME]); 1217F2FS_SBI_RW_ATTR(gc_idle_interval, interval_time[GC_TIME]); 1218F2FS_SBI_RW_ATTR(umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]); 1219F2FS_SBI_RW_ATTR(gc_pin_file_thresh, gc_pin_file_threshold); 1220F2FS_SBI_RW_ATTR(gc_reclaimed_segments, gc_reclaimed_segs); 1221F2FS_SBI_GENERAL_RW_ATTR(max_victim_search); 1222F2FS_SBI_GENERAL_RW_ATTR(migration_granularity); 1223F2FS_SBI_GENERAL_RW_ATTR(migration_window_granularity); 1224F2FS_SBI_GENERAL_RW_ATTR(dir_level); 1225F2FS_SBI_GENERAL_RW_ATTR(allocate_section_hint); 1226F2FS_SBI_GENERAL_RW_ATTR(allocate_section_policy); 1227#ifdef CONFIG_F2FS_IOSTAT 1228F2FS_SBI_GENERAL_RW_ATTR(iostat_enable); 1229F2FS_SBI_GENERAL_RW_ATTR(iostat_period_ms); 1230#endif 1231F2FS_SBI_GENERAL_RW_ATTR(readdir_ra); 1232F2FS_SBI_GENERAL_RW_ATTR(max_io_bytes); 1233F2FS_SBI_GENERAL_RW_ATTR(data_io_flag); 1234F2FS_SBI_GENERAL_RW_ATTR(node_io_flag); 1235F2FS_SBI_GENERAL_RW_ATTR(gc_remaining_trials); 1236F2FS_SBI_GENERAL_RW_ATTR(seq_file_ra_mul); 1237F2FS_SBI_GENERAL_RW_ATTR(gc_segment_mode); 1238F2FS_SBI_GENERAL_RW_ATTR(max_fragment_chunk); 1239F2FS_SBI_GENERAL_RW_ATTR(max_fragment_hole); 1240#ifdef CONFIG_F2FS_FS_COMPRESSION 1241F2FS_SBI_GENERAL_RW_ATTR(compr_written_block); 1242F2FS_SBI_GENERAL_RW_ATTR(compr_saved_block); 1243F2FS_SBI_GENERAL_RW_ATTR(compr_new_inode); 1244F2FS_SBI_GENERAL_RW_ATTR(compress_percent); 1245F2FS_SBI_GENERAL_RW_ATTR(compress_watermark); 1246#endif 1247/* atomic write */ 1248F2FS_SBI_GENERAL_RO_ATTR(current_atomic_write); 1249F2FS_SBI_GENERAL_RW_ATTR(peak_atomic_write); 1250F2FS_SBI_GENERAL_RW_ATTR(committed_atomic_block); 1251F2FS_SBI_GENERAL_RW_ATTR(revoked_atomic_block); 1252/* block age extent cache */ 1253F2FS_SBI_GENERAL_RW_ATTR(hot_data_age_threshold); 1254F2FS_SBI_GENERAL_RW_ATTR(warm_data_age_threshold); 1255F2FS_SBI_GENERAL_RW_ATTR(last_age_weight); 1256/* read extent cache */ 1257F2FS_SBI_GENERAL_RW_ATTR(max_read_extent_count); 1258#ifdef CONFIG_BLK_DEV_ZONED 1259F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec); 1260F2FS_SBI_GENERAL_RO_ATTR(max_open_zones); 1261F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy); 1262#endif 1263F2FS_SBI_GENERAL_RW_ATTR(carve_out); 1264F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section); 1265F2FS_SBI_GENERAL_RW_ATTR(bggc_io_aware); 1266 1267/* STAT_INFO ATTR */ 1268#ifdef CONFIG_F2FS_STAT_FS 1269STAT_INFO_RO_ATTR(cp_foreground_calls, cp_call_count[FOREGROUND]); 1270STAT_INFO_RO_ATTR(cp_background_calls, cp_call_count[BACKGROUND]); 1271STAT_INFO_RO_ATTR(gc_foreground_calls, gc_call_count[FOREGROUND]); 1272STAT_INFO_RO_ATTR(gc_background_calls, gc_call_count[BACKGROUND]); 1273#endif 1274 1275/* FAULT_INFO ATTR */ 1276#ifdef CONFIG_F2FS_FAULT_INJECTION 1277FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_RATE, inject_rate); 1278FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_TYPE, inject_type); 1279#endif 1280 1281/* RESERVED_BLOCKS ATTR */ 1282RESERVED_BLOCKS_GENERAL_RW_ATTR(reserved_blocks); 1283 1284/* CPRC_INFO ATTR */ 1285CPRC_INFO_GENERAL_RW_ATTR(ckpt_thread_ioprio); 1286 1287/* ATGC_INFO ATTR */ 1288ATGC_INFO_RW_ATTR(atgc_candidate_ratio, candidate_ratio); 1289ATGC_INFO_RW_ATTR(atgc_candidate_count, max_candidate_count); 1290ATGC_INFO_RW_ATTR(atgc_age_weight, age_weight); 1291ATGC_INFO_RW_ATTR(atgc_age_threshold, age_threshold); 1292 1293F2FS_GENERAL_RO_ATTR(dirty_segments); 1294F2FS_GENERAL_RO_ATTR(free_segments); 1295F2FS_GENERAL_RO_ATTR(ovp_segments); 1296F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes); 1297F2FS_GENERAL_RO_ATTR(features); 1298F2FS_GENERAL_RO_ATTR(current_reserved_blocks); 1299F2FS_GENERAL_RO_ATTR(unusable); 1300F2FS_GENERAL_RO_ATTR(encoding); 1301F2FS_GENERAL_RO_ATTR(encoding_flags); 1302F2FS_GENERAL_RO_ATTR(effective_lookup_mode); 1303F2FS_GENERAL_RO_ATTR(mounted_time_sec); 1304F2FS_GENERAL_RO_ATTR(main_blkaddr); 1305F2FS_GENERAL_RO_ATTR(pending_discard); 1306F2FS_GENERAL_RO_ATTR(atgc_enabled); 1307F2FS_GENERAL_RO_ATTR(gc_mode); 1308#ifdef CONFIG_F2FS_STAT_FS 1309F2FS_GENERAL_RO_ATTR(moved_blocks_background); 1310F2FS_GENERAL_RO_ATTR(moved_blocks_foreground); 1311F2FS_GENERAL_RO_ATTR(avg_vblocks); 1312#endif 1313 1314#ifdef CONFIG_FS_ENCRYPTION 1315F2FS_FEATURE_RO_ATTR(encryption); 1316F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2); 1317#if IS_ENABLED(CONFIG_UNICODE) 1318F2FS_FEATURE_RO_ATTR(encrypted_casefold); 1319#endif 1320#endif /* CONFIG_FS_ENCRYPTION */ 1321#ifdef CONFIG_BLK_DEV_ZONED 1322F2FS_FEATURE_RO_ATTR(block_zoned); 1323#endif 1324F2FS_FEATURE_RO_ATTR(atomic_write); 1325F2FS_FEATURE_RO_ATTR(extra_attr); 1326F2FS_FEATURE_RO_ATTR(project_quota); 1327F2FS_FEATURE_RO_ATTR(inode_checksum); 1328F2FS_FEATURE_RO_ATTR(flexible_inline_xattr); 1329F2FS_FEATURE_RO_ATTR(quota_ino); 1330F2FS_FEATURE_RO_ATTR(inode_crtime); 1331F2FS_FEATURE_RO_ATTR(lost_found); 1332#ifdef CONFIG_FS_VERITY 1333F2FS_FEATURE_RO_ATTR(verity); 1334#endif 1335F2FS_FEATURE_RO_ATTR(sb_checksum); 1336#if IS_ENABLED(CONFIG_UNICODE) 1337F2FS_FEATURE_RO_ATTR(casefold); 1338#endif 1339F2FS_FEATURE_RO_ATTR(readonly); 1340#ifdef CONFIG_F2FS_FS_COMPRESSION 1341F2FS_FEATURE_RO_ATTR(compression); 1342#endif 1343F2FS_FEATURE_RO_ATTR(pin_file); 1344#ifdef CONFIG_UNICODE 1345F2FS_FEATURE_RO_ATTR(linear_lookup); 1346#endif 1347F2FS_FEATURE_RO_ATTR(packed_ssa); 1348 1349#define ATTR_LIST(name) (&f2fs_attr_##name.attr) 1350static struct attribute *f2fs_attrs[] = { 1351 ATTR_LIST(gc_urgent_sleep_time), 1352 ATTR_LIST(gc_min_sleep_time), 1353 ATTR_LIST(gc_max_sleep_time), 1354 ATTR_LIST(gc_no_gc_sleep_time), 1355 ATTR_LIST(gc_no_zoned_gc_percent), 1356 ATTR_LIST(gc_boost_zoned_gc_percent), 1357 ATTR_LIST(gc_valid_thresh_ratio), 1358 ATTR_LIST(gc_boost_gc_multiple), 1359 ATTR_LIST(gc_boost_gc_greedy), 1360 ATTR_LIST(gc_idle), 1361 ATTR_LIST(gc_urgent), 1362 ATTR_LIST(reclaim_segments), 1363 ATTR_LIST(main_blkaddr), 1364 ATTR_LIST(max_small_discards), 1365 ATTR_LIST(max_discard_request), 1366 ATTR_LIST(min_discard_issue_time), 1367 ATTR_LIST(mid_discard_issue_time), 1368 ATTR_LIST(max_discard_issue_time), 1369 ATTR_LIST(discard_io_aware_gran), 1370 ATTR_LIST(discard_urgent_util), 1371 ATTR_LIST(discard_granularity), 1372 ATTR_LIST(max_ordered_discard), 1373 ATTR_LIST(discard_io_aware), 1374 ATTR_LIST(pending_discard), 1375 ATTR_LIST(gc_mode), 1376 ATTR_LIST(ipu_policy), 1377 ATTR_LIST(min_ipu_util), 1378 ATTR_LIST(min_fsync_blocks), 1379 ATTR_LIST(min_seq_blocks), 1380 ATTR_LIST(min_hot_blocks), 1381 ATTR_LIST(min_ssr_sections), 1382 ATTR_LIST(reserved_segments), 1383 ATTR_LIST(max_victim_search), 1384 ATTR_LIST(migration_granularity), 1385 ATTR_LIST(migration_window_granularity), 1386 ATTR_LIST(dir_level), 1387 ATTR_LIST(ram_thresh), 1388 ATTR_LIST(ra_nid_pages), 1389 ATTR_LIST(dirty_nats_ratio), 1390 ATTR_LIST(max_roll_forward_node_blocks), 1391 ATTR_LIST(cp_interval), 1392 ATTR_LIST(idle_interval), 1393 ATTR_LIST(discard_idle_interval), 1394 ATTR_LIST(gc_idle_interval), 1395 ATTR_LIST(umount_discard_timeout), 1396 ATTR_LIST(bggc_io_aware), 1397#ifdef CONFIG_F2FS_IOSTAT 1398 ATTR_LIST(iostat_enable), 1399 ATTR_LIST(iostat_period_ms), 1400#endif 1401 ATTR_LIST(readdir_ra), 1402 ATTR_LIST(max_io_bytes), 1403 ATTR_LIST(gc_pin_file_thresh), 1404 ATTR_LIST(extension_list), 1405#ifdef CONFIG_F2FS_FAULT_INJECTION 1406 ATTR_LIST(inject_rate), 1407 ATTR_LIST(inject_type), 1408#endif 1409 ATTR_LIST(data_io_flag), 1410 ATTR_LIST(node_io_flag), 1411 ATTR_LIST(gc_remaining_trials), 1412 ATTR_LIST(ckpt_thread_ioprio), 1413 ATTR_LIST(dirty_segments), 1414 ATTR_LIST(free_segments), 1415 ATTR_LIST(ovp_segments), 1416 ATTR_LIST(unusable), 1417 ATTR_LIST(lifetime_write_kbytes), 1418 ATTR_LIST(features), 1419 ATTR_LIST(reserved_blocks), 1420 ATTR_LIST(current_reserved_blocks), 1421 ATTR_LIST(encoding), 1422 ATTR_LIST(encoding_flags), 1423 ATTR_LIST(effective_lookup_mode), 1424 ATTR_LIST(mounted_time_sec), 1425#ifdef CONFIG_F2FS_STAT_FS 1426 ATTR_LIST(cp_foreground_calls), 1427 ATTR_LIST(cp_background_calls), 1428 ATTR_LIST(gc_foreground_calls), 1429 ATTR_LIST(gc_background_calls), 1430 ATTR_LIST(moved_blocks_foreground), 1431 ATTR_LIST(moved_blocks_background), 1432 ATTR_LIST(avg_vblocks), 1433#endif 1434#ifdef CONFIG_BLK_DEV_ZONED 1435 ATTR_LIST(unusable_blocks_per_sec), 1436 ATTR_LIST(max_open_zones), 1437 ATTR_LIST(blkzone_alloc_policy), 1438#endif 1439#ifdef CONFIG_F2FS_FS_COMPRESSION 1440 ATTR_LIST(compr_written_block), 1441 ATTR_LIST(compr_saved_block), 1442 ATTR_LIST(compr_new_inode), 1443 ATTR_LIST(compress_percent), 1444 ATTR_LIST(compress_watermark), 1445#endif 1446 /* For ATGC */ 1447 ATTR_LIST(atgc_candidate_ratio), 1448 ATTR_LIST(atgc_candidate_count), 1449 ATTR_LIST(atgc_age_weight), 1450 ATTR_LIST(atgc_age_threshold), 1451 ATTR_LIST(atgc_enabled), 1452 ATTR_LIST(seq_file_ra_mul), 1453 ATTR_LIST(gc_segment_mode), 1454 ATTR_LIST(gc_reclaimed_segments), 1455 ATTR_LIST(max_fragment_chunk), 1456 ATTR_LIST(max_fragment_hole), 1457 ATTR_LIST(current_atomic_write), 1458 ATTR_LIST(peak_atomic_write), 1459 ATTR_LIST(committed_atomic_block), 1460 ATTR_LIST(revoked_atomic_block), 1461 ATTR_LIST(hot_data_age_threshold), 1462 ATTR_LIST(warm_data_age_threshold), 1463 ATTR_LIST(last_age_weight), 1464 ATTR_LIST(max_read_extent_count), 1465 ATTR_LIST(carve_out), 1466 ATTR_LIST(reserved_pin_section), 1467 ATTR_LIST(allocate_section_hint), 1468 ATTR_LIST(allocate_section_policy), 1469 NULL, 1470}; 1471ATTRIBUTE_GROUPS(f2fs); 1472 1473#define BASE_ATTR_LIST(name) (&f2fs_base_attr_##name.attr) 1474static struct attribute *f2fs_feat_attrs[] = { 1475#ifdef CONFIG_FS_ENCRYPTION 1476 BASE_ATTR_LIST(encryption), 1477 BASE_ATTR_LIST(test_dummy_encryption_v2), 1478#if IS_ENABLED(CONFIG_UNICODE) 1479 BASE_ATTR_LIST(encrypted_casefold), 1480#endif 1481#endif /* CONFIG_FS_ENCRYPTION */ 1482#ifdef CONFIG_BLK_DEV_ZONED 1483 BASE_ATTR_LIST(block_zoned), 1484#endif 1485 BASE_ATTR_LIST(atomic_write), 1486 BASE_ATTR_LIST(extra_attr), 1487 BASE_ATTR_LIST(project_quota), 1488 BASE_ATTR_LIST(inode_checksum), 1489 BASE_ATTR_LIST(flexible_inline_xattr), 1490 BASE_ATTR_LIST(quota_ino), 1491 BASE_ATTR_LIST(inode_crtime), 1492 BASE_ATTR_LIST(lost_found), 1493#ifdef CONFIG_FS_VERITY 1494 BASE_ATTR_LIST(verity), 1495#endif 1496 BASE_ATTR_LIST(sb_checksum), 1497#if IS_ENABLED(CONFIG_UNICODE) 1498 BASE_ATTR_LIST(casefold), 1499#endif 1500 BASE_ATTR_LIST(readonly), 1501#ifdef CONFIG_F2FS_FS_COMPRESSION 1502 BASE_ATTR_LIST(compression), 1503#endif 1504 BASE_ATTR_LIST(pin_file), 1505#ifdef CONFIG_UNICODE 1506 BASE_ATTR_LIST(linear_lookup), 1507#endif 1508 BASE_ATTR_LIST(packed_ssa), 1509 NULL, 1510}; 1511ATTRIBUTE_GROUPS(f2fs_feat); 1512 1513F2FS_GENERAL_RO_ATTR(sb_status); 1514F2FS_GENERAL_RO_ATTR(cp_status); 1515F2FS_GENERAL_RO_ATTR(issued_discard); 1516F2FS_GENERAL_RO_ATTR(queued_discard); 1517F2FS_GENERAL_RO_ATTR(undiscard_blks); 1518 1519static struct attribute *f2fs_stat_attrs[] = { 1520 ATTR_LIST(sb_status), 1521 ATTR_LIST(cp_status), 1522 ATTR_LIST(issued_discard), 1523 ATTR_LIST(queued_discard), 1524 ATTR_LIST(undiscard_blks), 1525 NULL, 1526}; 1527ATTRIBUTE_GROUPS(f2fs_stat); 1528 1529F2FS_SB_FEATURE_RO_ATTR(encryption, ENCRYPT); 1530F2FS_SB_FEATURE_RO_ATTR(block_zoned, BLKZONED); 1531F2FS_SB_FEATURE_RO_ATTR(extra_attr, EXTRA_ATTR); 1532F2FS_SB_FEATURE_RO_ATTR(project_quota, PRJQUOTA); 1533F2FS_SB_FEATURE_RO_ATTR(inode_checksum, INODE_CHKSUM); 1534F2FS_SB_FEATURE_RO_ATTR(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); 1535F2FS_SB_FEATURE_RO_ATTR(quota_ino, QUOTA_INO); 1536F2FS_SB_FEATURE_RO_ATTR(inode_crtime, INODE_CRTIME); 1537F2FS_SB_FEATURE_RO_ATTR(lost_found, LOST_FOUND); 1538F2FS_SB_FEATURE_RO_ATTR(verity, VERITY); 1539F2FS_SB_FEATURE_RO_ATTR(sb_checksum, SB_CHKSUM); 1540F2FS_SB_FEATURE_RO_ATTR(casefold, CASEFOLD); 1541F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION); 1542F2FS_SB_FEATURE_RO_ATTR(readonly, RO); 1543F2FS_SB_FEATURE_RO_ATTR(device_alias, DEVICE_ALIAS); 1544F2FS_SB_FEATURE_RO_ATTR(packed_ssa, PACKED_SSA); 1545 1546static struct attribute *f2fs_sb_feat_attrs[] = { 1547 ATTR_LIST(sb_encryption), 1548 ATTR_LIST(sb_block_zoned), 1549 ATTR_LIST(sb_extra_attr), 1550 ATTR_LIST(sb_project_quota), 1551 ATTR_LIST(sb_inode_checksum), 1552 ATTR_LIST(sb_flexible_inline_xattr), 1553 ATTR_LIST(sb_quota_ino), 1554 ATTR_LIST(sb_inode_crtime), 1555 ATTR_LIST(sb_lost_found), 1556 ATTR_LIST(sb_verity), 1557 ATTR_LIST(sb_sb_checksum), 1558 ATTR_LIST(sb_casefold), 1559 ATTR_LIST(sb_compression), 1560 ATTR_LIST(sb_readonly), 1561 ATTR_LIST(sb_device_alias), 1562 ATTR_LIST(sb_packed_ssa), 1563 NULL, 1564}; 1565ATTRIBUTE_GROUPS(f2fs_sb_feat); 1566 1567F2FS_TUNE_RW_ATTR(reclaim_caches_kb); 1568 1569static struct attribute *f2fs_tune_attrs[] = { 1570 BASE_ATTR_LIST(reclaim_caches_kb), 1571 NULL, 1572}; 1573ATTRIBUTE_GROUPS(f2fs_tune); 1574 1575static const struct sysfs_ops f2fs_attr_ops = { 1576 .show = f2fs_attr_show, 1577 .store = f2fs_attr_store, 1578}; 1579 1580static const struct kobj_type f2fs_sb_ktype = { 1581 .default_groups = f2fs_groups, 1582 .sysfs_ops = &f2fs_attr_ops, 1583 .release = f2fs_sb_release, 1584}; 1585 1586static const struct kobj_type f2fs_ktype = { 1587 .sysfs_ops = &f2fs_attr_ops, 1588}; 1589 1590static struct kset f2fs_kset = { 1591 .kobj = {.ktype = &f2fs_ktype}, 1592}; 1593 1594static const struct sysfs_ops f2fs_feat_attr_ops = { 1595 .show = f2fs_base_attr_show, 1596 .store = f2fs_base_attr_store, 1597}; 1598 1599static const struct kobj_type f2fs_feat_ktype = { 1600 .default_groups = f2fs_feat_groups, 1601 .sysfs_ops = &f2fs_feat_attr_ops, 1602}; 1603 1604static struct kobject f2fs_feat = { 1605 .kset = &f2fs_kset, 1606}; 1607 1608static const struct sysfs_ops f2fs_tune_attr_ops = { 1609 .show = f2fs_base_attr_show, 1610 .store = f2fs_base_attr_store, 1611}; 1612 1613static const struct kobj_type f2fs_tune_ktype = { 1614 .default_groups = f2fs_tune_groups, 1615 .sysfs_ops = &f2fs_tune_attr_ops, 1616}; 1617 1618static struct kobject f2fs_tune = { 1619 .kset = &f2fs_kset, 1620}; 1621 1622static ssize_t f2fs_stat_attr_show(struct kobject *kobj, 1623 struct attribute *attr, char *buf) 1624{ 1625 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 1626 s_stat_kobj); 1627 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); 1628 1629 return a->show ? a->show(a, sbi, buf) : 0; 1630} 1631 1632static ssize_t f2fs_stat_attr_store(struct kobject *kobj, struct attribute *attr, 1633 const char *buf, size_t len) 1634{ 1635 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 1636 s_stat_kobj); 1637 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); 1638 1639 return a->store ? a->store(a, sbi, buf, len) : 0; 1640} 1641 1642static void f2fs_stat_kobj_release(struct kobject *kobj) 1643{ 1644 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 1645 s_stat_kobj); 1646 complete(&sbi->s_stat_kobj_unregister); 1647} 1648 1649static const struct sysfs_ops f2fs_stat_attr_ops = { 1650 .show = f2fs_stat_attr_show, 1651 .store = f2fs_stat_attr_store, 1652}; 1653 1654static const struct kobj_type f2fs_stat_ktype = { 1655 .default_groups = f2fs_stat_groups, 1656 .sysfs_ops = &f2fs_stat_attr_ops, 1657 .release = f2fs_stat_kobj_release, 1658}; 1659 1660static ssize_t f2fs_sb_feat_attr_show(struct kobject *kobj, 1661 struct attribute *attr, char *buf) 1662{ 1663 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 1664 s_feature_list_kobj); 1665 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); 1666 1667 return a->show ? a->show(a, sbi, buf) : 0; 1668} 1669 1670static void f2fs_feature_list_kobj_release(struct kobject *kobj) 1671{ 1672 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, 1673 s_feature_list_kobj); 1674 complete(&sbi->s_feature_list_kobj_unregister); 1675} 1676 1677static const struct sysfs_ops f2fs_feature_list_attr_ops = { 1678 .show = f2fs_sb_feat_attr_show, 1679}; 1680 1681static const struct kobj_type f2fs_feature_list_ktype = { 1682 .default_groups = f2fs_sb_feat_groups, 1683 .sysfs_ops = &f2fs_feature_list_attr_ops, 1684 .release = f2fs_feature_list_kobj_release, 1685}; 1686 1687static int __maybe_unused segment_info_seq_show(struct seq_file *seq, 1688 void *offset) 1689{ 1690 struct super_block *sb = seq->private; 1691 struct f2fs_sb_info *sbi = F2FS_SB(sb); 1692 unsigned int total_segs = 1693 le32_to_cpu(sbi->raw_super->segment_count_main); 1694 int i; 1695 1696 seq_puts(seq, "format: segment_type|valid_blocks\n" 1697 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); 1698 1699 for (i = 0; i < total_segs; i++) { 1700 struct seg_entry *se = get_seg_entry(sbi, i); 1701 1702 if ((i % 10) == 0) 1703 seq_printf(seq, "%-10d", i); 1704 seq_printf(seq, "%d|%-3u", se->type, se->valid_blocks); 1705 if ((i % 10) == 9 || i == (total_segs - 1)) 1706 seq_putc(seq, '\n'); 1707 else 1708 seq_putc(seq, ' '); 1709 } 1710 1711 return 0; 1712} 1713 1714static int __maybe_unused segment_bits_seq_show(struct seq_file *seq, 1715 void *offset) 1716{ 1717 struct super_block *sb = seq->private; 1718 struct f2fs_sb_info *sbi = F2FS_SB(sb); 1719 unsigned int total_segs = 1720 le32_to_cpu(sbi->raw_super->segment_count_main); 1721 int i, j; 1722 1723 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps|mtime\n" 1724 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); 1725 1726 for (i = 0; i < total_segs; i++) { 1727 struct seg_entry *se = get_seg_entry(sbi, i); 1728 1729 seq_printf(seq, "%-10d", i); 1730 seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks); 1731 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++) 1732 seq_printf(seq, " %.2x", se->cur_valid_map[j]); 1733 seq_printf(seq, "| %llx", se->mtime); 1734 seq_putc(seq, '\n'); 1735 } 1736 return 0; 1737} 1738 1739static int __maybe_unused victim_bits_seq_show(struct seq_file *seq, 1740 void *offset) 1741{ 1742 struct super_block *sb = seq->private; 1743 struct f2fs_sb_info *sbi = F2FS_SB(sb); 1744 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); 1745 int i; 1746 1747 seq_puts(seq, "format: victim_secmap bitmaps\n"); 1748 1749 for (i = 0; i < MAIN_SECS(sbi); i++) { 1750 if ((i % 10) == 0) 1751 seq_printf(seq, "%-10d", i); 1752 seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0); 1753 if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1)) 1754 seq_putc(seq, '\n'); 1755 else 1756 seq_putc(seq, ' '); 1757 } 1758 return 0; 1759} 1760 1761static int __maybe_unused discard_plist_seq_show(struct seq_file *seq, 1762 void *offset) 1763{ 1764 struct super_block *sb = seq->private; 1765 struct f2fs_sb_info *sbi = F2FS_SB(sb); 1766 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 1767 int i, count; 1768 1769 seq_puts(seq, "Discard pend list(Show diacrd_cmd count on each entry, .:not exist):\n"); 1770 if (!f2fs_realtime_discard_enable(sbi)) 1771 return 0; 1772 1773 if (dcc) { 1774 mutex_lock(&dcc->cmd_lock); 1775 for (i = 0; i < MAX_PLIST_NUM; i++) { 1776 struct list_head *pend_list; 1777 struct discard_cmd *dc, *tmp; 1778 1779 if (i % 8 == 0) 1780 seq_printf(seq, " %-3d", i); 1781 count = 0; 1782 pend_list = &dcc->pend_list[i]; 1783 list_for_each_entry_safe(dc, tmp, pend_list, list) 1784 count++; 1785 if (count) 1786 seq_printf(seq, " %7d", count); 1787 else 1788 seq_puts(seq, " ."); 1789 if (i % 8 == 7) 1790 seq_putc(seq, '\n'); 1791 } 1792 seq_putc(seq, '\n'); 1793 mutex_unlock(&dcc->cmd_lock); 1794 } 1795 1796 return 0; 1797} 1798 1799static int __maybe_unused disk_map_seq_show(struct seq_file *seq, 1800 void *offset) 1801{ 1802 struct super_block *sb = seq->private; 1803 struct f2fs_sb_info *sbi = F2FS_SB(sb); 1804 int i; 1805 1806 seq_printf(seq, "Address Layout : %5luB Block address (# of Segments)\n", 1807 F2FS_BLKSIZE); 1808 seq_printf(seq, " SB : %12s\n", "0/1024B"); 1809 seq_printf(seq, " seg0_blkaddr : 0x%010x\n", SEG0_BLKADDR(sbi)); 1810 seq_printf(seq, " Checkpoint : 0x%010x (%10d)\n", 1811 le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr), 2); 1812 seq_printf(seq, " SIT : 0x%010x (%10d)\n", 1813 SIT_I(sbi)->sit_base_addr, 1814 le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_sit)); 1815 seq_printf(seq, " NAT : 0x%010x (%10d)\n", 1816 NM_I(sbi)->nat_blkaddr, 1817 le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_nat)); 1818 seq_printf(seq, " SSA : 0x%010x (%10d)\n", 1819 SM_I(sbi)->ssa_blkaddr, 1820 le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_ssa)); 1821 seq_printf(seq, " Main : 0x%010x (%10d)\n", 1822 SM_I(sbi)->main_blkaddr, 1823 le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_main)); 1824 seq_printf(seq, " Block size : %12lu KB\n", F2FS_BLKSIZE >> 10); 1825 seq_printf(seq, " Segment size : %12d MB\n", 1826 (BLKS_PER_SEG(sbi) << (F2FS_BLKSIZE_BITS - 10)) >> 10); 1827 seq_printf(seq, " Segs/Sections : %12d\n", 1828 SEGS_PER_SEC(sbi)); 1829 seq_printf(seq, " Section size : %12d MB\n", 1830 (BLKS_PER_SEC(sbi) << (F2FS_BLKSIZE_BITS - 10)) >> 10); 1831 seq_printf(seq, " # of Sections : %12d\n", 1832 le32_to_cpu(F2FS_RAW_SUPER(sbi)->section_count)); 1833 1834 if (!f2fs_is_multi_device(sbi)) 1835 return 0; 1836 1837 seq_puts(seq, "\nDisk Map for multi devices:\n"); 1838 for (i = 0; i < sbi->s_ndevs; i++) 1839 seq_printf(seq, "Disk:%2d (zoned=%d): 0x%010x - 0x%010x on %s\n", 1840 i, bdev_is_zoned(FDEV(i).bdev), 1841 FDEV(i).start_blk, FDEV(i).end_blk, 1842 FDEV(i).path); 1843 return 0; 1844} 1845 1846static int __maybe_unused donation_list_seq_show(struct seq_file *seq, 1847 void *offset) 1848{ 1849 struct super_block *sb = seq->private; 1850 struct f2fs_sb_info *sbi = F2FS_SB(sb); 1851 struct inode *inode; 1852 struct f2fs_inode_info *fi; 1853 struct dentry *dentry; 1854 char *buf, *path; 1855 int i; 1856 1857 buf = f2fs_getname(sbi); 1858 if (!buf) 1859 return 0; 1860 1861 seq_printf(seq, "Donation List\n"); 1862 seq_printf(seq, " # of files : %u\n", sbi->donate_files); 1863 seq_printf(seq, " %-50s %10s %20s %20s %22s\n", 1864 "File path", "Status", "Donation offset (kb)", 1865 "Donation size (kb)", "File cached size (kb)"); 1866 seq_printf(seq, "---\n"); 1867 1868 for (i = 0; i < sbi->donate_files; i++) { 1869 spin_lock(&sbi->inode_lock[DONATE_INODE]); 1870 if (list_empty(&sbi->inode_list[DONATE_INODE])) { 1871 spin_unlock(&sbi->inode_lock[DONATE_INODE]); 1872 break; 1873 } 1874 fi = list_first_entry(&sbi->inode_list[DONATE_INODE], 1875 struct f2fs_inode_info, gdonate_list); 1876 list_move_tail(&fi->gdonate_list, &sbi->inode_list[DONATE_INODE]); 1877 inode = igrab(&fi->vfs_inode); 1878 spin_unlock(&sbi->inode_lock[DONATE_INODE]); 1879 1880 if (!inode) 1881 continue; 1882 1883 inode_lock_shared(inode); 1884 1885 dentry = d_find_alias(inode); 1886 if (!dentry) { 1887 path = NULL; 1888 } else { 1889 path = dentry_path_raw(dentry, buf, PATH_MAX); 1890 if (IS_ERR(path)) 1891 goto next; 1892 } 1893 seq_printf(seq, " %-50s %10s %20llu %20llu %22llu\n", 1894 path ? path : "<unlinked>", 1895 is_inode_flag_set(inode, FI_DONATE_FINISHED) ? 1896 "Evicted" : "Donated", 1897 (loff_t)fi->donate_start << (PAGE_SHIFT - 10), 1898 (loff_t)(fi->donate_end + 1) << (PAGE_SHIFT - 10), 1899 (loff_t)inode->i_mapping->nrpages << (PAGE_SHIFT - 10)); 1900next: 1901 dput(dentry); 1902 inode_unlock_shared(inode); 1903 iput(inode); 1904 } 1905 f2fs_putname(buf); 1906 return 0; 1907} 1908 1909#ifdef CONFIG_F2FS_FAULT_INJECTION 1910static int __maybe_unused inject_stats_seq_show(struct seq_file *seq, 1911 void *offset) 1912{ 1913 struct super_block *sb = seq->private; 1914 struct f2fs_sb_info *sbi = F2FS_SB(sb); 1915 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; 1916 int i; 1917 1918 seq_puts(seq, "fault_type injected_count\n"); 1919 1920 for (i = 0; i < FAULT_MAX; i++) 1921 seq_printf(seq, "%-24s%-10u\n", f2fs_fault_name[i], 1922 ffi->inject_count[i]); 1923 return 0; 1924} 1925#endif 1926 1927int __init f2fs_init_sysfs(void) 1928{ 1929 int ret; 1930 1931 kobject_set_name(&f2fs_kset.kobj, "f2fs"); 1932 f2fs_kset.kobj.parent = fs_kobj; 1933 ret = kset_register(&f2fs_kset); 1934 if (ret) 1935 return ret; 1936 1937 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype, 1938 NULL, "features"); 1939 if (ret) 1940 goto put_kobject; 1941 1942 ret = kobject_init_and_add(&f2fs_tune, &f2fs_tune_ktype, 1943 NULL, "tuning"); 1944 if (ret) 1945 goto put_kobject; 1946 1947 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); 1948 if (!f2fs_proc_root) { 1949 ret = -ENOMEM; 1950 goto put_kobject; 1951 } 1952 1953 return 0; 1954 1955put_kobject: 1956 kobject_put(&f2fs_tune); 1957 kobject_put(&f2fs_feat); 1958 kset_unregister(&f2fs_kset); 1959 return ret; 1960} 1961 1962void f2fs_exit_sysfs(void) 1963{ 1964 kobject_put(&f2fs_tune); 1965 kobject_put(&f2fs_feat); 1966 kset_unregister(&f2fs_kset); 1967 remove_proc_entry("fs/f2fs", NULL); 1968 f2fs_proc_root = NULL; 1969} 1970 1971int f2fs_register_sysfs(struct f2fs_sb_info *sbi) 1972{ 1973 struct super_block *sb = sbi->sb; 1974 int err; 1975 1976 sbi->s_kobj.kset = &f2fs_kset; 1977 init_completion(&sbi->s_kobj_unregister); 1978 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL, 1979 "%s", sb->s_id); 1980 if (err) 1981 goto put_sb_kobj; 1982 1983 sbi->s_stat_kobj.kset = &f2fs_kset; 1984 init_completion(&sbi->s_stat_kobj_unregister); 1985 err = kobject_init_and_add(&sbi->s_stat_kobj, &f2fs_stat_ktype, 1986 &sbi->s_kobj, "stat"); 1987 if (err) 1988 goto put_stat_kobj; 1989 1990 sbi->s_feature_list_kobj.kset = &f2fs_kset; 1991 init_completion(&sbi->s_feature_list_kobj_unregister); 1992 err = kobject_init_and_add(&sbi->s_feature_list_kobj, 1993 &f2fs_feature_list_ktype, 1994 &sbi->s_kobj, "feature_list"); 1995 if (err) 1996 goto put_feature_list_kobj; 1997 1998 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); 1999 if (!sbi->s_proc) { 2000 err = -ENOMEM; 2001 goto put_feature_list_kobj; 2002 } 2003 2004 proc_create_single_data("segment_info", 0444, sbi->s_proc, 2005 segment_info_seq_show, sb); 2006 proc_create_single_data("segment_bits", 0444, sbi->s_proc, 2007 segment_bits_seq_show, sb); 2008#ifdef CONFIG_F2FS_IOSTAT 2009 proc_create_single_data("iostat_info", 0444, sbi->s_proc, 2010 iostat_info_seq_show, sb); 2011#endif 2012 proc_create_single_data("victim_bits", 0444, sbi->s_proc, 2013 victim_bits_seq_show, sb); 2014 proc_create_single_data("discard_plist_info", 0444, sbi->s_proc, 2015 discard_plist_seq_show, sb); 2016 proc_create_single_data("disk_map", 0444, sbi->s_proc, 2017 disk_map_seq_show, sb); 2018 proc_create_single_data("donation_list", 0444, sbi->s_proc, 2019 donation_list_seq_show, sb); 2020#ifdef CONFIG_F2FS_FAULT_INJECTION 2021 proc_create_single_data("inject_stats", 0444, sbi->s_proc, 2022 inject_stats_seq_show, sb); 2023#endif 2024 return 0; 2025put_feature_list_kobj: 2026 kobject_put(&sbi->s_feature_list_kobj); 2027 wait_for_completion(&sbi->s_feature_list_kobj_unregister); 2028put_stat_kobj: 2029 kobject_put(&sbi->s_stat_kobj); 2030 wait_for_completion(&sbi->s_stat_kobj_unregister); 2031put_sb_kobj: 2032 kobject_put(&sbi->s_kobj); 2033 wait_for_completion(&sbi->s_kobj_unregister); 2034 return err; 2035} 2036 2037void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) 2038{ 2039 remove_proc_subtree(sbi->sb->s_id, f2fs_proc_root); 2040 2041 kobject_put(&sbi->s_stat_kobj); 2042 wait_for_completion(&sbi->s_stat_kobj_unregister); 2043 kobject_put(&sbi->s_feature_list_kobj); 2044 wait_for_completion(&sbi->s_feature_list_kobj_unregister); 2045 2046 kobject_put(&sbi->s_kobj); 2047 wait_for_completion(&sbi->s_kobj_unregister); 2048}
~/
Read-only file preview.