1/*	$OpenBSD: vmctl.h,v 1.38 2024/05/18 06:45:00 jsg 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
24enum 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
43struct ctl_command;
44
45struct 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
66struct 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
74extern struct imsgbuf	*ibuf;
75
76/* main.c */
77int	 vmmaction(struct parse_result *);
78int	 parse_ifs(struct parse_result *, char *, int);
79int	 parse_network(struct parse_result *, char *);
80void	 parse_size(struct parse_result *, char *, const char *);
81int	 parse_disktype(const char *, const char **);
82int	 parse_disk(struct parse_result *, char *, int);
83int	 parse_vmid(struct parse_result *, char *, int);
84int	 parse_instance(struct parse_result *, char *);
85void	 parse_free(struct parse_result *);
86int	 parse(int, char *[]);
87__dead void
88	 ctl_openconsole(const char *);
89
90/* vmctl.c */
91int	 open_imagefile(int, const char *, int,
92	    struct virtio_backing *, off_t *);
93int	 create_imagefile(int, const char *, const char *, uint64_t, const char **);
94int	 vm_start(uint32_t, const char *, size_t, int, char **, int,
95	    char **, int *, char *, char *, char *, unsigned int);
96int	 vm_start_complete(struct imsg *, int *, int);
97void	 terminate_vm(uint32_t, const char *, unsigned int);
98int	 terminate_vm_complete(struct imsg *, int *, unsigned int);
99void	 waitfor_vm(uint32_t, const char *);
100void	 pause_vm(uint32_t, const char *);
101int	 pause_vm_complete(struct imsg *, int *);
102void	 unpause_vm(uint32_t, const char *);
103int	 unpause_vm_complete(struct imsg *, int *);
104void	 send_vm(uint32_t, const char *);
105void	 vm_receive(uint32_t, const char *);
106int	 check_info_id(const char *, uint32_t);
107void	 get_info_vm(uint32_t, const char *, enum actions, unsigned int);
108int	 add_info(struct imsg *, int *);
109const char
110	*vm_state(unsigned int);
111void	 print_vm_info(struct vmop_info_result *, size_t);
112void	 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