From c546eab5f1d0231433c620a42041d6a48ac41045 Mon Sep 17 00:00:00 2001 From: Richard Elling Date: Tue, 14 May 2019 14:23:32 -0700 Subject: [PATCH] Add long options to zdb command. Includes updates to ZTS tests and man page. Signed-off-by: Richard Elling --- cmd/zdb/zdb.c | 249 ++++++++++++------ cmd/zdb/zdb.h | 2 +- cmd/zdb/zdb_il.c | 2 - man/man8/zdb.8 | 76 +++--- tests/runfiles/linux.run | 2 +- tests/test-runner/bin/zts-report.py | 1 - .../tests/functional/cli_root/zdb/Makefile.am | 3 +- .../functional/cli_root/zdb/zdb_001_neg.ksh | 4 +- .../functional/cli_root/zdb/zdb_006_pos.ksh | 29 +- .../cli_root/zdb/zdb_long_options.ksh | 107 ++++++++ 10 files changed, 351 insertions(+), 124 deletions(-) create mode 100755 tests/zfs-tests/tests/functional/cli_root/zdb/zdb_long_options.ksh diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 4b07cdb8e0cb..d0fe412ca61e 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -26,6 +26,7 @@ * Copyright 2016 Nexenta Systems, Inc. * Copyright (c) 2017, 2018 Lawrence Livermore National Security, LLC. * Copyright (c) 2015, 2017, Intel Corporation. + * Copyright 2019 Richard Elling */ #include @@ -33,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -103,7 +105,13 @@ extern boolean_t spa_load_verify_dryrun; extern int zfs_reconstruct_indirect_combinations_max; static const char cmdname[] = "zdb"; -uint8_t dump_opt[256]; + +/* option_values are for long-only options */ +enum option_values { + OPTION_HELP = 256, + NUM_OPTION_VALUES +}; +uint8_t dump_opt[NUM_OPTION_VALUES]; typedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size); @@ -139,88 +147,97 @@ usage(void) (void) fprintf(stderr, "Usage:\t%s [-AbcdDFGhikLMPsvX] [-e [-V] [-p ...]] " "[-I ]\n" - "\t\t[-o =]... [-t ] [-U ] [-x ]\n" + "\t\t[-o =]... [-t ] [-U ] " + "[-x ]\n" "\t\t[ [ ...]]\n" - "\t%s [-AdiPv] [-e [-V] [-p ...]] [-U ] \n" + "\t%s [-AdiPv] [-e [-V] [-p ...]] [-U ] " + "\n" "\t\t[ ...]\n" - "\t%s -C [-A] [-U ]\n" + "\t%s -C [-A] [-U ]\n" "\t%s -l [-Aqu] \n" "\t%s -m [-AFLPX] [-e [-V] [-p ...]] [-t ] " - "[-U ]\n\t\t [ [ ...]]\n" + "[-U ]\n\t\t [ [ ...]]\n" "\t%s -O \n" - "\t%s -R [-A] [-e [-V] [-p ...]] [-U ]\n" + "\t%s -R [-A] [-e [-V] [-p ...]] [-U ]\n" "\t\t ::[:]\n" "\t%s -E [-A] word0:word1:...:word15\n" - "\t%s -S [-AP] [-e [-V] [-p ...]] [-U ] " + "\t%s -S [-AP] [-e [-V] [-p ...]] [-U ] " "\n\n", cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname); - (void) fprintf(stderr, " Dataset name must include at least one " - "separator character '/' or '@'\n"); - (void) fprintf(stderr, " If dataset name is specified, only that " - "dataset is dumped\n"); - (void) fprintf(stderr, " If object numbers are specified, only " - "those objects are dumped\n\n"); - (void) fprintf(stderr, " Options to control amount of output:\n"); - (void) fprintf(stderr, " -b block statistics\n"); - (void) fprintf(stderr, " -c checksum all metadata (twice for " - "all data) blocks\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, " -E decode and display block from an " - "embedded block pointer\n"); - (void) fprintf(stderr, " -h pool history\n"); - (void) fprintf(stderr, " -i intent logs\n"); - (void) fprintf(stderr, " -l read label contents\n"); - (void) fprintf(stderr, " -k examine the checkpointed state " - "of the pool\n"); - (void) fprintf(stderr, " -L disable leak tracking (do not " - "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 " - "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 " - "with other options:\n"); - (void) fprintf(stderr, " -A ignore assertions (-A), enable " - "panic recovery (-AA) or both (-AAA)\n"); - (void) fprintf(stderr, " -e pool is exported/destroyed/" - "has altroot/not in a cachefile\n"); - (void) fprintf(stderr, " -F attempt automatic rewind within " - "safe range of transaction groups\n"); - (void) fprintf(stderr, " -G dump zfs_dbgmsg buffer before " - "exiting\n"); - (void) fprintf(stderr, " -I -- " - "specify the maximum number of\n " - "checksumming I/Os [default is 200]\n"); - (void) fprintf(stderr, " -o = set global " - "variable to an unsigned 32-bit integer\n"); - (void) fprintf(stderr, " -p -- 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, " -t -- highest txg to use when " - "searching for uberblocks\n"); - (void) fprintf(stderr, " -u uberblock\n"); - (void) fprintf(stderr, " -U -- use alternate " - "cachefile\n"); - (void) fprintf(stderr, " -V do verbatim import\n"); - (void) fprintf(stderr, " -x -- " - "dump all read blocks into specified directory\n"); - (void) fprintf(stderr, " -X attempt extreme rewind (does not " - "work with dataset)\n"); - (void) fprintf(stderr, " -Y attempt all reconstruction " - "combinations for split blocks\n"); - (void) fprintf(stderr, "Specify an option more than once (e.g. -bb) " - "to make only that option verbose\n"); - (void) fprintf(stderr, "Default is to dump everything non-verbosely\n"); + (void) fprintf(stderr, + "Dataset name must include at least one " + "separator character '/' or '@'\n" + "If name is specified, only that dataset is dumped.\n" + "If numbers are specified, only " + "those objects are dumped.\n" + "\n"); + + (void) fprintf(stderr, + "Options to control amount of output:\n" + " -b, --block block information\n" + " -c, --checksum checksum all metadata " + "(-cc for all data) blocks\n" + " -C, --config pool configuration " + "(if no pool specified, show cachefile)\n" + " -d, --dataset dataset information\n" + " -D, --dedup dedup statistics\n" + " -E, --embedded-bp decode and display block " + "from an embedded block pointer\n" + " -h, --history pool history\n" + " --help show usage\n" + " -i, --zil ZFS intent logs\n" + " -l, --label show label contents\n" + " -k, --checkpoint examine the checkpointed " + "state of the pool\n" + " -L, --no-leak disable leak tracking " + "(do not load spacemaps)\n" + " -m, --metaslab show metaslabs\n" + " -M, --metaslab-group show metaslab groups\n" + " -O, --object-by-path perform object lookups by path\n" + " -R, --read-block read and display block from a device\n" + " -s, --stats report stats on zdb's I/O\n" + " -S, --simulate-dedup simulate dedup to measure effect\n" + " -v, --verbose verbose (applies to all others)\n" + "\n"); + + (void) fprintf(stderr, + "The following options are used with other options:\n" + " -A, --no-assertions ignore assertions, " + "enable panic recovery (-AA), or both (-AAA)\n" + " -e, --exported pool is exported, " + "destroyed, or has altroot: not in a cachefile\n" + " -F, --rewind attempt automatic rewind " + "within safe range of transaction groups\n" + " -G, --debug-buffer dump zfs_dbgmsg buffer before exiting\n" + " -I, --inflight[=NUMBER] " + "specify the maximum NUMBER of\n" + " " + "inflight checksumming I/Os [default=1000]\n" + " -o, --set=VARIABLE=VALUE set global " + "VARIABLE to unsigned 32-bit integer VALUE\n" + " -p, --path=DIR vdev directory, " + "can use one or more with -e option\n" + " -P, --parseable print numbers in parseable form\n" + " -q, --no-label-contents don't print label contents (quiet)\n" + " -t, --txg=NUMBER highest txg NUMBER to use " + "when searching for uberblocks\n" + " -u, --uberblock show label uberblocks\n" + " -U, --cachefile=FILENAME use alternate cachefile FILENAME\n" + " -V, --verbatim do verbatim import\n" + " -x, --dump-dir=DIR " + "dump all read blocks into specified directory\n" + " -X, --extreme-rewind attempt pool extreme " + "rewind (does not work with dataset)\n" + " -Y, --reconstruct attempt all reconstruction " + "combinations for split blocks\n" + "\n"); + + (void) fprintf(stderr, + "Specify an option more than once (e.g. -bb) " + "to make only that option verbose\n" + "Default is to dump everything non-verbosely\n"); exit(1); } @@ -5859,6 +5876,19 @@ zdb_embedded_block(char *thing) free(buf); } +static void +print_options_debug(int opt) +{ + if (opt == ':') + return; + if (opt < 256) + (void) fprintf(stderr, "%c %d\n", (char)opt, + dump_opt[opt]); + else + (void) fprintf(stderr, "%d %d\n", opt, + dump_opt[opt]); +} + int main(int argc, char **argv) { @@ -5883,6 +5913,48 @@ main(int argc, char **argv) (void) setrlimit(RLIMIT_NOFILE, &rl); (void) enable_extended_FILE_stdio(-1, -1); + static char *short_options = \ + "AbcCdDeEFGhiI:klLmMo:Op:PqRsSt:uU:vVx:XY"; + + struct option long_options[] = { + {"no-assertions", no_argument, NULL, 'A'}, + {"block", no_argument, NULL, 'b'}, + {"checksum", no_argument, NULL, 'c'}, + {"config", no_argument, NULL, 'C'}, + {"dataset", no_argument, NULL, 'd'}, + {"dedup", no_argument, NULL, 'D'}, + {"exported", no_argument, NULL, 'e'}, + {"embedded-bp", no_argument, NULL, 'E'}, + {"rewind", no_argument, NULL, 'F'}, + {"debug-buffer", no_argument, NULL, 'G'}, + {"help", no_argument, NULL, OPTION_HELP}, + {"history", no_argument, NULL, 'h'}, + {"zil", no_argument, NULL, 'i'}, + {"inflight", required_argument, NULL, 'I'}, + {"checkpoint", no_argument, NULL, 'k'}, + {"label", no_argument, NULL, 'l'}, + {"no-leak", no_argument, NULL, 'L'}, + {"metaslab", no_argument, NULL, 'm'}, + {"metaslab-group", no_argument, NULL, 'M'}, + {"set", required_argument, NULL, 'o'}, + {"object-by-path", no_argument, NULL, 'O'}, + {"path", required_argument, NULL, 'p'}, + {"parseable", no_argument, NULL, 'P'}, + {"no-label-contents", no_argument, NULL, 'q'}, + {"read-block", no_argument, NULL, 'R'}, + {"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-dir", required_argument, NULL, 'x'}, + {"extreme-rewind", no_argument, NULL, 'X'}, + {"reconstruct", no_argument, NULL, 'Y'}, + {0, 0, 0, 0} + }; + dprintf_setup(&argc, argv); /* @@ -5894,9 +5966,12 @@ main(int argc, char **argv) if (spa_config_path_env != NULL) spa_config_path = spa_config_path_env; - while ((c = getopt(argc, argv, - "AbcCdDeEFGhiI:klLmMo:Op:PqRsSt:uU:vVx:XY")) != -1) { + while ((c = getopt_long( + argc, argv, short_options, long_options, NULL)) != -1) { switch (c) { + case OPTION_HELP: + usage(); + break; case 'b': case 'c': case 'C': @@ -5933,7 +6008,8 @@ main(int argc, char **argv) break; /* NB: Sort single match options below. */ case 'I': - max_inflight = strtoull(optarg, NULL, 0); + if (optarg != NULL) + max_inflight = strtoull(optarg, NULL, 0); if (max_inflight == 0) { (void) fprintf(stderr, "maximum number " "of inflight I/Os must be greater " @@ -6042,12 +6118,27 @@ main(int argc, char **argv) argc -= optind; argv += optind; - if (argc < 2 && dump_opt['R']) + if (getenv("ZFS_OPTIONS_DEBUG") != NULL) { + (void) fprintf(stderr, "options parsed\n"); + for (char *s = short_options; *s != '\0'; s++) { + print_options_debug((int)*s); + } + for (int i = OPTION_HELP; i < NUM_OPTION_VALUES; i++) + print_options_debug(i); + (void) fprintf(stderr, "argc %d\n", argc); + exit(0); + } + + if (argc < 2 && dump_opt['R']) { + (void) fprintf(stderr, "missing block specification\n"); usage(); + } if (dump_opt['E']) { - if (argc != 1) + if (argc != 1) { + (void) fprintf(stderr, "missing block pointer\n"); usage(); + } zdb_embedded_block(argv[0]); return (0); } @@ -6064,8 +6155,10 @@ main(int argc, char **argv) return (dump_label(argv[0])); if (dump_opt['O']) { - if (argc != 2) + if (argc != 2) { + (void) fprintf(stderr, "missing dataset and path\n"); usage(); + } dump_opt['v'] = verbose + 3; return (dump_path(argv[0], argv[1])); } diff --git a/cmd/zdb/zdb.h b/cmd/zdb/zdb.h index 49579811efbb..903257a3c6d4 100644 --- a/cmd/zdb/zdb.h +++ b/cmd/zdb/zdb.h @@ -28,6 +28,6 @@ #define _ZDB_H void dump_intent_log(zilog_t *); -extern uint8_t dump_opt[256]; +extern uint8_t dump_opt[]; #endif /* _ZDB_H */ diff --git a/cmd/zdb/zdb_il.c b/cmd/zdb/zdb_il.c index c12178effae0..5d2af6820bba 100644 --- a/cmd/zdb/zdb_il.c +++ b/cmd/zdb/zdb_il.c @@ -47,8 +47,6 @@ #include "zdb.h" -extern uint8_t dump_opt[256]; - static char tab_prefix[4] = "\t\t\t"; static void diff --git a/man/man8/zdb.8 b/man/man8/zdb.8 index 57403cba74a2..e70e64297564 100644 --- a/man/man8/zdb.8 +++ b/man/man8/zdb.8 @@ -14,6 +14,7 @@ .\" Copyright 2017 Nexenta Systems, Inc. .\" Copyright (c) 2017 Lawrence Livermore National Security, LLC. .\" Copyright (c) 2017 Intel Corporation. +.\" Copyright 2019 Richard Elling .\" .Dd April 14, 2019 .Dt ZDB 8 SMM @@ -103,18 +104,18 @@ that zdb may interpret inconsistent pool data and behave erratically. .Sh OPTIONS Display options: .Bl -tag -width Ds -.It Fl b +.It Fl b, -block Display statistics regarding the number, size .Pq logical, physical and allocated and deduplication of blocks. -.It Fl c +.It Fl c, -checksum Verify the checksum of all metadata blocks while printing block statistics .Po see .Fl b .Pc . .Pp If specified multiple times, verify the checksums of all blocks. -.It Fl C +.It Fl C, -config Display information about the configuration. If specified with no other options, instead display information about the cache file @@ -127,7 +128,7 @@ cached configuration and the on-disk configuration. If specified multiple times with .Fl e also display the configuration that would be used were the pool to be imported. -.It Fl d +.It Fl d, -dataset Display information about datasets. Specified once, displays basic dataset information: ID, create transaction, size, and object count. @@ -136,7 +137,7 @@ If specified multiple times provides greater and greater verbosity. .Pp If object IDs are specified, display information about those specific objects only. -.It Fl D +.It Fl D, -dedup Display deduplication statistics, including the deduplication ratio .Pq Sy dedup , compression ratio @@ -157,23 +158,25 @@ Display the statistics independently for each deduplication table. Dump the contents of the deduplication tables describing duplicate blocks. .It Fl DDDDD Also dump the contents of the deduplication tables describing unique blocks. -.It Fl E Ar word0 Ns \&: Ns Ar word1 Ns :...: Ns Ar word15 +.It Fl E, -embedded-bp Ar word0 Ns \&: Ns Ar word1 Ns :...: Ns Ar word15 Decode and display block from an embedded block pointer specified by the .Ar word arguments. -.It Fl h +.It Fl -help +Show usage. +.It Fl h, -history Display pool history similar to .Nm zpool Cm history , but include internal changes, transaction, and dataset information. -.It Fl i +.It Fl i, -zil Display information about intent log .Pq ZIL entries relating to each dataset. If specified multiple times, display counts of each intent log transaction type. -.It Fl k +.It Fl k, -checkpoint Examine the checkpointed state of the pool. Note, the on disk format of the pool is not reverted to the checkpointed state. -.It Fl l Ar device +.It Fl l, -label Ar device Read the vdev labels from the specified device. .Nm Fl l will return 0 if valid label was found, 1 if error occurred, and 2 if no valid @@ -191,12 +194,12 @@ If the .Fl u option is also specified, also display the uberblocks on this device. Specify multiple times to increase verbosity. -.It Fl L +.It Fl L, -no-leak Disable leak detection and the loading of space maps. By default, .Nm verifies that all non-free blocks are referenced, which can be very expensive. -.It Fl m +.It Fl m, -metaslab Display the offset, spacemap, and free space of each metaslab. .It Fl mm Also display information about the on-disk free space histogram associated with @@ -206,14 +209,14 @@ Display the maximum contiguous free space, the in-core free space histogram, and the percentage of free space in each space map. .It Fl mmmm Display every spacemap record. -.It Fl M +.It Fl M, -metaslab-group Display the offset, spacemap, and free space of each metaslab. .It Fl MM Also display information about the maximum contiguous free space and the percentage of free space in each space map. .It Fl MMM Display every spacemap record. -.It Fl O Ar dataset path +.It Fl O, -object-by-path Ar dataset path Look up the specified .Ar path inside of the @@ -227,7 +230,7 @@ This option can be combined with .Fl v for increasing verbosity. .It Xo -.Fl R Ar poolname vdev Ns \&: Ns Ar offset Ns \&: Ns Ar size Ns Op : Ns Ar flags +.Fl R, -read-block Ar poolname vdev Ns \&: Ns Ar offset Ns \&: Ns Ar size Ns Op : Ns Ar flags .Xc 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 @@ -261,36 +264,40 @@ Dump indirect block .It Sy r Dump raw uninterpreted block data .El -.It Fl s +.It Fl s, -stats Report statistics on .Nm zdb I/O. Display operation counts, bandwidth, and error counts of I/O to the pool from .Nm . -.It Fl S +.It Fl S, -simulate-dedup Simulate the effects of deduplication, constructing a DDT and then display that DDT as with .Fl DD . -.It Fl u +.It Fl u, -uberblock Display the current uberblock. .El .Pp Other options: .Bl -tag -width Ds -.It Fl A +.It Fl A, -no-assertions Do not abort should any assertion fail. .It Fl AA Enable panic recovery, certain errors which would otherwise be fatal are demoted to warnings. .It Fl AAA Do not abort if asserts fail and also enable panic recovery. -.It Fl e Op Fl p Ar path ... +.It Fl e, -exported Op Fl p Ar path ... Operate on an exported pool, not present in .Pa /etc/zfs/zpool.cache . The .Fl p flag specifies the path under which devices are to be searched. -.It Fl x Ar dumpdir +Note: if the poolname is specified and multiple pools are discovered +with the same name in the exported device paths, then an 'Invalid +argument' error message is printed. The solution is to use the +desired pool's guid rather than the conflicted pool name. +.It Fl x, -dump-dir Ar dumpdir 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 that of the file or device read. @@ -301,53 +308,54 @@ Note that the flags are sufficient to access .Pq and thus copy all metadata on the pool. -.It Fl F +.It Fl F, -rewind Attempt to make an unreadable pool readable by trying progressively older transactions. -.It Fl G +.It Fl G, -debug-buffer Dump the contents of the zfs_dbgmsg buffer before exiting .Nm . zfs_dbgmsg is a buffer used by ZFS to dump advanced debug information. -.It Fl I Ar inflight I/Os +.It Fl I, -inflight Ar inflight I/Os Limit the number of outstanding checksum I/Os to the specified value. -The default value is 200. +The default value is 1000. This option affects the performance of the .Fl c option. -.It Fl o Ar var Ns = Ns Ar value ... +.It Fl o, -set Ar var Ns = Ns Ar value ... 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. -.It Fl P +.It Fl P, -parseable Print numbers in an unscaled form more amenable to parsing, eg. 1000000 rather than 1M. -.It Fl t Ar transaction -Specify the highest transaction to use when searching for uberblocks. +.It Fl t, -txg Ar transaction +Specify the highest transaction group number to use when searching for +uberblocks. See also the .Fl u and .Fl l options for a means to see the available uberblocks and their associated transaction numbers. -.It Fl U Ar cachefile +.It Fl U, -cachefile Ar cachefile Use a cache file other than .Pa /etc/zfs/zpool.cache . -.It Fl v +.It Fl v, -verbose Enable verbosity. Specify multiple times for increased verbosity. -.It Fl V +.It Fl V, -verbatim Attempt verbatim import. This mimics the behavior of the kernel when loading a pool from a cachefile. Only usable with .Fl e . -.It Fl X +.It Fl X, -extreme-rewind Attempt .Qq extreme transaction rewind, that is attempt the same recovery as .Fl F but read transactions otherwise deemed too old. -.It Fl Y +.It Fl Y, -reconstruct Attempt all possible combinations when reconstructing indirect split blocks. This flag disables the individual I/O deadman timer in order to allow as much time as required for the attempted reconstruction. diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 8219cf42b101..aa327e2a363f 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -106,7 +106,7 @@ tags = ['functional', 'clean_mirror'] [tests/functional/cli_root/zdb] tests = ['zdb_001_neg', 'zdb_002_pos', 'zdb_003_pos', 'zdb_004_pos', - 'zdb_005_pos', 'zdb_006_pos'] + 'zdb_005_pos', 'zdb_006_pos', 'zdb_long_options'] pre = post = tags = ['functional', 'cli_root', 'zdb'] diff --git a/tests/test-runner/bin/zts-report.py b/tests/test-runner/bin/zts-report.py index d046c13a55ef..855914f93cb4 100755 --- a/tests/test-runner/bin/zts-report.py +++ b/tests/test-runner/bin/zts-report.py @@ -220,7 +220,6 @@ 'cache/setup': ['SKIP', disk_reason], 'cache/cache_010_neg': ['FAIL', known_reason], 'chattr/setup': ['SKIP', exec_reason], - 'cli_root/zdb/zdb_006_pos': ['FAIL', known_reason], 'cli_root/zfs_get/zfs_get_004_pos': ['FAIL', known_reason], 'cli_root/zfs_get/zfs_get_009_pos': ['SKIP', '5479'], 'cli_root/zfs_rollback/zfs_rollback_001_pos': ['FAIL', '6415'], diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am index d37bcf607f46..2e8864bb4026 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am @@ -5,4 +5,5 @@ dist_pkgdata_SCRIPTS = \ zdb_003_pos.ksh \ zdb_004_pos.ksh \ zdb_005_pos.ksh \ - zdb_006_pos.ksh + zdb_006_pos.ksh \ + zdb_long_options.ksh diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_001_neg.ksh index a5f827b5642f..49c9bb506c85 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_001_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_001_neg.ksh @@ -27,6 +27,7 @@ # # Copyright (c) 2012, 2017 by Delphix. All rights reserved. +# Copyright 2019 Richard Elling # . $STF_SUITE/include/libtest.shlib @@ -59,7 +60,8 @@ set -A args "create" "add" "destroy" "import fakepool" \ "-a" "-f" "-g" "-h" "-j" "-m" "-n" "-o" "-p" \ "-p /tmp" "-r" "-t" "-w" "-x" "-y" "-z" \ "-D" "-E" "-G" "-H" "-I" "-J" "-K" "-M" \ - "-N" "-Q" "-R" "-S" "-T" "-W" "-Y" "-Z" + "-N" "-Q" "-R" "-S" "-T" "-W" "-Z" \ + "--blocks" "--create" "--rewind=10" log_assert "Execute zdb using invalid parameters." diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_006_pos.ksh index 97b00e9e1996..332228233694 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_006_pos.ksh @@ -13,6 +13,7 @@ # # Copyright (c) 2018 by Nutanix. All rights reserved. +# Copyright 2019 Richard Elling # . $STF_SUITE/include/libtest.shlib @@ -46,16 +47,34 @@ default_mirror_setup_noexit $DISKS log_must zfs snap $TESTPOOL/$TESTFS@snap log_must zdb -d $TESTPOOL -log_must zdb -d $TESTPOOL/ +log_must zdb --dataset $TESTPOOL/ log_must zdb -d $TESTPOOL/$TESTFS log_must zdb -d $TESTPOOL/$TESTFS@snap +# more detailed dataset information and zdb long option tests +typeset tmpfile=$(mktemp) +log_must zdb --dataset $TESTPOOL/$TESTFS >$tmpfile +log_mustnot grep -q "DMU dnode" $tmpfile +log_must zdb --dataset --dataset $TESTPOOL/$TESTFS >$tmpfile +log_must grep -q "DMU dnode" $tmpfile +rm -f $tmpfile + +# in many test systems, $TESTPOOL labels may linger +# to avoid zdb import confusion on exported pool names, use pool guid +TESTPOOL_GUID=$(zpool get -Hp -o value guid $TESTPOOL) log_must zpool export $TESTPOOL -log_must zdb -ed $TESTPOOL -log_must zdb -ed $TESTPOOL/ -log_must zdb -ed $TESTPOOL/$TESTFS -log_must zdb -ed $TESTPOOL/$TESTFS@snap +# to use the '-e' option, the DISKS need to be in /dev +# check the dirname to see if they are elsewhere +DISKS_ARRAY=($DISKS) +DIRNAME=$(dirname ${DISKS_ARRAY[0]}) +[[ $DIRNAME == "." ]] && DIRNAME=/dev + +log_must zdb -ed -p $DIRNAME $TESTPOOL_GUID +log_must zdb -ed -p $DIRNAME $TESTPOOL_GUID/ +log_must zdb --exported --dataset --path=$DIRNAME $TESTPOOL_GUID/$TESTFS +log_must zdb -e --dataset --path $DIRNAME $TESTPOOL_GUID/$TESTFS +log_must zdb -ed -p $DIRNAME $TESTPOOL_GUID/$TESTFS@snap log_must zpool import $TESTPOOL diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_long_options.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_long_options.ksh new file mode 100755 index 000000000000..f948218d4149 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_long_options.ksh @@ -0,0 +1,107 @@ +#!/bin/ksh + +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# https://opensource.org/licenses/CDDL-1.0 +# + +# +# Copyright 2019 Richard Elling +# + +. $STF_SUITE/include/libtest.shlib + +# +# Description: +# Test zdb options parsing. The options are complicated and testing +# with a live zdb executable is difficult. By setting the environment +# variable ZFS_OPTIONS_DEBUG, zdb will print the internally parsed +# options to stderr and exit without performing any operations. This +# allows testing of options parsing in a more complete, automated manner. +# + +function compare_value # key expected option ... +{ + typeset local key=$1 + shift + typeset local expected=$1 + shift + log_assert "key=$key count=$expected command=zdb $*" + result=$(zdb $* 2>&1 1>/dev/null | + awk -v key=$key '$1 == key {print $NF;exit}') + if [[ $result != $expected ]]; then + log_fail "zdb parse result \"$result\", expected \"$expected\"" + fi +} +typeset TEST_DESC="zdb options parser" +log_assert $TEST_DESC + +export ZFS_OPTIONS_DEBUG=true + +compare_value l 1 -l +compare_value l 2 -ll +compare_value l 2 -l -l +compare_value l 2 --label --label +compare_value l 2 -l --label +compare_value l 6 -l -ll --label -l -l + +compare_value d 1 -l -d +compare_value d 3 --dataset -dd + +compare_value argc 0 -e --path /dir --path=/dir -p /dir +compare_value argc 1 -e --path /dir --path=/dir -p /dir poolname +compare_value argc 2 -d poolname object + +# dump all sets many keys to value=2 +compare_value argc 1 poolname +compare_value b 2 poolname +compare_value c 2 poolname +compare_value C 2 poolname +compare_value d 2 poolname +compare_value e 0 poolname +compare_value e 2 --exported poolname +compare_value E 0 poolname +compare_value G 2 poolname +compare_value h 2 poolname +compare_value i 2 poolname +compare_value I 2 poolname +compare_value k 0 poolname +compare_value l 0 poolname +compare_value L 0 poolname +compare_value m 2 poolname +compare_value M 2 poolname +compare_value o 2 poolname +compare_value O 0 poolname +compare_value p 2 poolname +compare_value P 0 poolname +compare_value q 2 poolname +compare_value R 0 poolname +compare_value s 2 poolname +compare_value S 0 poolname +compare_value t 2 poolname +compare_value u 2 poolname +compare_value U 2 poolname +compare_value v 2 poolname +compare_value V 2 poolname +compare_value x 2 poolname +compare_value X 0 poolname +compare_value Y 2 poolname +compare_value 256 0 poolname + +# setting some options disables dump all +compare_value b 1 -b +compare_value c 0 -b +compare_value d 0 -b + +# option 256 is --help, but it exits immediately after printing message +log_assert "zdb --help shows usage message" +RES=$(zdb --help 2>&1 1>/dev/null | awk '{print $1;exit}') +[[ $RES != "Usage:" ]] && log_fail zdb --help usage not found + +log_pass $TEST_DESC