OpenZFS 6410 - teach zdb to perform object lookups by path

Authored by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Will Andrews <will@freebsd.org>
Approved by: Dan McDonald <danmcd@omniti.com>
Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>

Porting Notes:
- Replaced zdb.8 with upstream mdoc zdb.1m version.  Updated to
  include Linux specific features: -V verbatium imports and
  improved label printing (-u, and -l).
- Minor changes to `zdb -h` output to honor 80 character limit.

OpenZFS-issue: https://www.illumos.org/issues/6410
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/ed61ec1
Closes #6006
This commit is contained in:
Brian Behlendorf 2017-04-13 09:40:56 -07:00 committed by GitHub
parent e550644f0c
commit a44e7faa6c
2 changed files with 562 additions and 600 deletions

View File

@ -22,8 +22,10 @@
/* /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2016 by Delphix. All rights reserved. * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
* Copyright (c) 2015, 2017, Intel Corporation. * Copyright (c) 2014 Integros [integros.com]
* Copyright 2016 Nexenta Systems, Inc. * Copyright 2016 Nexenta Systems, Inc.
* Copyright (c) 2017 Lawrence Livermore National Security, LLC.
* Copyright (c) 2015, 2017, Intel Corporation.
*/ */
#include <stdio.h> #include <stdio.h>
@ -122,19 +124,22 @@ static void
usage(void) usage(void)
{ {
(void) fprintf(stderr, (void) fprintf(stderr,
"Usage: %s [-CmMdibcsDvhLXFPAG] [-t txg] [-e [-p path...]] " "Usage:\t%s [-AbcdDFGhiLMPsvVX] [-e [-p <path> ...]] "
"[-U config] [-I inflight I/Os] [-x dumpdir] [-o var=value] " "[-I <inflight I/Os>]\n"
"poolname [object...]\n" "\t\t[-o <var>=<value>]... [-t <txg>] [-U <cache>] [-x <dumpdir>]\n"
" %s [-divPA] [-e -p path...] [-U config] dataset " "\t\t[<poolname> [<object> ...]]\n"
"[object...]\n" "\t%s [-AdiPv] [-e [-p <path> ...]] [-U <cache>] <dataset> "
" %s -mM [-LXFPA] [-t txg] [-e [-p path...]] [-U config] " "[<object> ...]\n"
"poolname [vdev [metaslab...]]\n" "\t%s -C [-A] [-U <cache>]\n"
" %s -R [-A] [-e [-p path...]] poolname " "\t%s -l [-Aqu] <device>\n"
"vdev:offset:size[:flags]\n" "\t%s -m [-AFLPX] [-e [-p <path> ...]] [-t <txg>] [-U <cache>]\n"
" %s -S [-PA] [-e [-p path...]] [-U config] poolname\n" "\t\t<poolname> [<vdev> [<metaslab> ...]]\n"
" %s -l [-Aqu] device\n" "\t%s -O <dataset> <path>\n"
" %s -C [-A] [-U config]\n\n", "\t%s -R [-A] [-e [-p <path> ...]] [-U <cache>]\n"
cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname); "\t\t<poolname> <vdev>:<offset>:<size>[:<flags>]\n"
"\t%s -S [-AP] [-e [-p <path> ...]] [-U <cache>] <poolname>\n\n",
cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname,
cmdname);
(void) fprintf(stderr, " Dataset name must include at least one " (void) fprintf(stderr, " Dataset name must include at least one "
"separator character '/' or '@'\n"); "separator character '/' or '@'\n");
@ -143,52 +148,56 @@ usage(void)
(void) fprintf(stderr, " If object numbers are specified, only " (void) fprintf(stderr, " If object numbers are specified, only "
"those objects are dumped\n\n"); "those objects are dumped\n\n");
(void) fprintf(stderr, " Options to control amount of output:\n"); (void) fprintf(stderr, " Options to control amount of output:\n");
(void) fprintf(stderr, " -d dataset(s)\n");
(void) fprintf(stderr, " -i intent logs\n");
(void) fprintf(stderr, " -C config (or cachefile if alone)\n");
(void) fprintf(stderr, " -h pool history\n");
(void) fprintf(stderr, " -b block statistics\n"); (void) fprintf(stderr, " -b block statistics\n");
(void) fprintf(stderr, " -m metaslabs\n");
(void) fprintf(stderr, " -M metaslab groups\n");
(void) fprintf(stderr, " -c checksum all metadata (twice for " (void) fprintf(stderr, " -c checksum all metadata (twice for "
"all data) blocks\n"); "all data) blocks\n");
(void) fprintf(stderr, " -s report stats on zdb's I/O\n"); (void) fprintf(stderr, " -C config (or cachefile if alone)\n");
(void) fprintf(stderr, " -d dataset(s)\n");
(void) fprintf(stderr, " -D dedup statistics\n"); (void) fprintf(stderr, " -D dedup statistics\n");
(void) fprintf(stderr, " -S simulate dedup to measure effect\n"); (void) fprintf(stderr, " -h pool history\n");
(void) fprintf(stderr, " -v verbose (applies to all others)\n"); (void) fprintf(stderr, " -i intent logs\n");
(void) fprintf(stderr, " -l read label contents\n"); (void) fprintf(stderr, " -l read label contents\n");
(void) fprintf(stderr, " -L disable leak tracking (do not " (void) fprintf(stderr, " -L disable leak tracking (do not "
"load spacemaps)\n"); "load spacemaps)\n");
(void) fprintf(stderr, " -m metaslabs\n");
(void) fprintf(stderr, " -M metaslab groups\n");
(void) fprintf(stderr, " -O perform object lookups by path\n");
(void) fprintf(stderr, " -R read and display block from a " (void) fprintf(stderr, " -R read and display block from a "
"device\n\n"); "device\n");
(void) fprintf(stderr, " -s report stats on zdb's I/O\n");
(void) fprintf(stderr, " -S simulate dedup to measure effect\n");
(void) fprintf(stderr, " -v verbose (applies to all "
"others)\n\n");
(void) fprintf(stderr, " Below options are intended for use " (void) fprintf(stderr, " Below options are intended for use "
"with other options:\n"); "with other options:\n");
(void) fprintf(stderr, " -A ignore assertions (-A), enable " (void) fprintf(stderr, " -A ignore assertions (-A), enable "
"panic recovery (-AA) or both (-AAA)\n"); "panic recovery (-AA) or both (-AAA)\n");
(void) fprintf(stderr, " -F attempt automatic rewind within "
"safe range of transaction groups\n");
(void) fprintf(stderr, " -U <cachefile_path> -- use alternate "
"cachefile\n");
(void) fprintf(stderr, " -X attempt extreme rewind (does not "
"work with dataset)\n");
(void) fprintf(stderr, " -e pool is exported/destroyed/" (void) fprintf(stderr, " -e pool is exported/destroyed/"
"has altroot/not in a cachefile\n"); "has altroot/not in a cachefile\n");
(void) fprintf(stderr, " -p <path> -- use one or more with " (void) fprintf(stderr, " -F attempt automatic rewind within "
"-e to specify path to vdev dir\n"); "safe range of transaction groups\n");
(void) fprintf(stderr, " -x <dumpdir> -- "
"dump all read blocks into specified directory\n");
(void) fprintf(stderr, " -P print numbers in parsable form\n");
(void) fprintf(stderr, " -t <txg> -- highest txg to use when "
"searching for uberblocks\n");
(void) fprintf(stderr, " -I <number of inflight I/Os> -- "
"specify the maximum number of "
"checksumming I/Os [default is 200]\n");
(void) fprintf(stderr, " -G dump zfs_dbgmsg buffer before " (void) fprintf(stderr, " -G dump zfs_dbgmsg buffer before "
"exiting\n"); "exiting\n");
(void) fprintf(stderr, " -I <number of inflight I/Os> -- "
"specify the maximum number of\n "
"checksumming I/Os [default is 200]\n");
(void) fprintf(stderr, " -o <variable>=<value> set global " (void) fprintf(stderr, " -o <variable>=<value> set global "
"variable to an unsigned 32-bit integer value\n"); "variable to an unsigned 32-bit integer\n");
(void) fprintf(stderr, " -p <path> -- use one or more with "
"-e to specify path to vdev dir\n");
(void) fprintf(stderr, " -P print numbers in parseable form\n");
(void) fprintf(stderr, " -q don't print label contents\n"); (void) fprintf(stderr, " -q don't print label contents\n");
(void) fprintf(stderr, " -t <txg> -- highest txg to use when "
"searching for uberblocks\n");
(void) fprintf(stderr, " -u uberblock\n"); (void) fprintf(stderr, " -u uberblock\n");
(void) fprintf(stderr, " -U <cachefile_path> -- use alternate "
"cachefile\n");
(void) fprintf(stderr, " -x <dumpdir> -- "
"dump all read blocks into specified directory\n");
(void) fprintf(stderr, " -X attempt extreme rewind (does not "
"work with dataset)\n");
(void) fprintf(stderr, " -V verbatim import (as if it had been "
"loaded at boot)\n\n");
(void) fprintf(stderr, "Specify an option more than once (e.g. -bb) " (void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
"to make only that option verbose\n"); "to make only that option verbose\n");
(void) fprintf(stderr, "Default is to dump everything non-verbosely\n"); (void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
@ -1607,8 +1616,55 @@ dump_deadlist(dsl_deadlist_t *dl)
static avl_tree_t idx_tree; static avl_tree_t idx_tree;
static avl_tree_t domain_tree; static avl_tree_t domain_tree;
static boolean_t fuid_table_loaded; static boolean_t fuid_table_loaded;
static boolean_t sa_loaded; static objset_t *sa_os = NULL;
sa_attr_type_t *sa_attr_table; static sa_attr_type_t *sa_attr_table = NULL;
static int
open_objset(const char *path, dmu_objset_type_t type, void *tag, objset_t **osp)
{
int err;
uint64_t sa_attrs = 0;
uint64_t version = 0;
VERIFY3P(sa_os, ==, NULL);
err = dmu_objset_own(path, type, B_TRUE, tag, osp);
if (err != 0) {
(void) fprintf(stderr, "failed to own dataset '%s': %s\n", path,
strerror(err));
return (err);
}
if (dmu_objset_type(*osp) == DMU_OST_ZFS) {
(void) zap_lookup(*osp, MASTER_NODE_OBJ, ZPL_VERSION_STR,
8, 1, &version);
if (version >= ZPL_VERSION_SA) {
(void) zap_lookup(*osp, MASTER_NODE_OBJ, ZFS_SA_ATTRS,
8, 1, &sa_attrs);
}
err = sa_setup(*osp, sa_attrs, zfs_attr_table, ZPL_END,
&sa_attr_table);
if (err != 0) {
(void) fprintf(stderr, "sa_setup failed: %s\n",
strerror(err));
dmu_objset_disown(*osp, tag);
*osp = NULL;
}
}
sa_os = *osp;
return (0);
}
static void
close_objset(objset_t *os, void *tag)
{
VERIFY3P(os, ==, sa_os);
if (os->os_sa != NULL)
sa_tear_down(os);
dmu_objset_disown(os, tag);
sa_attr_table = NULL;
sa_os = NULL;
}
static void static void
fuid_table_destroy(void) fuid_table_destroy(void)
@ -1735,25 +1791,7 @@ dump_znode(objset_t *os, uint64_t object, void *data, size_t size)
int idx = 0; int idx = 0;
int error; int error;
if (!sa_loaded) { VERIFY3P(os, ==, sa_os);
uint64_t sa_attrs = 0;
uint64_t version;
VERIFY(zap_lookup(os, MASTER_NODE_OBJ, ZPL_VERSION_STR,
8, 1, &version) == 0);
if (version >= ZPL_VERSION_SA) {
VERIFY(zap_lookup(os, MASTER_NODE_OBJ, ZFS_SA_ATTRS,
8, 1, &sa_attrs) == 0);
}
if ((error = sa_setup(os, sa_attrs, zfs_attr_table,
ZPL_END, &sa_attr_table)) != 0) {
(void) printf("sa_setup failed errno %d, can't "
"display znode contents\n", error);
return;
}
sa_loaded = B_TRUE;
}
if (sa_handle_get(os, object, NULL, SA_HDL_PRIVATE, &hdl)) { if (sa_handle_get(os, object, NULL, SA_HDL_PRIVATE, &hdl)) {
(void) printf("Failed to get handle for SA znode\n"); (void) printf("Failed to get handle for SA znode\n");
return; return;
@ -2499,6 +2537,108 @@ dump_label_uberblocks(label_t *label, uint64_t ashift, int label_num)
} }
} }
static char curpath[PATH_MAX];
/*
* Iterate through the path components, recursively passing
* current one's obj and remaining path until we find the obj
* for the last one.
*/
static int
dump_path_impl(objset_t *os, uint64_t obj, char *name)
{
int err;
int header = 1;
uint64_t child_obj;
char *s;
dmu_buf_t *db;
dmu_object_info_t doi;
if ((s = strchr(name, '/')) != NULL)
*s = '\0';
err = zap_lookup(os, obj, name, 8, 1, &child_obj);
(void) strlcat(curpath, name, sizeof (curpath));
if (err != 0) {
(void) fprintf(stderr, "failed to lookup %s: %s\n",
curpath, strerror(err));
return (err);
}
child_obj = ZFS_DIRENT_OBJ(child_obj);
err = sa_buf_hold(os, child_obj, FTAG, &db);
if (err != 0) {
(void) fprintf(stderr,
"failed to get SA dbuf for obj %llu: %s\n",
(u_longlong_t)child_obj, strerror(err));
return (EINVAL);
}
dmu_object_info_from_db(db, &doi);
sa_buf_rele(db, FTAG);
if (doi.doi_bonus_type != DMU_OT_SA &&
doi.doi_bonus_type != DMU_OT_ZNODE) {
(void) fprintf(stderr, "invalid bonus type %d for obj %llu\n",
doi.doi_bonus_type, (u_longlong_t)child_obj);
return (EINVAL);
}
if (dump_opt['v'] > 6) {
(void) printf("obj=%llu %s type=%d bonustype=%d\n",
(u_longlong_t)child_obj, curpath, doi.doi_type,
doi.doi_bonus_type);
}
(void) strlcat(curpath, "/", sizeof (curpath));
switch (doi.doi_type) {
case DMU_OT_DIRECTORY_CONTENTS:
if (s != NULL && *(s + 1) != '\0')
return (dump_path_impl(os, child_obj, s + 1));
/*FALLTHROUGH*/
case DMU_OT_PLAIN_FILE_CONTENTS:
dump_object(os, child_obj, dump_opt['v'], &header);
return (0);
default:
(void) fprintf(stderr, "object %llu has non-file/directory "
"type %d\n", (u_longlong_t)obj, doi.doi_type);
break;
}
return (EINVAL);
}
/*
* Dump the blocks for the object specified by path inside the dataset.
*/
static int
dump_path(char *ds, char *path)
{
int err;
objset_t *os;
uint64_t root_obj;
err = open_objset(ds, DMU_OST_ZFS, FTAG, &os);
if (err != 0)
return (err);
err = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1, &root_obj);
if (err != 0) {
(void) fprintf(stderr, "can't lookup root znode: %s\n",
strerror(err));
dmu_objset_disown(os, FTAG);
return (EINVAL);
}
(void) snprintf(curpath, sizeof (curpath), "dataset=%s path=/", ds);
err = dump_path_impl(os, root_obj, path);
close_objset(os, FTAG);
return (err);
}
static int static int
dump_label(const char *dev) dump_label(const char *dev)
{ {
@ -2677,11 +2817,9 @@ dump_one_dir(const char *dsname, void *arg)
objset_t *os; objset_t *os;
spa_feature_t f; spa_feature_t f;
error = dmu_objset_own(dsname, DMU_OST_ANY, B_TRUE, FTAG, &os); error = open_objset(dsname, DMU_OST_ANY, FTAG, &os);
if (error) { if (error != 0)
(void) printf("Could not open %s, error %d\n", dsname, error);
return (0); return (0);
}
for (f = 0; f < SPA_FEATURES; f++) { for (f = 0; f < SPA_FEATURES; f++) {
if (!dmu_objset_ds(os)->ds_feature_inuse[f]) if (!dmu_objset_ds(os)->ds_feature_inuse[f])
@ -2692,9 +2830,8 @@ dump_one_dir(const char *dsname, void *arg)
} }
dump_dir(os); dump_dir(os);
dmu_objset_disown(os, FTAG); close_objset(os, FTAG);
fuid_table_destroy(); fuid_table_destroy();
sa_loaded = B_FALSE;
return (0); return (0);
} }
@ -4077,38 +4214,37 @@ main(int argc, char **argv)
spa_config_path = spa_config_path_env; spa_config_path = spa_config_path_env;
while ((c = getopt(argc, argv, while ((c = getopt(argc, argv,
"bcdhilmMI:suCDRSAFLXx:evp:t:U:PVGoq")) != -1) { "AbcCdDeFGhiI:lLmMo:Op:PqRsSt:uU:vVx:X")) != -1) {
switch (c) { switch (c) {
case 'b': case 'b':
case 'c': case 'c':
case 'C':
case 'd': case 'd':
case 'D':
case 'G':
case 'h': case 'h':
case 'i': case 'i':
case 'l': case 'l':
case 'm': case 'm':
case 's':
case 'u':
case 'C':
case 'D':
case 'M': case 'M':
case 'O':
case 'R': case 'R':
case 's':
case 'S': case 'S':
case 'G': case 'u':
dump_opt[c]++; dump_opt[c]++;
dump_all = 0; dump_all = 0;
break; break;
case 'A': case 'A':
case 'e':
case 'F': case 'F':
case 'L': case 'L':
case 'X':
case 'e':
case 'P': case 'P':
case 'q': case 'q':
case 'X':
dump_opt[c]++; dump_opt[c]++;
break; break;
case 'V': /* NB: Sort single match options below. */
flags |= ZFS_IMPORT_VERBATIM;
break;
case 'I': case 'I':
max_inflight = strtoull(optarg, NULL, 0); max_inflight = strtoull(optarg, NULL, 0);
if (max_inflight == 0) { if (max_inflight == 0) {
@ -4118,6 +4254,11 @@ main(int argc, char **argv)
usage(); usage();
} }
break; break;
case 'o':
error = set_global_var(optarg);
if (error != 0)
usage();
break;
case 'p': case 'p':
if (searchdirs == NULL) { if (searchdirs == NULL) {
searchdirs = umem_alloc(sizeof (char *), searchdirs = umem_alloc(sizeof (char *),
@ -4147,14 +4288,12 @@ main(int argc, char **argv)
case 'v': case 'v':
verbose++; verbose++;
break; break;
case 'V':
flags |= ZFS_IMPORT_VERBATIM;
break;
case 'x': case 'x':
vn_dumpdir = optarg; vn_dumpdir = optarg;
break; break;
case 'o':
error = set_global_var(optarg);
if (error != 0)
usage();
break;
default: default:
usage(); usage();
break; break;
@ -4196,7 +4335,7 @@ main(int argc, char **argv)
verbose = MAX(verbose, 1); verbose = MAX(verbose, 1);
for (c = 0; c < 256; c++) { for (c = 0; c < 256; c++) {
if (dump_all && !strchr("elAFLRSXP", c)) if (dump_all && strchr("AeFlLOPRSX", c) == NULL)
dump_opt[c] = 1; dump_opt[c] = 1;
if (dump_opt[c]) if (dump_opt[c])
dump_opt[c] += verbose; dump_opt[c] += verbose;
@ -4221,6 +4360,13 @@ main(int argc, char **argv)
if (dump_opt['l']) if (dump_opt['l'])
return (dump_label(argv[0])); return (dump_label(argv[0]));
if (dump_opt['O']) {
if (argc != 2)
usage();
dump_opt['v'] = verbose + 3;
return (dump_path(argv[0], argv[1]));
}
if (dump_opt['X'] || dump_opt['F']) if (dump_opt['X'] || dump_opt['F'])
rewind = ZPOOL_DO_REWIND | rewind = ZPOOL_DO_REWIND |
(dump_opt['X'] ? ZPOOL_EXTREME_REWIND : 0); (dump_opt['X'] ? ZPOOL_EXTREME_REWIND : 0);
@ -4285,8 +4431,7 @@ main(int argc, char **argv)
} }
} }
} else { } else {
error = dmu_objset_own(target, DMU_OST_ANY, error = open_objset(target, DMU_OST_ANY, FTAG, &os);
B_TRUE, FTAG, &os);
} }
} }
nvlist_free(policy); nvlist_free(policy);
@ -4329,10 +4474,12 @@ main(int argc, char **argv)
zdb_read_block(argv[i], spa); zdb_read_block(argv[i], spa);
} }
(os != NULL) ? dmu_objset_disown(os, FTAG) : spa_close(spa, FTAG); if (os != NULL)
close_objset(os, FTAG);
else
spa_close(spa, FTAG);
fuid_table_destroy(); fuid_table_destroy();
sa_loaded = B_FALSE;
dump_debug_buffer(); dump_debug_buffer();

View File

@ -1,4 +1,3 @@
'\" t
.\" .\"
.\" This file and its contents are supplied under the terms of the .\" This file and its contents are supplied under the terms of the
.\" Common Development and Distribution License ("CDDL"), version 1.0. .\" Common Development and Distribution License ("CDDL"), version 1.0.
@ -12,556 +11,378 @@
.\" .\"
.\" Copyright 2012, Richard Lowe. .\" Copyright 2012, Richard Lowe.
.\" Copyright (c) 2012, 2016 by Delphix. All rights reserved. .\" Copyright (c) 2012, 2016 by Delphix. All rights reserved.
.\" Copyright 2016 Nexenta Systems, Inc. .\" Copyright 2017 Nexenta Systems, Inc.
.\" Copyright (c) 2017 Lawrence Livermore National Security, LLC.
.\" Copyright (c) 2017 Intel Corporation.
.\" .\"
.TH "ZDB" "8" "April 9, 2016" "" "" .Dd April 11, 2017
.Dt ZDB 8 SMM
.SH "NAME" .Os Linux
\fBzdb\fR - Display zpool debugging and consistency information .Sh NAME
.Nm zdb
.SH "SYNOPSIS" .Nd display zpool debugging and consistency information
\fBzdb\fR [-CumdibcsDvhLMXFPAG] [-e [-p \fIpath\fR...]] [-t \fItxg\fR] .Sh SYNOPSIS
[-U \fIcache\fR] [-I \fIinflight I/Os\fR] [-x \fIdumpdir\fR] .Nm
[-o \fIvar\fR=\fIvalue\fR] ... [\fIpoolname\fR [\fIobject\fR ...]] .Op Fl AbcdDFGhiLMPsvVX
.Op Fl e Op Fl p Ar path ...
.P .Op Fl I Ar inflight I/Os
\fBzdb\fR [-divPA] [-e [-p \fIpath\fR...]] [-U \fIcache\fR] .Oo Fl o Ar var Ns = Ns Ar value Oc Ns ...
\fIdataset\fR [\fIobject\fR ...] .Op Fl t Ar txg
.Op Fl U Ar cache
.P .Op Fl x Ar dumpdir
\fBzdb\fR -m [-MLXFPA] [-t \fItxg\fR] [-e [-p \fIpath\fR...]] [-U \fIcache\fR] .Op Ar poolname Op Ar object ...
\fIpoolname\fR [\fIvdev\fR [\fImetaslab\fR ...]] .Nm
.Op Fl AdiPv
.P .Op Fl e Op Fl p Ar path ...
\fBzdb\fR -R [-A] [-e [-p \fIpath\fR...]] [-U \fIcache\fR] \fIpoolname\fR .Op Fl U Ar cache
\fIvdev\fR:\fIoffset\fR:\fIsize\fR[:\fIflags\fR] .Ar dataset Op Ar object ...
.Nm
.P .Fl C
\fBzdb\fR -S [-AP] [-e [-p \fIpath\fR...]] [-U \fIcache\fR] \fIpoolname\fR .Op Fl A
.Op Fl U Ar cache
.P .Nm
\fBzdb\fR -l [-Aqu] \fIdevice\fR .Fl l
.Op Fl Aqu
.P .Ar device
\fBzdb\fR -C [-A] [-U \fIcache\fR] .Nm
.Fl m
.SH "DESCRIPTION" .Op Fl AFLPVX
The \fBzdb\fR utility displays information about a ZFS pool useful for .Op Fl t Ar txg
debugging and performs some amount of consistency checking. It is a not a .Op Fl e Op Fl p Ar path ...
general purpose tool and options (and facilities) may change. This is neither .Op Fl U Ar cache
a fsck(8) nor an fsdb(8) utility. .Ar poolname Op Ar vdev Op Ar metaslab ...
.Nm
.P .Fl O
.Ar dataset path
.Nm
.Fl R
.Op Fl A
.Op Fl e Op Fl p Ar path ...
.Op Fl U Ar cache
.Ar poolname vdev Ns : Ns Ar offset Ns : Ns Ar size Ns Op : Ns Ar flags
.Nm
.Fl S
.Op Fl AP
.Op Fl e Op Fl p Ar path ...
.Op Fl U Ar cache
.Ar poolname
.Sh DESCRIPTION
The
.Nm
utility displays information about a ZFS pool useful for debugging and performs
some amount of consistency checking.
It is a not a general purpose tool and options
.Pq and facilities
may change.
This is neither a
.Xr fsck 1M
nor an
.Xr fsdb 1M
utility.
.Pp
The output of this command in general reflects the on-disk structure of a ZFS The output of this command in general reflects the on-disk structure of a ZFS
pool, and is inherently unstable. The precise output of most invocations is pool, and is inherently unstable.
not documented, a knowledge of ZFS internals is assumed. The precise output of most invocations is not documented, a knowledge of ZFS
internals is assumed.
.P .Pp
If the \fIdataset\fR argument does not contain any \fB/\fR or \fB@\fR If the
characters, it is interpreted as a pool name. The root dataset can be .Ar dataset
specified as \fIpool\fB/\fR (pool name followed by a slash). argument does not contain any
.Qq Sy /
.P or
.Qq Sy @
characters, it is interpreted as a pool name.
The root dataset can be specified as
.Ar pool Ns /
.Pq pool name followed by a slash .
.Pp
When operating on an imported and active pool it is possible, though unlikely, When operating on an imported and active pool it is possible, though unlikely,
that zdb may interpret inconsistent pool data and behave erratically. that zdb may interpret inconsistent pool data and behave erratically.
.Sh OPTIONS
.SH "OPTIONS"
Display options: Display options:
.Bl -tag -width Ds
.sp .It Fl b
.ne 2 Display statistics regarding the number, size
.na .Pq logical, physical and allocated
\fB-b\fR and deduplication of blocks.
.ad .It Fl c
.sp .6
.RS 4n
Display statistics regarding the number, size (logical, physical and
allocated) and deduplication of blocks.
.RE
.sp
.ne 2
.na
\fB-c\fR
.ad
.sp .6
.RS 4n
Verify the checksum of all metadata blocks while printing block statistics Verify the checksum of all metadata blocks while printing block statistics
(see \fB-b\fR). .Po see
.sp .Fl b
.Pc .
.Pp
If specified multiple times, verify the checksums of all blocks. If specified multiple times, verify the checksums of all blocks.
.RE .It Fl C
Display information about the configuration.
.sp If specified with no other options, instead display information about the cache
.ne 2 file
.na .Pq Pa /etc/zfs/zpool.cache .
\fB-C\fR To specify the cache file to display, see
.ad .Fl U .
.sp .6 .Pp
.RS 4n If specified multiple times, and a pool name is also specified display both the
Display information about the configuration. If specified with no other cached configuration and the on-disk configuration.
options, instead display information about the cache file If specified multiple times with
(\fB/etc/zfs/zpool.cache\fR). To specify the cache file to display, see .Fl e
\fB-U\fR. also display the configuration that would be used were the pool to be imported.
.P .It Fl d
If specified multiple times, and a pool name is also specified display both Display information about datasets.
the cached configuration and the on-disk configuration. If specified multiple Specified once, displays basic dataset information: ID, create transaction,
times with \fB-e\fR also display the configuration that would be used were the size, and object count.
pool to be imported. .Pp
.RE
.sp
.ne 2
.na
\fB-d\fR
.ad
.sp .6
.RS 4n
Display information about datasets. Specified once, displays basic dataset
information: ID, create transaction, size, and object count.
.sp
If specified multiple times provides greater and greater verbosity. If specified multiple times provides greater and greater verbosity.
.sp .Pp
If object IDs are specified, display information about those specific objects only. If object IDs are specified, display information about those specific objects
.RE only.
.It Fl D
.sp Display deduplication statistics, including the deduplication ratio
.ne 2 .Pq Sy dedup ,
.na compression ratio
\fB-D\fR .Pq Sy compress ,
.ad inflation due to the zfs copies property
.sp .6 .Pq Sy copies ,
.RS 4n and an overall effective ratio
Display deduplication statistics, including the deduplication ratio (dedup), .Pq Sy dedup No * Sy compress No / Sy copies .
compression ratio (compress), inflation due to the zfs copies property .It Fl DD
(copies), and an overall effective ratio (dedup * compress / copies). Display a histogram of deduplication statistics, showing the allocated
.sp .Pq physically present on disk
If specified twice, display a histogram of deduplication statistics, showing and referenced
the allocated (physically present on disk) and referenced (logically .Pq logically referenced in the pool
referenced in the pool) block counts and sizes by reference count. block counts and sizes by reference count.
.sp .It Fl DDD
If specified a third time, display the statistics independently for each deduplication table. Display the statistics independently for each deduplication table.
.sp .It Fl DDDD
If specified a fourth time, dump the contents of the deduplication tables describing duplicate blocks. Dump the contents of the deduplication tables describing duplicate blocks.
.sp .It Fl DDDDD
If specified a fifth time, also dump the contents of the deduplication tables describing unique blocks. Also dump the contents of the deduplication tables describing unique blocks.
.RE .It Fl h
Display pool history similar to
.sp .Nm zpool Cm history ,
.ne 2 but include internal changes, transaction, and dataset information.
.na .It Fl i
\fB-h\fR Display information about intent log
.ad .Pq ZIL
.sp .6 entries relating to each dataset.
.RS 4n If specified multiple times, display counts of each intent log transaction type.
Display pool history similar to \fBzpool history\fR, but include internal .It Fl l Ar device
changes, transaction, and dataset information. Read the vdev labels from the specified device.
.RE .Nm Fl l
will return 0 if valid label was found, 1 if error occurred, and 2 if no valid
.sp labels were found. Each unique configuration is displayed only once.
.ne 2 .It Fl ll Ar device
.na In addition display label space usage stats.
\fB-i\fR .It Fl lll Ar device
.ad Display every configuration, unique or not.
.sp .6 .Pp
.RS 4n If the
Display information about intent log (ZIL) entries relating to each .Fl q
dataset. If specified multiple times, display counts of each intent log option is also specified, don't print the labels.
transaction type. .Pp
.RE If the
.Fl u
.sp option is also specified, also display the uberblocks on this device. Specify
.ne 2 multiple times to increase verbosity.
.na .It Fl L
\fB-l\fR \fIdevice\fR Disable leak tracing and the loading of space maps.
.ad By default,
.sp .6 .Nm
.RS 4n
Read the vdev labels from the specified device and dump the unique
configuration nvlist(s). \fBzdb -l\fR will return 1 if an error occured, 2 if
no configuration nvlist could be unpacked (errors or not), and 0 otherwise.
Specify multiple times to increase verbosity.
.P
If the \fB-u\fR option is also specified, also display the uberblocks on this
device. Specify multiple times to increase verbosity.
.P
If the \fB-q\fR option is also specified, don't dump the configurations or the
uberblocks.
.RE
.sp
.ne 2
.na
\fB-L\fR
.ad
.sp .6
.RS 4n
Disable leak tracing and the loading of space maps. By default, \fBzdb\fR
verifies that all non-free blocks are referenced, which can be very expensive. verifies that all non-free blocks are referenced, which can be very expensive.
.RE .It Fl m
.sp
.ne 2
.na
\fB-m\fR
.ad
.sp .6
.RS 4n
Display the offset, spacemap, and free space of each metaslab. Display the offset, spacemap, and free space of each metaslab.
When specified twice, also display information about the on-disk free .It Fl mm
space histogram associated with each metaslab. When specified three time, Also display information about the on-disk free space histogram associated with
display the maximum contiguous free space, the in-core free space histogram, each metaslab.
and the percentage of free space in each space map. When specified .It Fl mmm
four times display every spacemap record. Display the maximum contiguous free space, the in-core free space histogram, and
.RE the percentage of free space in each space map.
.It Fl mmmm
.sp Display every spacemap record.
.ne 2 .It Fl M
.na
\fB-M\fR
.ad
.sp .6
.RS 4n
Display the offset, spacemap, and free space of each metaslab. Display the offset, spacemap, and free space of each metaslab.
When specified twice, also display information about the maximum contiguous .It Fl MM
free space and the percentage of free space in each space map. When specified Also display information about the maximum contiguous free space and the
three times display every spacemap record. percentage of free space in each space map.
.RE .It Fl MMM
Display every spacemap record.
.sp .It Fl O Ar dataset path
.ne 2 Look up the specified
.na .Ar path
\fB-R\fR \fIpoolname\fR \fIvdev\fR:\fIoffset\fR:\fIsize\fR[:\fIflags\fR] inside of the
.ad .Ar dataset
.sp .6 and display its metadata and indirect blocks.
.RS 4n Specified
Read and display a block from the specified device. By default the block is .Ar path
displayed as a hex dump, but see the description of the \'r\' flag, below. must be relative to the root of
.sp .Ar dataset .
The block is specified in terms of a colon-separated tuple \fIvdev\fR (an This option can be combined with
integer vdev identifier) \fIoffset\fR (the offset within the vdev) \fIsize\fR .Fl v
(the size of the block to read) and, optionally, \fIflags\fR (a set of flags, for increasing verbosity.
described below). .It Fl R Ar poolname vdev Ns : Ns Ar offset Ns : Ns Ar size Ns Op : Ns Ar flags
Read and display a block from the specified device.
.sp By default the block is displayed as a hex dump, but see the description of the
.ne 2 .Sy r
.na flag, below.
\fBb\fR \fIoffset\fR .Pp
.ad The block is specified in terms of a colon-separated tuple
.sp .6 .Ar vdev
.RS 4n .Pq an integer vdev identifier
.Ar offset
.Pq the offset within the vdev
.Ar size
.Pq the size of the block to read
and, optionally,
.Ar flags
.Pq a set of flags, described below .
.Pp
.Bl -tag -compact -width "b offset"
.It Sy b Ar offset
Print block pointer Print block pointer
.RE .It Sy d
.sp
.ne 2
.na
\fBd\fR
.ad
.sp .6
.RS 4n
Decompress the block Decompress the block
.RE .It Sy e
.sp
.ne 2
.na
\fBe\fR
.ad
.sp .6
.RS 4n
Byte swap the block Byte swap the block
.RE .It Sy g
.sp
.ne 2
.na
\fBg\fR
.ad
.sp .6
.RS 4n
Dump gang block header Dump gang block header
.RE .It Sy i
.sp
.ne 2
.na
\fBi\fR
.ad
.sp .6
.RS 4n
Dump indirect block Dump indirect block
.RE .It Sy r
.sp
.ne 2
.na
\fBr\fR
.ad
.sp .6
.RS 4n
Dump raw uninterpreted block data Dump raw uninterpreted block data
.RE .El
.RE .It Fl s
Report statistics on
.sp .Nm zdb
.ne 2 I/O.
.na Display operation counts, bandwidth, and error counts of I/O to the pool from
\fB-s\fR .Nm .
.ad .It Fl S
.sp .6
.RS 4n
Report statistics on \fBzdb\fR\'s I/O. Display operation counts, bandwidth,
and error counts of I/O to the pool from \fBzdb\fR.
.RE
.sp
.ne 2
.na
\fB-S\fR
.ad
.sp .6
.RS 4n
Simulate the effects of deduplication, constructing a DDT and then display Simulate the effects of deduplication, constructing a DDT and then display
that DDT as with \fB-DD\fR. that DDT as with
.RE .Fl DD .
.It Fl u
.sp
.ne 2
.na
\fB-u\fR
.ad
.sp .6
.RS 4n
Display the current uberblock. Display the current uberblock.
.RE .El
.Pp
.P
Other options: Other options:
.Bl -tag -width Ds
.sp .It Fl A
.ne 2
.na
\fB-A\fR
.ad
.sp .6
.RS 4n
Do not abort should any assertion fail. Do not abort should any assertion fail.
.RE .It Fl AA
.sp
.ne 2
.na
\fB-AA\fR
.ad
.sp .6
.RS 4n
Enable panic recovery, certain errors which would otherwise be fatal are Enable panic recovery, certain errors which would otherwise be fatal are
demoted to warnings. demoted to warnings.
.RE .It Fl AAA
.sp
.ne 2
.na
\fB-AAA\fR
.ad
.sp .6
.RS 4n
Do not abort if asserts fail and also enable panic recovery. Do not abort if asserts fail and also enable panic recovery.
.RE .It Fl e Op Fl p Ar path ...
Operate on an exported pool, not present in
.sp .Pa /etc/zfs/zpool.cache .
.ne 2 The
.na .Fl p
\fB-e\fR [-p \fIpath\fR]... flag specifies the path under which devices are to be searched.
.ad .It Fl x Ar dumpdir
.sp .6
.RS 4n
Operate on an exported pool, not present in \fB/etc/zfs/zpool.cache\fR. The
\fB-p\fR flag specifies the path under which devices are to be searched.
.RE
.sp
.ne 2
.na
\fB-x\fR \fIdumpdir\fR
.ad
.sp .6
.RS 4n
All blocks accessed will be copied to files in the specified directory. All blocks accessed will be copied to files in the specified directory.
The blocks will be placed in sparse files whose name is the same as The blocks will be placed in sparse files whose name is the same as
that of the file or device read. zdb can be then run on the generated files. that of the file or device read.
Note that the \fB-bbc\fR flags are sufficient to access (and thus copy) .Nm
can be then run on the generated files.
Note that the
.Fl bbc
flags are sufficient to access
.Pq and thus copy
all metadata on the pool. all metadata on the pool.
.RE .It Fl F
.sp
.ne 2
.na
\fB-F\fR
.ad
.sp .6
.RS 4n
Attempt to make an unreadable pool readable by trying progressively older Attempt to make an unreadable pool readable by trying progressively older
transactions. transactions.
.RE .It Fl G
Dump the contents of the zfs_dbgmsg buffer before exiting
.sp .Nm .
.ne 2 zfs_dbgmsg is a buffer used by ZFS to dump advanced debug information.
.na .It Fl I Ar inflight I/Os
\fB-G\fR Limit the number of outstanding checksum I/Os to the specified value.
.ad The default value is 200.
.sp .6 This option affects the performance of the
.RS 4n .Fl c
Dump the contents of the zfs_dbgmsg buffer before exiting zdb. zfs_dbgmsg is
a buffer used by ZFS to dump advanced debug information.
.RE
.sp
.ne 2
.na
\fB-I \fIinflight I/Os\fR \fR
.ad
.sp .6
.RS 4n
Limit the number of outstanding checksum I/Os to the specified value. The
default value is 200. This option affects the performance of the \fB-c\fR
option. option.
.RE .It Fl o Ar var Ns = Ns Ar value ...
Set the given global libzpool variable to the provided value.
.sp The value must be an unsigned 32-bit integer.
.ne 2 Currently only little-endian systems are supported to avoid accidentally setting
.na the high 32 bits of 64-bit variables.
\fB-o \fIvar\fR=\fIvalue\fR ... \fR .It Fl P
.ad
.sp .6
.RS 4n
Set the given global libzpool variable to the provided value. The value must
be an unsigned 32-bit integer. Currently only little-endian systems are
supported to avoid accidentally setting the high 32 bits of 64-bit variables.
.RE
.sp
.ne 2
.na
\fB-P\fR
.ad
.sp .6
.RS 4n
Print numbers in an unscaled form more amenable to parsing, eg. 1000000 rather Print numbers in an unscaled form more amenable to parsing, eg. 1000000 rather
than 1M. than 1M.
.RE .It Fl t Ar transaction
Specify the highest transaction to use when searching for uberblocks.
.sp See also the
.ne 2 .Fl u
.na and
\fB-t\fR \fItransaction\fR .Fl l
.ad options for a means to see the available uberblocks and their associated
.sp .6 transaction numbers.
.RS 4n .It Fl U Ar cachefile
Specify the highest transaction to use when searching for uberblocks. See also Use a cache file other than
the \fB-u\fR and \fB-l\fR options for a means to see the available uberblocks .Pa /etc/zfs/zpool.cache .
and their associated transaction numbers. .It Fl v
.RE Enable verbosity.
Specify multiple times for increased verbosity.
.sp .It Fl V
.ne 2 Attempt a verbatim import. This mimics the behavior of the kernel when
.na loading a pool from a cachefile.
\fB-U\fR \fIcachefile\fR .It Fl X
.ad Attempt
.sp .6 .Qq extreme
.RS 4n transaction rewind, that is attempt the same recovery as
Use a cache file other than \fB/etc/zfs/zpool.cache\fR. .Fl F
.RE but read transactions otherwise deemed too old.
.El
.sp .Pp
.ne 2
.na
\fB-v\fR
.ad
.sp .6
.RS 4n
Enable verbosity. Specify multiple times for increased verbosity.
.RE
.sp
.ne 2
.na
\fB-X\fR
.ad
.sp .6
.RS 4n
Attempt \'extreme\' transaction rewind, that is attempt the same recovery as
\fB-F\fR but read transactions otherwise deemed too old.
.RE
.sp
.ne 2
.na
\fB-V\fR
.ad
.sp .6
.RS 4n
Attempt a verbatim import. This mimics the behavior of the kernel when loading
a pool from a cachefile.
.RE
.P
Specifying a display option more than once enables verbosity for only that Specifying a display option more than once enables verbosity for only that
option, with more occurrences enabling more verbosity. option, with more occurrences enabling more verbosity.
.P .Pp
If no options are specified, all information about the named pool will be If no options are specified, all information about the named pool will be
displayed at default verbosity. displayed at default verbosity.
.Sh EXAMPLES
.SH "EXAMPLES" .Bl -tag -width Ds
.LP .It Xo
\fBExample 1 \fRDisplay the configuration of imported pool 'rpool' .Sy Example 1
.sp Display the configuration of imported pool
.in +2 .Pa rpool
.nf .Xc
.Bd -literal
# zdb -C rpool # zdb -C rpool
MOS Configuration: MOS Configuration:
version: 28 version: 28
name: 'rpool' name: 'rpool'
... ...
.fi .Ed
.in -2 .It Xo
.sp .Sy Example 2
Display basic dataset information about
.LP .Pa rpool
\fBExample 2 \fRDisplay basic dataset information about 'rpool' .Xc
.sp .Bd -literal
.in +2
.nf
# zdb -d rpool # zdb -d rpool
Dataset mos [META], ID 0, cr_txg 4, 26.9M, 1051 objects Dataset mos [META], ID 0, cr_txg 4, 26.9M, 1051 objects
Dataset rpool/swap [ZVOL], ID 59, cr_txg 356, 486M, 2 objects Dataset rpool/swap [ZVOL], ID 59, cr_txg 356, 486M, 2 objects
... ...
.fi .Ed
.in -2 .It Xo
.sp .Sy Example 3
Display basic information about object 0 in
.LP .Pa rpool/export/home
\fBExample 3 \fRDisplay basic information about object 0 .Xc
in 'rpool/export/home' .Bd -literal
.sp
.in +2
.nf
# zdb -d rpool/export/home 0 # zdb -d rpool/export/home 0
Dataset rpool/export/home [ZPL], ID 137, cr_txg 1546, 32K, 8 objects Dataset rpool/export/home [ZPL], ID 137, cr_txg 1546, 32K, 8 objects
Object lvl iblk dblk dsize lsize %full type Object lvl iblk dblk dsize lsize %full type
0 7 16K 16K 15.0K 16K 25.00 DMU dnode 0 7 16K 16K 15.0K 16K 25.00 DMU dnode
.fi .Ed
.in -2 .It Xo
.sp .Sy Example 4
Display the predicted effect of enabling deduplication on
.LP .Pa rpool
\fBExample 4 \fRDisplay the predicted effect of enabling deduplication on 'rpool' .Xc
.sp .Bd -literal
.in +2
.nf
# zdb -S rpool # zdb -S rpool
Simulated DDT histogram: Simulated DDT histogram:
@ -573,14 +394,8 @@ refcnt blocks LSIZE PSIZE DSIZE blocks LSIZE PSIZE DSIZE
2 35.0K 1.33G 699M 699M 74.7K 2.79G 1.45G 1.45G 2 35.0K 1.33G 699M 699M 74.7K 2.79G 1.45G 1.45G
... ...
dedup = 1.11, compress = 1.80, copies = 1.00, dedup * compress / copies = 2.00 dedup = 1.11, compress = 1.80, copies = 1.00, dedup * compress / copies = 2.00
.fi .Ed
.in -2 .El
.sp .Sh SEE ALSO
.Xr zfs 8 ,
.SH "ENVIRONMENT VARIABLES" .Xr zpool 8
.TP
.B "SPA_CONFIG_PATH"
Override the default \fBspa_config_path\fR (\fI/etc/zfs/zpool.cache\fR) setting. If \fB-U\fR flag is specified it will override this environment variable settings once again.
.SH "SEE ALSO"
zfs(8), zpool(8)