1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2024 Oxide Computer Company 14 */ 15 16 #include <stdio.h> 17 #include <unistd.h> 18 #include <stdlib.h> 19 #include <fcntl.h> 20 #include <libgen.h> 21 22 #include <sys/vmm.h> 23 #include <sys/viona_io.h> 24 #include <vmmapi.h> 25 26 #include "common.h" 27 #include "in_guest.h" 28 #include "viona_suite.h" 29 30 int 31 main(int argc, char *argv[]) 32 { 33 const char *suite_name = basename(argv[0]); 34 struct vmctx *ctx; 35 36 ctx = test_initialize_plain(suite_name); 37 if (ctx == NULL) { 38 test_fail_errno(errno, "could not open test VM"); 39 } 40 41 int vfd = open_viona(); 42 if (vfd < 0) { 43 test_fail_errno(errno, "could not open viona device"); 44 } 45 46 datalink_id_t dlid; 47 dladm_status_t dls = query_dlid(VIONA_TEST_IFACE_NAME, &dlid); 48 if (dls != DLADM_STATUS_OK) { 49 char errbuf[DLADM_STRSIZE]; 50 51 test_fail_msg("could not query datalink id for %s: %s", 52 VIONA_TEST_IFACE_NAME, dladm_status2str(dls, errbuf)); 53 } 54 55 vioc_create_t create_ioc = { 56 .c_linkid = dlid, 57 .c_vmfd = vm_get_device_fd(ctx), 58 }; 59 if (ioctl(vfd, VNA_IOC_CREATE, &create_ioc) != 0) { 60 test_fail_errno(errno, "failed to create link on viona device"); 61 } 62 63 if (ioctl(vfd, VNA_IOC_DELETE, 0) != 0) { 64 test_fail_errno(errno, "failed to delete link on viona device"); 65 } 66 67 test_pass(); 68 return (EXIT_SUCCESS); 69 } 70