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 http://www.opensolaris.org/os/licensing.
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]
23 * Portions Copyright 2020 iXsystems, Inc.
27 * Test some invalid send operations with libzfs/libzfs_core.
29 * Specifying the to and from snaps in the wrong order should return EXDEV.
30 * We are checking that the early return doesn't accidentally leave any
31 * references held, so this test is designed to trigger a panic when asserts
32 * are verified with the bug present.
36 #include <libzfs_core.h>
46 usage(const char *name)
48 fprintf(stderr, "usage: %s snap0 snap1\n", name);
53 main(int argc, char const * const argv[])
55 sendflags_t flags = { 0 };
56 libzfs_handle_t *zhdl;
58 const char *fromfull, *tofull, *fsname, *fromsnap, *tosnap, *p;
68 p = strchr(fromfull, '@');
73 p = strchr(tofull, '@');
78 fsname = strndup(tofull, p - tofull);
79 if (strncmp(fsname, fromfull, p - tofull) != 0)
82 fd = open("/dev/null", O_WRONLY);
84 err(EX_OSERR, "open(\"/dev/null\", O_WRONLY)");
88 errx(EX_OSERR, "libzfs_init(): %s", libzfs_error_init(errno));
90 zhp = zfs_open(zhdl, fsname, ZFS_TYPE_FILESYSTEM);
92 err(EX_OSERR, "zfs_open(\"%s\")", fsname);
95 * Exercise EXDEV in dmu_send_obj. The error gets translated to
96 * EZFS_CROSSTARGET in libzfs.
98 error = zfs_send(zhp, tosnap, fromsnap, &flags, fd, NULL, NULL, NULL);
99 if (error == 0 || libzfs_errno(zhdl) != EZFS_CROSSTARGET)
100 errx(EX_OSERR, "zfs_send(\"%s\", \"%s\") should have failed "
101 "with EZFS_CROSSTARGET, not %d",
102 tofull, fromfull, libzfs_errno(zhdl));
103 printf("zfs_send(\"%s\", \"%s\"): %s\n",
104 tofull, fromfull, libzfs_error_description(zhdl));
109 * Exercise EXDEV in dmu_send.
111 error = lzc_send_resume_redacted(fromfull, tofull, fd, 0, 0, 0, NULL);
113 errx(EX_OSERR, "lzc_send_resume_redacted(\"%s\", \"%s\")"
114 " should have failed with EXDEV, not %d",
115 fromfull, tofull, error);
116 printf("lzc_send_resume_redacted(\"%s\", \"%s\"): %s\n",
117 fromfull, tofull, strerror(error));
120 * Exercise EXDEV in dmu_send_estimate_fast.
122 error = lzc_send_space_resume_redacted(fromfull, tofull, 0, 0, 0, 0,
125 errx(EX_OSERR, "lzc_send_space_resume_redacted(\"%s\", \"%s\")"
126 " should have failed with EXDEV, not %d",
127 fromfull, tofull, error);
128 printf("lzc_send_space_resume_redacted(\"%s\", \"%s\"): %s\n",
129 fromfull, tofull, strerror(error));
133 free((void *)fsname);
135 return (EXIT_SUCCESS);