Skip to content

Commit

Permalink
zdb: Fix zdb '-O|-r' options with -e/exported zpool
Browse files Browse the repository at this point in the history
zdb with '-e' or exported zpool doesn't work along with
'-O' and '-r' options as we process them before '-e' has
been processed.

Below errors are seen:

~> zdb -e pool-mds65/mdt65 -O oi.9/0x200000009:0x0:0x0
failed to hold dataset 'pool-mds65/mdt65': No such file or directory

~> zdb -e pool-oss0/ost0 -r file1 /tmp/filecopy1 -p.
failed to hold dataset 'pool-oss0/ost0': No such file or directory
zdb: internal error: No such file or directory

We need to make sure to process '-O|-r' options after the
'-e' option has been processed, which imports the pool to
the namespace if it's not in the cachefile.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Akash B <akash-b@hpe.com>
Closes openzfs#15532
  • Loading branch information
akashb-22 authored and behlendorf committed Nov 28, 2023
1 parent 7c785f3 commit 96131a5
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -9164,22 +9164,6 @@ main(int argc, char **argv)
if (dump_opt['l'])
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], NULL));
}
if (dump_opt['r']) {
target_is_spa = B_FALSE;
if (argc != 3)
usage();
dump_opt['v'] = verbose;
error = dump_path(argv[0], argv[1], &object);
if (error != 0)
fatal("internal error: %s", strerror(error));
}

if (dump_opt['X'] || dump_opt['F'])
rewind = ZPOOL_DO_REWIND |
(dump_opt['X'] ? ZPOOL_EXTREME_REWIND : 0);
Expand Down Expand Up @@ -9280,6 +9264,29 @@ main(int argc, char **argv)
searchdirs = NULL;
}

/*
* We need to make sure to process -O option or call
* dump_path after the -e option has been processed,
* which imports the pool to the namespace if it's
* not in the cachefile.
*/
if (dump_opt['O']) {
if (argc != 2)
usage();
dump_opt['v'] = verbose + 3;
return (dump_path(argv[0], argv[1], NULL));
}

if (dump_opt['r']) {
target_is_spa = B_FALSE;
if (argc != 3)
usage();
dump_opt['v'] = verbose;
error = dump_path(argv[0], argv[1], &object);
if (error != 0)
fatal("internal error: %s", strerror(error));
}

/*
* import_checkpointed_state makes the assumption that the
* target pool that we pass it is already part of the spa
Expand Down

0 comments on commit 96131a5

Please sign in to comment.