From b702644a6eb66615d67b492fd73ecd9efa11fc7d Mon Sep 17 00:00:00 2001 From: Tim Chase Date: Tue, 19 Jul 2016 16:24:06 -0700 Subject: [PATCH] 7164 zdb should be able to open the root dataset Reviewed by: Pavel Zakharov Reviewed by: Matthew Ahrens Approved by: Robert Mustacchi --- usr/src/cmd/zdb/zdb.c | 18 +++++++++++++++++- usr/src/man/man1m/zdb.1m | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/usr/src/cmd/zdb/zdb.c b/usr/src/cmd/zdb/zdb.c index deef7b40848f..751610c6fb71 100644 --- a/usr/src/cmd/zdb/zdb.c +++ b/usr/src/cmd/zdb/zdb.c @@ -3533,6 +3533,7 @@ main(int argc, char **argv) uint64_t max_txg = UINT64_MAX; int rewind = ZPOOL_NEVER_REWIND; char *spa_config_path_env; + boolean_t target_is_spa = B_TRUE; (void) setrlimit(RLIMIT_NOFILE, &rl); (void) enable_extended_FILE_stdio(-1, -1); @@ -3711,8 +3712,23 @@ main(int argc, char **argv) } } + if (strpbrk(target, "/@") != NULL) { + size_t targetlen; + + target_is_spa = B_FALSE; + /* + * Remove any trailing slash. Later code would get confused + * by it, but we want to allow it so that "pool/" can + * indicate that we want to dump the topmost filesystem, + * rather than the whole pool. + */ + targetlen = strlen(target); + if (targetlen != 0 && target[targetlen - 1] == '/') + target[targetlen - 1] = '\0'; + } + if (error == 0) { - if (strpbrk(target, "/@") == NULL || dump_opt['R']) { + if (target_is_spa || dump_opt['R']) { error = spa_open_rewind(target, &spa, FTAG, policy, NULL); if (error) { diff --git a/usr/src/man/man1m/zdb.1m b/usr/src/man/man1m/zdb.1m index 7ec98908f625..0b5b01df76be 100644 --- a/usr/src/man/man1m/zdb.1m +++ b/usr/src/man/man1m/zdb.1m @@ -55,6 +55,11 @@ 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 not documented, a knowledge of ZFS internals is assumed. +.P +If the \fIdataset\fR argument does not contain any \fB/\fR or \fB@\fR +characters, it is interpreted as a pool name. The root dataset can be +specified as \fIpool\fB/\fR (pool name followed by a slash). + .P When operating on an imported and active pool it is possible, though unlikely, that zdb may interpret inconsistent pool data and behave erratically.