dsl_dataset: put IO-inducing frees on the pool deadlist
[zfs.git] / cmd / zfs_ids_to_path.c
blob4db7e949ead017f2278f3b7b859a989c9286ae54
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 2019 by Delphix. All rights reserved.
24 #include <libintl.h>
25 #include <unistd.h>
26 #include <sys/types.h>
27 #include <stdint.h>
28 #include <libzfs.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <errno.h>
33 libzfs_handle_t *g_zfs;
35 static void
36 usage(int err)
38 fprintf(stderr, "Usage: zfs_ids_to_path [-v] <pool> <objset id> "
39 "<object id>\n");
40 exit(err);
43 int
44 main(int argc, char **argv)
46 boolean_t verbose = B_FALSE;
47 int c;
48 while ((c = getopt(argc, argv, "v")) != -1) {
49 switch (c) {
50 case 'v':
51 verbose = B_TRUE;
52 break;
55 argc -= optind;
56 argv += optind;
58 if (argc != 3) {
59 (void) fprintf(stderr, "Incorrect number of arguments: %d\n",
60 argc);
61 usage(1);
64 uint64_t objset, object;
65 if (sscanf(argv[1], "%llu", (u_longlong_t *)&objset) != 1) {
66 (void) fprintf(stderr, "Invalid objset id: %s\n", argv[1]);
67 usage(2);
69 if (sscanf(argv[2], "%llu", (u_longlong_t *)&object) != 1) {
70 (void) fprintf(stderr, "Invalid object id: %s\n", argv[2]);
71 usage(3);
73 if ((g_zfs = libzfs_init()) == NULL) {
74 (void) fprintf(stderr, "%s\n", libzfs_error_init(errno));
75 return (4);
77 zpool_handle_t *pool = zpool_open(g_zfs, argv[0]);
78 if (pool == NULL) {
79 fprintf(stderr, "Could not open pool %s\n", argv[0]);
80 libzfs_fini(g_zfs);
81 return (5);
84 char pathname[PATH_MAX * 2];
85 if (verbose) {
86 zpool_obj_to_path_ds(pool, objset, object, pathname,
87 sizeof (pathname));
88 } else {
89 zpool_obj_to_path(pool, objset, object, pathname,
90 sizeof (pathname));
92 printf("%s\n", pathname);
93 zpool_close(pool);
94 libzfs_fini(g_zfs);
95 return (0);