xref: /freebsd/sys/contrib/openzfs/cmd/zstream/zstream_token.c (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 
13 /*
14  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
15  * Use is subject to license terms.
16  *
17  * Portions Copyright 2012 Martin Matuska <martin@matuska.org>
18  */
19 
20 /*
21  * Copyright (c) 2020 by Datto Inc. All rights reserved.
22  */
23 
24 #include <errno.h>
25 #include <libnvpair.h>
26 #include <libzfs.h>
27 #include <stdio.h>
28 #include <sys/nvpair.h>
29 
30 #include "zstream.h"
31 
32 int
zstream_do_token(int argc,char * argv[])33 zstream_do_token(int argc, char *argv[])
34 {
35 	char *resume_token = NULL;
36 	libzfs_handle_t *hdl;
37 
38 	if (argc < 2) {
39 		(void) fprintf(stderr, "Need to pass the resume token\n");
40 		zstream_usage();
41 	}
42 
43 	resume_token = argv[1];
44 
45 	if ((hdl = libzfs_init()) == NULL) {
46 		(void) fprintf(stderr, "%s\n", libzfs_error_init(errno));
47 		return (1);
48 	}
49 
50 	nvlist_t *resume_nvl =
51 	    zfs_send_resume_token_to_nvlist(hdl, resume_token);
52 
53 	if (resume_nvl == NULL) {
54 		(void) fprintf(stderr,
55 		    "Unable to parse resume token: %s\n",
56 		    libzfs_error_description(hdl));
57 		libzfs_fini(hdl);
58 		return (1);
59 	}
60 
61 	dump_nvlist(resume_nvl, 5);
62 	nvlist_free(resume_nvl);
63 
64 	libzfs_fini(hdl);
65 	return (0);
66 }
67