summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/tree-checker.c
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2019-03-20 01:36:06 -0400
committerDavid Sterba <dsterba@suse.com>2019-04-29 13:02:31 -0400
commitf114024376bceb1c0f61a7bad4a72a0f978767af (patch)
treea6b14941c212665c51871b15dbc8b9476da85689 /fs/btrfs/tree-checker.c
parent82fc28fbedbb59642f05215db3b0ef4eb91aa31d (diff)
btrfs: tree-checker: Make chunk item checker messages more readable
Old error message would be something like: BTRFS error (device dm-3): invalid chunk num_stipres: 0 New error message would be: Btrfs critical (device dm-3): corrupt superblock syschunk array: chunk_start=2097152, invalid chunk num_stripes: 0 Or Btrfs critical (device dm-3): corrupt leaf: root=3 block=8388608 slot=3 chunk_start=2097152, invalid chunk num_stripes: 0 And for certain error message, also output expected value. The error message levels are changed from error to critical. Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/tree-checker.c')
-rw-r--r--fs/btrfs/tree-checker.c81
1 files changed, 68 insertions, 13 deletions
diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index eee861975816..80d87814f261 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -448,6 +448,51 @@ static int check_block_group_item(struct btrfs_fs_info *fs_info,
448 return 0; 448 return 0;
449} 449}
450 450
451__printf(5, 6)
452__cold
453static void chunk_err(const struct btrfs_fs_info *fs_info,
454 const struct extent_buffer *leaf,
455 const struct btrfs_chunk *chunk, u64 logical,
456 const char *fmt, ...)
457{
458 bool is_sb;
459 struct va_format vaf;
460 va_list args;
461 int i;
462 int slot = -1;
463
464 /* Only superblock eb is able to have such small offset */
465 is_sb = (leaf->start == BTRFS_SUPER_INFO_OFFSET);
466
467 if (!is_sb) {
468 /*
469 * Get the slot number by iterating through all slots, this
470 * would provide better readability.
471 */
472 for (i = 0; i < btrfs_header_nritems(leaf); i++) {
473 if (btrfs_item_ptr_offset(leaf, i) ==
474 (unsigned long)chunk) {
475 slot = i;
476 break;
477 }
478 }
479 }
480 va_start(args, fmt);
481 vaf.fmt = fmt;
482 vaf.va = &args;
483
484 if (is_sb)
485 btrfs_crit(fs_info,
486 "corrupt superblock syschunk array: chunk_start=%llu, %pV",
487 logical, &vaf);
488 else
489 btrfs_crit(fs_info,
490 "corrupt leaf: root=%llu block=%llu slot=%d chunk_start=%llu, %pV",
491 BTRFS_CHUNK_TREE_OBJECTID, leaf->start, slot,
492 logical, &vaf);
493 va_end(args);
494}
495
451/* 496/*
452 * The common chunk check which could also work on super block sys chunk array. 497 * The common chunk check which could also work on super block sys chunk array.
453 * 498 *
@@ -473,31 +518,38 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
473 type = btrfs_chunk_type(leaf, chunk); 518 type = btrfs_chunk_type(leaf, chunk);
474 519
475 if (!num_stripes) { 520 if (!num_stripes) {
476 btrfs_err(fs_info, "invalid chunk num_stripes: %u", 521 chunk_err(fs_info, leaf, chunk, logical,
477 num_stripes); 522 "invalid chunk num_stripes, have %u", num_stripes);
478 return -EIO; 523 return -EIO;
479 } 524 }
480 if (!IS_ALIGNED(logical, fs_info->sectorsize)) { 525 if (!IS_ALIGNED(logical, fs_info->sectorsize)) {
481 btrfs_err(fs_info, "invalid chunk logical %llu", logical); 526 chunk_err(fs_info, leaf, chunk, logical,
527 "invalid chunk logical, have %llu should aligned to %u",
528 logical, fs_info->sectorsize);
482 return -EIO; 529 return -EIO;
483 } 530 }
484 if (btrfs_chunk_sector_size(leaf, chunk) != fs_info->sectorsize) { 531 if (btrfs_chunk_sector_size(leaf, chunk) != fs_info->sectorsize) {
485 btrfs_err(fs_info, "invalid chunk sectorsize %u", 532 chunk_err(fs_info, leaf, chunk, logical,
486 btrfs_chunk_sector_size(leaf, chunk)); 533 "invalid chunk sectorsize, have %u expect %u",
534 btrfs_chunk_sector_size(leaf, chunk),
535 fs_info->sectorsize);
487 return -EIO; 536 return -EIO;
488 } 537 }
489 if (!length || !IS_ALIGNED(length, fs_info->sectorsize)) { 538 if (!length || !IS_ALIGNED(length, fs_info->sectorsize)) {
490 btrfs_err(fs_info, "invalid chunk length %llu", length); 539 chunk_err(fs_info, leaf, chunk, logical,
540 "invalid chunk length, have %llu", length);
491 return -EIO; 541 return -EIO;
492 } 542 }
493 if (!is_power_of_2(stripe_len) || stripe_len != BTRFS_STRIPE_LEN) { 543 if (!is_power_of_2(stripe_len) || stripe_len != BTRFS_STRIPE_LEN) {
494 btrfs_err(fs_info, "invalid chunk stripe length: %llu", 544 chunk_err(fs_info, leaf, chunk, logical,
545 "invalid chunk stripe length: %llu",
495 stripe_len); 546 stripe_len);
496 return -EIO; 547 return -EIO;
497 } 548 }
498 if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) & 549 if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) &
499 type) { 550 type) {
500 btrfs_err(fs_info, "unrecognized chunk type: %llu", 551 chunk_err(fs_info, leaf, chunk, logical,
552 "unrecognized chunk type: 0x%llx",
501 ~(BTRFS_BLOCK_GROUP_TYPE_MASK | 553 ~(BTRFS_BLOCK_GROUP_TYPE_MASK |
502 BTRFS_BLOCK_GROUP_PROFILE_MASK) & 554 BTRFS_BLOCK_GROUP_PROFILE_MASK) &
503 btrfs_chunk_type(leaf, chunk)); 555 btrfs_chunk_type(leaf, chunk));
@@ -505,14 +557,17 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
505 } 557 }
506 558
507 if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) { 559 if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) {
508 btrfs_err(fs_info, "missing chunk type flag: 0x%llx", type); 560 chunk_err(fs_info, leaf, chunk, logical,
561 "missing chunk type flag, have 0x%llx one bit must be set in 0x%llx",
562 type, BTRFS_BLOCK_GROUP_TYPE_MASK);
509 return -EIO; 563 return -EIO;
510 } 564 }
511 565
512 if ((type & BTRFS_BLOCK_GROUP_SYSTEM) && 566 if ((type & BTRFS_BLOCK_GROUP_SYSTEM) &&
513 (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) { 567 (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) {
514 btrfs_err(fs_info, 568 chunk_err(fs_info, leaf, chunk, logical,
515 "system chunk with data or metadata type: 0x%llx", type); 569 "system chunk with data or metadata type: 0x%llx",
570 type);
516 return -EIO; 571 return -EIO;
517 } 572 }
518 573
@@ -523,7 +578,7 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
523 if (!mixed) { 578 if (!mixed) {
524 if ((type & BTRFS_BLOCK_GROUP_METADATA) && 579 if ((type & BTRFS_BLOCK_GROUP_METADATA) &&
525 (type & BTRFS_BLOCK_GROUP_DATA)) { 580 (type & BTRFS_BLOCK_GROUP_DATA)) {
526 btrfs_err(fs_info, 581 chunk_err(fs_info, leaf, chunk, logical,
527 "mixed chunk type in non-mixed mode: 0x%llx", type); 582 "mixed chunk type in non-mixed mode: 0x%llx", type);
528 return -EIO; 583 return -EIO;
529 } 584 }
@@ -535,7 +590,7 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
535 (type & BTRFS_BLOCK_GROUP_RAID6 && num_stripes < 3) || 590 (type & BTRFS_BLOCK_GROUP_RAID6 && num_stripes < 3) ||
536 (type & BTRFS_BLOCK_GROUP_DUP && num_stripes != 2) || 591 (type & BTRFS_BLOCK_GROUP_DUP && num_stripes != 2) ||
537 ((type & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 && num_stripes != 1)) { 592 ((type & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 && num_stripes != 1)) {
538 btrfs_err(fs_info, 593 chunk_err(fs_info, leaf, chunk, logical,
539 "invalid num_stripes:sub_stripes %u:%u for profile %llu", 594 "invalid num_stripes:sub_stripes %u:%u for profile %llu",
540 num_stripes, sub_stripes, 595 num_stripes, sub_stripes,
541 type & BTRFS_BLOCK_GROUP_PROFILE_MASK); 596 type & BTRFS_BLOCK_GROUP_PROFILE_MASK);