Long opts for zdb

This change introduces long options for zdb. It updates the usage
message as well to include the long options.

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Manoj Joseph <manoj.joseph@delphix.com>
Closes #12818
This commit is contained in:
Manoj Joseph 2022-01-06 10:54:32 -08:00 committed by GitHub
parent 2a149775b4
commit 6b2e32019e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 157 additions and 92 deletions

View File

@ -39,6 +39,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <getopt.h>
#include <sys/zfs_context.h> #include <sys/zfs_context.h>
#include <sys/spa.h> #include <sys/spa.h>
#include <sys/spa_impl.h> #include <sys/spa_impl.h>
@ -820,65 +821,87 @@ usage(void)
" z ZAPs\n" " z ZAPs\n"
" - Negate effect of next flag\n\n"); " - Negate effect of next flag\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, " -b block statistics\n"); (void) fprintf(stderr, " -b --block-stats "
(void) fprintf(stderr, " -c checksum all metadata (twice for " "block statistics\n");
"all data) blocks\n"); (void) fprintf(stderr, " -c --checksum "
(void) fprintf(stderr, " -C config (or cachefile if alone)\n"); "checksum all metadata (twice for all data) blocks\n");
(void) fprintf(stderr, " -d dataset(s)\n"); (void) fprintf(stderr, " -C --config "
(void) fprintf(stderr, " -D dedup statistics\n"); "config (or cachefile if alone)\n");
(void) fprintf(stderr, " -E decode and display block from an " (void) fprintf(stderr, " -d --datasets "
"embedded block pointer\n"); "dataset(s)\n");
(void) fprintf(stderr, " -h pool history\n"); (void) fprintf(stderr, " -D --dedup-stats "
(void) fprintf(stderr, " -i intent logs\n"); "dedup statistics\n");
(void) fprintf(stderr, " -l read label contents\n"); (void) fprintf(stderr, " -E --embedded-block-pointer=INTEGER\n"
(void) fprintf(stderr, " -k examine the checkpointed state " " decode and display block "
"of the pool\n"); "from an embedded block pointer\n");
(void) fprintf(stderr, " -L disable leak tracking (do not " (void) fprintf(stderr, " -h --history "
"load spacemaps)\n"); "pool history\n");
(void) fprintf(stderr, " -m metaslabs\n"); (void) fprintf(stderr, " -i --intent-logs "
(void) fprintf(stderr, " -M metaslab groups\n"); "intent logs\n");
(void) fprintf(stderr, " -O perform object lookups by path\n"); (void) fprintf(stderr, " -l --label "
(void) fprintf(stderr, " -r copy an object by path to file\n"); "read label contents\n");
(void) fprintf(stderr, " -R read and display block from a " (void) fprintf(stderr, " -k --checkpointed-state "
"device\n"); "examine the checkpointed state of the pool\n");
(void) fprintf(stderr, " -s report stats on zdb's I/O\n"); (void) fprintf(stderr, " -L --disable-leak-tracking "
(void) fprintf(stderr, " -S simulate dedup to measure effect\n"); "disable leak tracking (do not load spacemaps)\n");
(void) fprintf(stderr, " -v verbose (applies to all " (void) fprintf(stderr, " -m --metaslabs "
"others)\n"); "metaslabs\n");
(void) fprintf(stderr, " -y perform livelist and metaslab " (void) fprintf(stderr, " -M --metaslab-groups "
"validation on any livelists being deleted\n\n"); "metaslab groups\n");
(void) fprintf(stderr, " -O --object-lookups "
"perform object lookups by path\n");
(void) fprintf(stderr, " -r --copy-object "
"copy an object by path to file\n");
(void) fprintf(stderr, " -R --read-block "
"read and display block from a device\n");
(void) fprintf(stderr, " -s --io-stats "
"report stats on zdb's I/O\n");
(void) fprintf(stderr, " -S --simulate-dedup "
"simulate dedup to measure effect\n");
(void) fprintf(stderr, " -v --verbose "
"verbose (applies to all others)\n");
(void) fprintf(stderr, " -y --livelist "
"perform livelist and metaslab validation on any livelists being "
"deleted\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 "
"panic recovery (-AA) or both (-AAA)\n"); "ignore assertions (-A), enable panic recovery (-AA) or both "
(void) fprintf(stderr, " -e pool is exported/destroyed/" "(-AAA)\n");
"has altroot/not in a cachefile\n"); (void) fprintf(stderr, " -e --exported "
(void) fprintf(stderr, " -F attempt automatic rewind within " "pool is exported/destroyed/has altroot/not in a cachefile\n");
"safe range of transaction groups\n"); (void) fprintf(stderr, " -F --automatic-rewind "
(void) fprintf(stderr, " -G dump zfs_dbgmsg buffer before " "attempt automatic rewind within safe range of transaction "
"exiting\n"); "groups\n");
(void) fprintf(stderr, " -I <number of inflight I/Os> -- " (void) fprintf(stderr, " -G --dump-debug-msg "
"specify the maximum number of\n " "dump zfs_dbgmsg buffer before exiting\n");
"checksumming I/Os [default is 200]\n"); (void) fprintf(stderr, " -I --inflight=INTEGER "
(void) fprintf(stderr, " -o <variable>=<value> set global " "specify the maximum number of checksumming I/Os "
"variable to an unsigned 32-bit integer\n"); "[default is 200]\n");
(void) fprintf(stderr, " -p <path> -- use one or more with " (void) fprintf(stderr, " -o --option=\"OPTION=INTEGER\" "
"-e to specify path to vdev dir\n"); "set global variable to an unsigned 32-bit integer\n");
(void) fprintf(stderr, " -P print numbers in parseable form\n"); (void) fprintf(stderr, " -p --path==PATH "
(void) fprintf(stderr, " -q don't print label contents\n"); "use one or more with -e to specify path to vdev dir\n");
(void) fprintf(stderr, " -t <txg> -- highest txg to use when " (void) fprintf(stderr, " -P --parseable "
"searching for uberblocks\n"); "print numbers in parseable form\n");
(void) fprintf(stderr, " -u uberblock\n"); (void) fprintf(stderr, " -q --skip-label "
(void) fprintf(stderr, " -U <cachefile_path> -- use alternate " "don't print label contents\n");
"cachefile\n"); (void) fprintf(stderr, " -t --txg=INTEGER "
(void) fprintf(stderr, " -V do verbatim import\n"); "highest txg to use when searching for uberblocks\n");
(void) fprintf(stderr, " -x <dumpdir> -- " (void) fprintf(stderr, " -u --uberblock "
"uberblock\n");
(void) fprintf(stderr, " -U --cachefile=PATH "
"use alternate cachefile\n");
(void) fprintf(stderr, " -V --verbatim "
"do verbatim import\n");
(void) fprintf(stderr, " -x --dump-blocks=PATH "
"dump all read blocks into specified directory\n"); "dump all read blocks into specified directory\n");
(void) fprintf(stderr, " -X attempt extreme rewind (does not " (void) fprintf(stderr, " -X --extreme-rewind "
"work with dataset)\n"); "attempt extreme rewind (does not work with dataset)\n");
(void) fprintf(stderr, " -Y attempt all reconstruction " (void) fprintf(stderr, " -Y --all-reconstruction "
"combinations for split blocks\n"); "attempt all reconstruction combinations for split blocks\n");
(void) fprintf(stderr, " -Z show ZSTD headers \n"); (void) fprintf(stderr, " -Z --zstd-headers "
"show ZSTD headers \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");
@ -8410,8 +8433,50 @@ main(int argc, char **argv)
*/ */
zfs_btree_verify_intensity = 3; zfs_btree_verify_intensity = 3;
while ((c = getopt(argc, argv, struct option long_options[] = {
"AbcCdDeEFGhiI:klLmMo:Op:PqrRsSt:uU:vVx:XYyZ")) != -1) { {"ignore-assertions", no_argument, NULL, 'A'},
{"block-stats", no_argument, NULL, 'b'},
{"checksum", no_argument, NULL, 'c'},
{"config", no_argument, NULL, 'C'},
{"datasets", no_argument, NULL, 'd'},
{"dedup-stats", no_argument, NULL, 'D'},
{"exported", no_argument, NULL, 'e'},
{"embedded-block-pointer", no_argument, NULL, 'E'},
{"automatic-rewind", no_argument, NULL, 'F'},
{"dump-debug-msg", no_argument, NULL, 'G'},
{"history", no_argument, NULL, 'h'},
{"intent-logs", no_argument, NULL, 'i'},
{"inflight", required_argument, NULL, 'I'},
{"checkpointed-state", no_argument, NULL, 'k'},
{"label", no_argument, NULL, 'l'},
{"disable-leak-tracking", no_argument, NULL, 'L'},
{"metaslabs", no_argument, NULL, 'm'},
{"metaslab-groups", no_argument, NULL, 'M'},
{"option", required_argument, NULL, 'o'},
{"object-lookups", no_argument, NULL, 'O'},
{"path", required_argument, NULL, 'p'},
{"parseable", no_argument, NULL, 'P'},
{"skip-label", no_argument, NULL, 'q'},
{"copy-object", no_argument, NULL, 'r'},
{"read-block", no_argument, NULL, 'R'},
{"io-stats", no_argument, NULL, 's'},
{"simulate-dedup", no_argument, NULL, 'S'},
{"txg", required_argument, NULL, 't'},
{"uberblock", no_argument, NULL, 'u'},
{"cachefile", required_argument, NULL, 'U'},
{"verbose", no_argument, NULL, 'v'},
{"verbatim", no_argument, NULL, 'V'},
{"dump-blocks", required_argument, NULL, 'x'},
{"extreme-rewind", no_argument, NULL, 'X'},
{"all-reconstruction", no_argument, NULL, 'Y'},
{"livelist", no_argument, NULL, 'y'},
{"zstd-headers", no_argument, NULL, 'Z'},
{0, 0, 0, 0}
};
while ((c = getopt_long(argc, argv,
"AbcCdDeEFGhiI:klLmMo:Op:PqrRsSt:uU:vVx:XYyZ",
long_options, NULL)) != -1) {
switch (c) { switch (c) {
case 'b': case 'b':
case 'c': case 'c':

View File

@ -109,18 +109,18 @@ that zdb may interpret inconsistent pool data and behave erratically.
.Sh OPTIONS .Sh OPTIONS
Display options: Display options:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl b .It Fl b , -block-stats
Display statistics regarding the number, size Display statistics regarding the number, size
.Pq logical, physical and allocated .Pq logical, physical and allocated
and deduplication of blocks. and deduplication of blocks.
.It Fl c .It Fl c , -checksum
Verify the checksum of all metadata blocks while printing block statistics Verify the checksum of all metadata blocks while printing block statistics
.Po see .Po see
.Fl b .Fl b
.Pc . .Pc .
.Pp .Pp
If specified multiple times, verify the checksums of all blocks. If specified multiple times, verify the checksums of all blocks.
.It Fl C .It Fl C , -config
Display information about the configuration. Display information about the configuration.
If specified with no other options, instead display information about the cache If specified with no other options, instead display information about the cache
file file
@ -133,7 +133,7 @@ cached configuration and the on-disk configuration.
If specified multiple times with If specified multiple times with
.Fl e .Fl e
also display the configuration that would be used were the pool to be imported. also display the configuration that would be used were the pool to be imported.
.It Fl d .It Fl d , -datasets
Display information about datasets. Display information about datasets.
Specified once, displays basic dataset information: ID, create transaction, Specified once, displays basic dataset information: ID, create transaction,
size, and object count. size, and object count.
@ -182,7 +182,7 @@ Dump ZAP objects
.It Sy - .It Sy -
Negate the effect of next flag Negate the effect of next flag
.El .El
.It Fl D .It Fl D , -dedup-stats
Display deduplication statistics, including the deduplication ratio Display deduplication statistics, including the deduplication ratio
.Pq Sy dedup , .Pq Sy dedup ,
compression ratio compression ratio
@ -203,23 +203,23 @@ Display the statistics independently for each deduplication table.
Dump the contents of the deduplication tables describing duplicate blocks. Dump the contents of the deduplication tables describing duplicate blocks.
.It Fl DDDDD .It Fl DDDDD
Also dump the contents of the deduplication tables describing unique blocks. Also dump the contents of the deduplication tables describing unique blocks.
.It Fl E Ar word0 : Ns Ar word1 Ns :…: Ns Ar word15 .It Fl E , -embedded-block-pointer Ns = Ns Ar word0 : Ns Ar word1 Ns :…: Ns Ar word15
Decode and display block from an embedded block pointer specified by the Decode and display block from an embedded block pointer specified by the
.Ar word .Ar word
arguments. arguments.
.It Fl h .It Fl h , -history
Display pool history similar to Display pool history similar to
.Nm zpool Cm history , .Nm zpool Cm history ,
but include internal changes, transaction, and dataset information. but include internal changes, transaction, and dataset information.
.It Fl i .It Fl i , -intent-logs
Display information about intent log Display information about intent log
.Pq ZIL .Pq ZIL
entries relating to each dataset. entries relating to each dataset.
If specified multiple times, display counts of each intent log transaction type. If specified multiple times, display counts of each intent log transaction type.
.It Fl k .It Fl k , -checkpointed-state
Examine the checkpointed state of the pool. Examine the checkpointed state of the pool.
Note, the on disk format of the pool is not reverted to the checkpointed state. Note, the on disk format of the pool is not reverted to the checkpointed state.
.It Fl l Ar device .It Fl l , -label Ns = Ns Ar device
Read the vdev labels and L2ARC header from the specified device. Read the vdev labels and L2ARC header from the specified device.
.Nm Fl l .Nm Fl l
will return 0 if valid label was found, 1 if error occurred, and 2 if no valid will return 0 if valid label was found, 1 if error occurred, and 2 if no valid
@ -249,12 +249,12 @@ If the
.Fl u .Fl u
option is also specified, also display the uberblocks on this device. option is also specified, also display the uberblocks on this device.
Specify multiple times to increase verbosity. Specify multiple times to increase verbosity.
.It Fl L .It Fl L , -disable-leak-tracking
Disable leak detection and the loading of space maps. Disable leak detection and the loading of space maps.
By default, By default,
.Nm .Nm
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.
.It Fl m .It Fl m , -metaslabs
Display the offset, spacemap, free space of each metaslab, all the log Display the offset, spacemap, free space of each metaslab, all the log
spacemaps and their obsolete entry statistics. spacemaps and their obsolete entry statistics.
.It Fl mm .It Fl mm
@ -265,12 +265,12 @@ Display the maximum contiguous free space, the in-core free space histogram, and
the percentage of free space in each space map. the percentage of free space in each space map.
.It Fl mmmm .It Fl mmmm
Display every spacemap record. Display every spacemap record.
.It Fl M .It Fl M , -metaslab-groups
Display all "normal" vdev metaslab group information - per-vdev metaslab count, fragmentation, Display all "normal" vdev metaslab group information - per-vdev metaslab count, fragmentation,
and free space histogram, as well as overall pool fragmentation and histogram. and free space histogram, as well as overall pool fragmentation and histogram.
.It Fl MM .It Fl MM
"Special" vdevs are added to -M's normal output. "Special" vdevs are added to -M's normal output.
.It Fl O Ar dataset path .It Fl O , -object-lookups Ns = Ns Ar dataset path
Look up the specified Look up the specified
.Ar path .Ar path
inside of the inside of the
@ -283,7 +283,7 @@ must be relative to the root of
This option can be combined with This option can be combined with
.Fl v .Fl v
for increasing verbosity. for increasing verbosity.
.It Fl r Ar dataset path destination .It Fl r , -copy-object Ns = Ns Ar dataset path destination
Copy the specified Copy the specified
.Ar path .Ar path
inside of the inside of the
@ -297,7 +297,7 @@ This option can be combined with
.Fl v .Fl v
for increasing verbosity. for increasing verbosity.
.It Xo .It Xo
.Fl R Ar poolname vdev : Ns Ar offset : Ns Oo Ar lsize Ns / Oc Ns Ar psize Ns Op : Ns Ar flags .Fl R , -read-block Ns = Ns Ar poolname vdev : Ns Ar offset : Ns Oo Ar lsize Ns / Oc Ns Ar psize Ns Op : Ns Ar flags
.Xc .Xc
Read and display a block from the specified device. Read and display a block from the specified device.
By default the block is displayed as a hex dump, but see the description of the By default the block is displayed as a hex dump, but see the description of the
@ -336,36 +336,36 @@ Dump raw uninterpreted block data
.It Sy v .It Sy v
Verbose output for guessing compression algorithm Verbose output for guessing compression algorithm
.El .El
.It Fl s .It Fl s , -io-stats
Report statistics on Report statistics on
.Nm zdb .Nm zdb
I/O. I/O.
Display operation counts, bandwidth, and error counts of I/O to the pool from Display operation counts, bandwidth, and error counts of I/O to the pool from
.Nm . .Nm .
.It Fl S .It Fl S , -simulate-dedup
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 that DDT as with
.Fl DD . .Fl DD .
.It Fl u .It Fl u , -uberblock
Display the current uberblock. Display the current uberblock.
.El .El
.Pp .Pp
Other options: Other options:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl A .It Fl A , -ignore-assertions
Do not abort should any assertion fail. Do not abort should any assertion fail.
.It Fl AA .It Fl AA
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.
.It Fl AAA .It Fl AAA
Do not abort if asserts fail and also enable panic recovery. Do not abort if asserts fail and also enable panic recovery.
.It Fl e Oo Fl p Ar path Oc Ns .It Fl e , -exported Ns = Ns Oo Fl p Ar path Oc Ns
Operate on an exported pool, not present in Operate on an exported pool, not present in
.Pa /etc/zfs/zpool.cache . .Pa /etc/zfs/zpool.cache .
The The
.Fl p .Fl p
flag specifies the path under which devices are to be searched. flag specifies the path under which devices are to be searched.
.It Fl x Ar dumpdir .It Fl x , -dump-blocks Ns = Ns Ar dumpdir
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. that of the file or device read.
@ -376,30 +376,30 @@ Note that the
flags are sufficient to access flags are sufficient to access
.Pq and thus copy .Pq and thus copy
all metadata on the pool. all metadata on the pool.
.It Fl F .It Fl F , -automatic-rewind
Attempt to make an unreadable pool readable by trying progressively older Attempt to make an unreadable pool readable by trying progressively older
transactions. transactions.
.It Fl G .It Fl G , -dump-debug-msg
Dump the contents of the zfs_dbgmsg buffer before exiting Dump the contents of the zfs_dbgmsg buffer before exiting
.Nm . .Nm .
zfs_dbgmsg is a buffer used by ZFS to dump advanced debug information. zfs_dbgmsg is a buffer used by ZFS to dump advanced debug information.
.It Fl I Ar inflight I/Os .It Fl I , -inflight Ns = Ns Ar inflight I/Os
Limit the number of outstanding checksum I/Os to the specified value. Limit the number of outstanding checksum I/Os to the specified value.
The default value is 200. The default value is 200.
This option affects the performance of the This option affects the performance of the
.Fl c .Fl c
option. option.
.It Fl o Ar var Ns = Ns Ar value .It Fl o , -option Ns = Ns Ar var Ns = Ns Ar value
Set the given global libzpool variable to the provided value. Set the given global libzpool variable to the provided value.
The value must be an unsigned 32-bit integer. The value must be an unsigned 32-bit integer.
Currently only little-endian systems are supported to avoid accidentally setting Currently only little-endian systems are supported to avoid accidentally setting
the high 32 bits of 64-bit variables. the high 32 bits of 64-bit variables.
.It Fl P .It Fl P , -parseable
Print numbers in an unscaled form more amenable to parsing, e.g.\& Print numbers in an unscaled form more amenable to parsing, e.g.\&
.Sy 1000000 .Sy 1000000
rather than rather than
.Sy 1M . .Sy 1M .
.It Fl t Ar transaction .It Fl t , -txg Ns = Ns Ar transaction
Specify the highest transaction to use when searching for uberblocks. Specify the highest transaction to use when searching for uberblocks.
See also the See also the
.Fl u .Fl u
@ -407,28 +407,28 @@ and
.Fl l .Fl l
options for a means to see the available uberblocks and their associated options for a means to see the available uberblocks and their associated
transaction numbers. transaction numbers.
.It Fl U Ar cachefile .It Fl U , -cachefile Ns = Ns Ar cachefile
Use a cache file other than Use a cache file other than
.Pa /etc/zfs/zpool.cache . .Pa /etc/zfs/zpool.cache .
.It Fl v .It Fl v , -verbose
Enable verbosity. Enable verbosity.
Specify multiple times for increased verbosity. Specify multiple times for increased verbosity.
.It Fl V .It Fl V , -verbatim
Attempt verbatim import. Attempt verbatim import.
This mimics the behavior of the kernel when loading a pool from a cachefile. This mimics the behavior of the kernel when loading a pool from a cachefile.
Only usable with Only usable with
.Fl e . .Fl e .
.It Fl X .It Fl X , -extreme-rewind
Attempt Attempt
.Qq extreme .Qq extreme
transaction rewind, that is attempt the same recovery as transaction rewind, that is attempt the same recovery as
.Fl F .Fl F
but read transactions otherwise deemed too old. but read transactions otherwise deemed too old.
.It Fl Y .It Fl Y , -all-reconstruction
Attempt all possible combinations when reconstructing indirect split blocks. Attempt all possible combinations when reconstructing indirect split blocks.
This flag disables the individual I/O deadman timer in order to allow as This flag disables the individual I/O deadman timer in order to allow as
much time as required for the attempted reconstruction. much time as required for the attempted reconstruction.
.It Fl y .It Fl y , -livelist
Perform validation for livelists that are being deleted. Perform validation for livelists that are being deleted.
Scans through the livelist and metaslabs, checking for duplicate entries Scans through the livelist and metaslabs, checking for duplicate entries
and compares the two, checking for potential double frees. and compares the two, checking for potential double frees.