1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * CDDL HEADER START 4 * 5 * The contents of this file are subject to the terms of the 6 * Common Development and Distribution License (the "License"). 7 * You may not use this file except in compliance with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or https://opensource.org/licenses/CDDL-1.0. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 23 /* 24 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 * 27 * Portions Copyright 2012 Martin Matuska <martin@matuska.org> 28 */ 29 30 /* 31 * Copyright (c) 2020 by Datto Inc. All rights reserved. 32 */ 33 34 #include <ctype.h> 35 #include <libnvpair.h> 36 #include <stdio.h> 37 #include <stdlib.h> 38 #include <string.h> 39 #include <unistd.h> 40 #include <stddef.h> 41 42 #include <libzfs.h> 43 #include <libzfs_core.h> 44 45 #include <sys/dmu.h> 46 #include <sys/zfs_ioctl.h> 47 #include "zstream.h" 48 49 int 50 zstream_do_token(int argc, char *argv[]) 51 { 52 char *resume_token = NULL; 53 libzfs_handle_t *hdl; 54 55 if (argc < 2) { 56 (void) fprintf(stderr, "Need to pass the resume token\n"); 57 zstream_usage(); 58 } 59 60 resume_token = argv[1]; 61 62 if ((hdl = libzfs_init()) == NULL) { 63 (void) fprintf(stderr, "%s\n", libzfs_error_init(errno)); 64 return (1); 65 } 66 67 nvlist_t *resume_nvl = 68 zfs_send_resume_token_to_nvlist(hdl, resume_token); 69 70 if (resume_nvl == NULL) { 71 (void) fprintf(stderr, 72 "Unable to parse resume token: %s\n", 73 libzfs_error_description(hdl)); 74 libzfs_fini(hdl); 75 return (1); 76 } 77 78 dump_nvlist(resume_nvl, 5); 79 nvlist_free(resume_nvl); 80 81 libzfs_fini(hdl); 82 return (0); 83 } 84