1 /* $OpenBSD: vmctl.h,v 1.34 2021/01/27 07:21:12 deraadt 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 long long 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 int parse_size(struct parse_result *, 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 *, long, const char **); 94 int create_raw_imagefile(const char *, long); 95 int create_qc2_imagefile(const char *, const char *, long); 96 int vm_start(uint32_t, const char *, int, int, char **, int, 97 char **, int *, char *, char *, char *, unsigned int); 98 int vm_start_complete(struct imsg *, int *, int); 99 void terminate_vm(uint32_t, const char *, unsigned int); 100 int terminate_vm_complete(struct imsg *, int *, unsigned int); 101 void waitfor_vm(uint32_t, const char *); 102 void pause_vm(uint32_t, const char *); 103 int pause_vm_complete(struct imsg *, int *); 104 void unpause_vm(uint32_t, const char *); 105 int unpause_vm_complete(struct imsg *, int *); 106 void send_vm(uint32_t, const char *); 107 void vm_receive(uint32_t, const char *); 108 int check_info_id(const char *, uint32_t); 109 void get_info_vm(uint32_t, const char *, enum actions, unsigned int); 110 int add_info(struct imsg *, int *); 111 const char 112 *vm_state(unsigned int); 113 void print_vm_info(struct vmop_info_result *, size_t); 114 void terminate_all(struct vmop_info_result *, size_t, unsigned int); 115 __dead void 116 vm_console(struct vmop_info_result *, size_t); 117 118 #endif /* VMCTL_PARSER_H */ 119