zdb: Add -O option for -r to specify object-id

"zdb -r -O pool/dataset obj-id destination" will copy
the file with object-id obj-id to the named destination;
without -O it'll still be interpreted as a pathname.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Akash B <akash-b@hpe.com>
Signed-off-by: Sean Eric Fagan <sean.fagan@klarasystems.com>
Closes #16307
This commit is contained in:
Allan Jude 2025-12-18 12:25:09 -05:00 committed by Tony Hutter
parent 0de2da6a37
commit ccb7c82aa1
2 changed files with 19 additions and 3 deletions

View File

@ -738,13 +738,14 @@ usage(void)
"[-U <cache>]\n\t\t<poolname> [<vdev> [<metaslab> ...]]\n" "[-U <cache>]\n\t\t<poolname> [<vdev> [<metaslab> ...]]\n"
"\t%s -O [-K <key>] <dataset> <path>\n" "\t%s -O [-K <key>] <dataset> <path>\n"
"\t%s -r [-K <key>] <dataset> <path> <destination>\n" "\t%s -r [-K <key>] <dataset> <path> <destination>\n"
"\t%s -r [-K <key>] -O <dataset> <object-id> <destination>\n"
"\t%s -R [-A] [-e [-V] [-p <path> ...]] [-U <cache>]\n" "\t%s -R [-A] [-e [-V] [-p <path> ...]] [-U <cache>]\n"
"\t\t<poolname> <vdev>:<offset>:<size>[:<flags>]\n" "\t\t<poolname> <vdev>:<offset>:<size>[:<flags>]\n"
"\t%s -E [-A] word0:word1:...:word15\n" "\t%s -E [-A] word0:word1:...:word15\n"
"\t%s -S [-AP] [-e [-V] [-p <path> ...]] [-U <cache>] " "\t%s -S [-AP] [-e [-V] [-p <path> ...]] [-U <cache>] "
"<poolname>\n\n", "<poolname>\n\n",
cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname,
cmdname, cmdname, cmdname, 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");
@ -9955,7 +9956,7 @@ main(int argc, char **argv)
* which imports the pool to the namespace if it's * which imports the pool to the namespace if it's
* not in the cachefile. * not in the cachefile.
*/ */
if (dump_opt['O']) { if (dump_opt['O'] && !dump_opt['r']) {
if (argc != 2) if (argc != 2)
usage(); usage();
dump_opt['v'] = verbose + 3; dump_opt['v'] = verbose + 3;
@ -9968,7 +9969,11 @@ main(int argc, char **argv)
if (argc != 3) if (argc != 3)
usage(); usage();
dump_opt['v'] = verbose; dump_opt['v'] = verbose;
error = dump_path(argv[0], argv[1], &object); if (dump_opt['O']) {
object = strtoull(argv[1], NULL, 0);
} else {
error = dump_path(argv[0], argv[1], &object);
}
if (error != 0) if (error != 0)
fatal("internal error: %s", strerror(error)); fatal("internal error: %s", strerror(error));
} }

View File

@ -84,6 +84,11 @@
.Op Fl K Ar key .Op Fl K Ar key
.Ar dataset path destination .Ar dataset path destination
.Nm .Nm
.Fl r
.Fl O
.Op Fl K Ar key
.Ar dataset object-id destination
.Nm
.Fl R .Fl R
.Op Fl A .Op Fl A
.Op Fl e Oo Fl V Oc Oo Fl p Ar path Oc Ns .Op Fl e Oo Fl V Oc Oo Fl p Ar path Oc Ns
@ -376,6 +381,12 @@ Specified
.Ar path .Ar path
must be relative to the root of must be relative to the root of
.Ar dataset . .Ar dataset .
When used with
.Fl O ,
the
.Ar path
argument is interpreted as an object identifier,
not a path.
This option can be combined with This option can be combined with
.Fl v .Fl v
for increasing verbosity. for increasing verbosity.