Skip to content

zdb: better handling for corrupt block pointers #17166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2582,19 +2582,29 @@ snprintf_blkptr_compact(char *blkbuf, size_t buflen, const blkptr_t *bp,
}
}

static void
static u_longlong_t
print_indirect(spa_t *spa, blkptr_t *bp, const zbookmark_phys_t *zb,
const dnode_phys_t *dnp)
{
char blkbuf[BP_SPRINTF_LEN];
u_longlong_t offset;
int l;

offset = (u_longlong_t)blkid2offset(dnp, bp, zb);
if (!BP_IS_EMBEDDED(bp)) {
ASSERT3U(BP_GET_TYPE(bp), ==, dnp->dn_type);
ASSERT3U(BP_GET_LEVEL(bp), ==, zb->zb_level);
if (BP_GET_TYPE(bp) != dnp->dn_type) {
(void) fprintf(stderr, "%16llx: Block pointer type "
"(%llu) does not match dnode type (%hhu)\n",
offset, BP_GET_TYPE(bp), dnp->dn_type);
}
if (BP_GET_LEVEL(bp) != zb->zb_level) {
(void) fprintf(stderr, "%16llx: Block pointer level "
"(%llu) does not match bookmark level (%ld)\n",
offset, BP_GET_LEVEL(bp), zb->zb_level);
}
}

(void) printf("%16llx ", (u_longlong_t)blkid2offset(dnp, bp, zb));
(void) printf("%16llx ", offset);

ASSERT(zb->zb_level >= 0);

Expand All @@ -2610,18 +2620,21 @@ print_indirect(spa_t *spa, blkptr_t *bp, const zbookmark_phys_t *zb,
if (dump_opt['Z'] && BP_GET_COMPRESS(bp) == ZIO_COMPRESS_ZSTD)
snprintf_zstd_header(spa, blkbuf, sizeof (blkbuf), bp);
(void) printf("%s\n", blkbuf);

return (offset);
}

static int
visit_indirect(spa_t *spa, const dnode_phys_t *dnp,
blkptr_t *bp, const zbookmark_phys_t *zb)
{
u_longlong_t offset;
int err = 0;

if (BP_GET_LOGICAL_BIRTH(bp) == 0)
return (0);

print_indirect(spa, bp, zb, dnp);
offset = print_indirect(spa, bp, zb, dnp);

if (BP_GET_LEVEL(bp) > 0 && !BP_IS_HOLE(bp)) {
arc_flags_t flags = ARC_FLAG_WAIT;
Expand Down Expand Up @@ -2651,8 +2664,14 @@ visit_indirect(spa_t *spa, const dnode_phys_t *dnp,
break;
fill += BP_GET_FILL(cbp);
}
if (!err)
ASSERT3U(fill, ==, BP_GET_FILL(bp));
if (!err) {
if (fill != BP_GET_FILL(bp)) {
(void) fprintf(stderr, "%16llx: Block pointer "
"fill (%llu) does not match calculated "
"value (%lu)\n", offset, BP_GET_FILL(bp),
fill);
}
}
arc_buf_destroy(buf, &buf);
}

Expand Down
Loading