xref: /openbsd/usr.sbin/vmctl/vmctl.h (revision 85846d3e)
1 /*	$OpenBSD: vmctl.h,v 1.39 2024/07/09 15:51:11 mlarkin Exp $	*/
2 
3 /*
4  * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef VMCTL_PARSER_H
20 #define VMCTL_PARSER_H
21 
22 #define VMCTL_CU	"/usr/bin/cu"
23 
24 enum actions {
25 	NONE,
26 	CMD_CONSOLE,
27 	CMD_CREATE,
28 	CMD_LOAD,
29 	CMD_LOG,
30 	CMD_RELOAD,
31 	CMD_RESET,
32 	CMD_START,
33 	CMD_STATUS,
34 	CMD_STOP,
35 	CMD_STOPALL,
36 	CMD_WAITFOR,
37 	CMD_PAUSE,
38 	CMD_UNPAUSE,
39 	CMD_SEND,
40 	CMD_RECEIVE,
41 };
42 
43 struct ctl_command;
44 
45 struct parse_result {
46 	enum actions		 action;
47 	uint32_t		 id;
48 	char			*name;
49 	char			*path;
50 	char			*isopath;
51 	size_t			 size;
52 	int			 nifs;
53 	char			**nets;
54 	int			 nnets;
55 	size_t			 ndisks;
56 	char			**disks;
57 	int			*disktypes;
58 	int			 verbose;
59 	char			*instance;
60 	unsigned int		 flags;
61 	unsigned int		 mode;
62 	unsigned int		 bootdevice;
63 	struct ctl_command	*ctl;
64 };
65 
66 struct ctl_command {
67 	const char		*name;
68 	enum actions		 action;
69 	int			(*main)(struct parse_result *, int, char *[]);
70 	const char		*usage;
71 	int			 has_pledge;
72 };
73 
74 extern struct imsgbuf	*ibuf;
75 
76 /* main.c */
77 int	 vmmaction(struct parse_result *);
78 int	 parse_ifs(struct parse_result *, char *, int);
79 int	 parse_network(struct parse_result *, char *);
80 void	 parse_size(struct parse_result *, char *, const char *);
81 int	 parse_disktype(const char *, const char **);
82 int	 parse_disk(struct parse_result *, char *, int);
83 int	 parse_vmid(struct parse_result *, char *, int);
84 int	 parse_instance(struct parse_result *, char *);
85 void	 parse_free(struct parse_result *);
86 int	 parse(int, char *[]);
87 __dead void
88 	 ctl_openconsole(const char *);
89 
90 /* vmctl.c */
91 int	 open_imagefile(int, const char *, int,
92 	    struct virtio_backing *, off_t *);
93 int	 create_imagefile(int, const char *, const char *, uint64_t, const char **);
94 int	 vm_start(uint32_t, const char *, size_t, int, char **, int,
95 	    char **, int *, char *, char *, char *, unsigned int);
96 int	 vm_start_complete(struct imsg *, int *, int);
97 void	 terminate_vm(uint32_t, const char *, unsigned int);
98 int	 terminate_vm_complete(struct imsg *, int *, unsigned int);
99 void	 waitfor_vm(uint32_t, const char *);
100 void	 pause_vm(uint32_t, const char *);
101 int	 pause_vm_complete(struct imsg *, int *);
102 void	 unpause_vm(uint32_t, const char *);
103 int	 unpause_vm_complete(struct imsg *, int *);
104 void	 send_vm(uint32_t, const char *);
105 void	 vm_receive(uint32_t, const char *);
106 int	 check_info_id(const char *, uint32_t);
107 void	 get_info_vm(uint32_t, const char *, enum actions, unsigned int);
108 int	 add_info(struct imsg *, int *);
109 const char
110 	*vm_state(unsigned int);
111 int	 print_vm_info(struct vmop_info_result *, size_t);
112 void	 terminate_all(struct vmop_info_result *, size_t, unsigned int);
113 __dead void
114 	 vm_console(struct vmop_info_result *, size_t);
115 
116 #endif /* VMCTL_PARSER_H */
117