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 2022 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/vmm_drv_test.h>
24 #include <vmmapi.h>
25 
26 #include "common.h"
27 
28 int
main(int argc,char * argv[])29 main(int argc, char *argv[])
30 {
31 	const char *suite_name = basename(argv[0]);
32 	struct vmctx *ctx;
33 
34 	ctx = create_test_vm(suite_name);
35 	if (ctx == NULL) {
36 		perror("could open test VM");
37 		return (EXIT_FAILURE);
38 	}
39 
40 	int vdtfd = open_drv_test();
41 	if (vdtfd < 0) {
42 		perror("could open drv_test device");
43 		vm_destroy(ctx);
44 		return (EXIT_FAILURE);
45 	}
46 
47 	int err;
48 	err = ioctl(vdtfd, VDT_IOC_HOLD, vm_get_device_fd(ctx));
49 	if (err != 0) {
50 		perror("could not establish drv hold on VM");
51 		vm_destroy(ctx);
52 		return (EXIT_FAILURE);
53 	}
54 
55 	err = ioctl(vdtfd, VDT_IOC_RELE, 0);
56 	if (err != 0) {
57 		perror("could not release drv hold on VM");
58 		vm_destroy(ctx);
59 		return (EXIT_FAILURE);
60 	}
61 
62 	vm_destroy(ctx);
63 	(void) printf("%s\tPASS\n", suite_name);
64 	return (EXIT_SUCCESS);
65 }
66