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]
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
);
83 if (strncmp(fsname
, fromfull
, p
- tofull
) != 0)
86 fd
= open("/dev/null", O_WRONLY
);
88 err(EX_OSERR
, "open(\"/dev/null\", O_WRONLY)");
92 errx(EX_OSERR
, "libzfs_init(): %s", libzfs_error_init(errno
));
94 zhp
= zfs_open(zhdl
, fsname
, ZFS_TYPE_FILESYSTEM
);
96 err(EX_OSERR
, "zfs_open(\"%s\")", fsname
);
99 * Exercise EXDEV in dmu_send_obj. The error gets translated to
100 * EZFS_CROSSTARGET in libzfs.
102 error
= zfs_send(zhp
, tosnap
, fromsnap
, &flags
, fd
, NULL
, NULL
, NULL
);
103 if (error
== 0 || libzfs_errno(zhdl
) != EZFS_CROSSTARGET
)
104 errx(EX_OSERR
, "zfs_send(\"%s\", \"%s\") should have failed "
105 "with EZFS_CROSSTARGET, not %d",
106 tofull
, fromfull
, libzfs_errno(zhdl
));
107 printf("zfs_send(\"%s\", \"%s\"): %s\n",
108 tofull
, fromfull
, libzfs_error_description(zhdl
));
113 * Exercise EXDEV in dmu_send.
115 error
= lzc_send_resume_redacted(fromfull
, tofull
, fd
, 0, 0, 0, NULL
);
117 errx(EX_OSERR
, "lzc_send_resume_redacted(\"%s\", \"%s\")"
118 " should have failed with EXDEV, not %d",
119 fromfull
, tofull
, error
);
120 printf("lzc_send_resume_redacted(\"%s\", \"%s\"): %s\n",
121 fromfull
, tofull
, strerror(error
));
124 * Exercise EXDEV in dmu_send_estimate_fast.
126 error
= lzc_send_space_resume_redacted(fromfull
, tofull
, 0, 0, 0, 0,
129 errx(EX_OSERR
, "lzc_send_space_resume_redacted(\"%s\", \"%s\")"
130 " should have failed with EXDEV, not %d",
131 fromfull
, tofull
, error
);
132 printf("lzc_send_space_resume_redacted(\"%s\", \"%s\"): %s\n",
133 fromfull
, tofull
, strerror(error
));
137 free((void *)fsname
);
139 return (EXIT_SUCCESS
);