1 /* 2 * Copyright 2009-2017 Citrix Ltd and other contributors 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published 6 * by the Free Software Foundation; version 2.1 only. with the special 7 * exception on linking described in file LICENSE. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 */ 14 15 #ifndef XL_H 16 #define XL_H 17 18 #include <assert.h> 19 20 #include "_paths.h" 21 #include <xentoollog.h> 22 23 struct cmd_spec { 24 char *cmd_name; 25 int (*cmd_impl)(int argc, char **argv); 26 int can_dryrun; 27 int modifies; 28 char *cmd_desc; 29 char *cmd_usage; 30 char *cmd_option; 31 }; 32 33 struct domain_create { 34 int debug; 35 int daemonize; 36 int monitor; /* handle guest reboots etc */ 37 int paused; 38 int dryrun; 39 int quiet; 40 int vnc; 41 int vncautopass; 42 int console_autoconnect; 43 int checkpointed_stream; 44 int ignore_global_affinity_masks; 45 const char *config_file; 46 char *extra_config; /* extra config string */ 47 const char *restore_file; 48 char *colo_proxy_script; 49 bool userspace_colo_proxy; 50 int migrate_fd; /* -1 means none */ 51 int send_back_fd; /* -1 means none */ 52 char **migration_domname_r; /* from malloc */ 53 }; 54 55 int create_domain(struct domain_create *dom_info); 56 57 58 static const char savefileheader_magic[32]= 59 "Xen saved domain, xl format\n \0 \r"; 60 61 #ifndef LIBXL_HAVE_NO_SUSPEND_RESUME 62 static const char migrate_receiver_banner[]= 63 "xl migration receiver ready, send binary domain data.\n"; 64 static const char migrate_receiver_ready[]= 65 "domain received, ready to unpause"; 66 static const char migrate_permission_to_go[]= 67 "domain is yours, you are cleared to unpause"; 68 static const char migrate_report[]= 69 "my copy unpause results are as follows"; 70 #endif 71 72 /* followed by one byte: 73 * 0: everything went well, domain is running 74 * next thing is we all exit 75 * non-0: things went badly 76 * next thing should be a migrate_permission_to_go 77 * from target to source 78 */ 79 80 #define XL_MANDATORY_FLAG_JSON (1U << 0) /* config data is in JSON format */ 81 #define XL_MANDATORY_FLAG_STREAMv2 (1U << 1) /* stream is v2 */ 82 #define XL_MANDATORY_FLAG_ALL (XL_MANDATORY_FLAG_JSON | \ 83 XL_MANDATORY_FLAG_STREAMv2) 84 85 struct save_file_header { 86 char magic[32]; /* savefileheader_magic */ 87 /* All uint32_ts are in domain's byte order. */ 88 uint32_t byteorder; /* SAVEFILE_BYTEORDER_VALUE */ 89 uint32_t mandatory_flags; /* unknown flags => reject restore */ 90 uint32_t optional_flags; /* unknown flags => reject restore */ 91 uint32_t optional_data_len; /* skip, or skip tail, if not understood */ 92 }; 93 94 /* Optional data, in order: 95 * 4 bytes uint32_t config file size 96 * n bytes config file in Unix text file format 97 */ 98 99 #define SAVEFILE_BYTEORDER_VALUE ((uint32_t)0x01020304UL) 100 101 void save_domain_core_begin(uint32_t domid, 102 int preserve_domid, 103 const char *override_config_file, 104 uint8_t **config_data_r, 105 int *config_len_r); 106 void save_domain_core_writeconfig(int fd, const char *source, 107 const uint8_t *config_data, int config_len); 108 109 /* 110 * The xl process should always return either EXIT_SUCCESS or 111 * EXIT_FAILURE. main_* functions, implementing the various xl 112 * commands, can be treated as main() as if they are returning 113 * a process exit status and not a function return value. 114 */ 115 116 int main_vcpulist(int argc, char **argv); 117 int main_info(int argc, char **argv); 118 int main_sharing(int argc, char **argv); 119 int main_cd_eject(int argc, char **argv); 120 int main_cd_insert(int argc, char **argv); 121 int main_console(int argc, char **argv); 122 int main_vncviewer(int argc, char **argv); 123 int main_pcilist(int argc, char **argv); 124 int main_pcidetach(int argc, char **argv); 125 int main_pciattach(int argc, char **argv); 126 int main_pciassignable_add(int argc, char **argv); 127 int main_pciassignable_remove(int argc, char **argv); 128 int main_pciassignable_list(int argc, char **argv); 129 #ifndef LIBXL_HAVE_NO_SUSPEND_RESUME 130 int main_restore(int argc, char **argv); 131 int main_migrate_receive(int argc, char **argv); 132 int main_save(int argc, char **argv); 133 int main_migrate(int argc, char **argv); 134 #endif 135 int main_dump_core(int argc, char **argv); 136 int main_pause(int argc, char **argv); 137 int main_unpause(int argc, char **argv); 138 int main_destroy(int argc, char **argv); 139 int main_shutdown(int argc, char **argv); 140 int main_reboot(int argc, char **argv); 141 int main_list(int argc, char **argv); 142 int main_vm_list(int argc, char **argv); 143 int main_create(int argc, char **argv); 144 int main_config_update(int argc, char **argv); 145 int main_button_press(int argc, char **argv); 146 int main_vcpupin(int argc, char **argv); 147 int main_vcpuset(int argc, char **argv); 148 int main_memmax(int argc, char **argv); 149 int main_memset(int argc, char **argv); 150 int main_sched_credit(int argc, char **argv); 151 int main_sched_credit2(int argc, char **argv); 152 int main_sched_rtds(int argc, char **argv); 153 int main_domid(int argc, char **argv); 154 int main_domname(int argc, char **argv); 155 int main_rename(int argc, char **argv); 156 int main_trigger(int argc, char **argv); 157 int main_sysrq(int argc, char **argv); 158 int main_debug_keys(int argc, char **argv); 159 int main_set_parameters(int argc, char **argv); 160 int main_dmesg(int argc, char **argv); 161 int main_top(int argc, char **argv); 162 int main_networkattach(int argc, char **argv); 163 int main_networklist(int argc, char **argv); 164 int main_networkdetach(int argc, char **argv); 165 int main_channellist(int argc, char **argv); 166 int main_blockattach(int argc, char **argv); 167 int main_blocklist(int argc, char **argv); 168 int main_blockdetach(int argc, char **argv); 169 int main_vtpmattach(int argc, char **argv); 170 int main_vtpmlist(int argc, char **argv); 171 int main_vtpmdetach(int argc, char **argv); 172 int main_vdisplattach(int argc, char **argv); 173 int main_vdispllist(int argc, char **argv); 174 int main_vdispldetach(int argc, char **argv); 175 int main_vsndattach(int argc, char **argv); 176 int main_vsndlist(int argc, char **argv); 177 int main_vsnddetach(int argc, char **argv); 178 int main_vkbattach(int argc, char **argv); 179 int main_vkblist(int argc, char **argv); 180 int main_vkbdetach(int argc, char **argv); 181 int main_usbctrl_attach(int argc, char **argv); 182 int main_usbctrl_detach(int argc, char **argv); 183 int main_usbdev_attach(int argc, char **argv); 184 int main_usbdev_detach(int argc, char **argv); 185 int main_usblist(int argc, char **argv); 186 int main_uptime(int argc, char **argv); 187 int main_claims(int argc, char **argv); 188 int main_network2attach(int argc, char **argv); 189 int main_network2list(int argc, char **argv); 190 int main_network2detach(int argc, char **argv); 191 int main_cpupoolcreate(int argc, char **argv); 192 int main_cpupoollist(int argc, char **argv); 193 int main_cpupooldestroy(int argc, char **argv); 194 int main_cpupoolrename(int argc, char **argv); 195 int main_cpupoolcpuadd(int argc, char **argv); 196 int main_cpupoolcpuremove(int argc, char **argv); 197 int main_cpupoolmigrate(int argc, char **argv); 198 int main_cpupoolnumasplit(int argc, char **argv); 199 int main_getenforce(int argc, char **argv); 200 int main_setenforce(int argc, char **argv); 201 int main_loadpolicy(int argc, char **argv); 202 #ifndef LIBXL_HAVE_NO_SUSPEND_RESUME 203 int main_remus(int argc, char **argv); 204 #endif 205 int main_devd(int argc, char **argv); 206 #if defined(__i386__) || defined(__x86_64__) 207 int main_psr_hwinfo(int argc, char **argv); 208 int main_psr_cmt_attach(int argc, char **argv); 209 int main_psr_cmt_detach(int argc, char **argv); 210 int main_psr_cmt_show(int argc, char **argv); 211 int main_psr_cat_cbm_set(int argc, char **argv); 212 int main_psr_cat_show(int argc, char **argv); 213 int main_psr_mba_set(int argc, char **argv); 214 int main_psr_mba_show(int argc, char **argv); 215 #endif 216 int main_qemu_monitor_command(int argc, char **argv); 217 218 void help(const char *command); 219 220 extern const char *common_domname; 221 extern struct cmd_spec cmd_table[]; 222 extern int cmdtable_len; 223 /* Look up a command in the table, allowing unambiguous truncation */ 224 struct cmd_spec *cmdtable_lookup(const char *s); 225 226 extern libxl_ctx *ctx; 227 extern xentoollog_logger_stdiostream *logger; 228 extern int logfile; 229 230 void xl_ctx_alloc(void); 231 232 /* child processes */ 233 234 typedef struct { 235 /* every struct like this must be in XLCHILD_LIST */ 236 pid_t pid; /* 0: not in use */ 237 int reaped; /* valid iff pid!=0 */ 238 int status; /* valid iff reaped */ 239 const char *description; /* valid iff pid!=0 */ 240 } xlchild; 241 242 typedef enum { 243 child_console, child_waitdaemon, child_migration, child_vncviewer, 244 child_max 245 } xlchildnum; 246 247 extern xlchild children[child_max]; 248 249 pid_t xl_fork(xlchildnum, const char *description); 250 /* like fork, but prints and dies if it fails */ 251 void postfork(void); /* needed only if we aren't going to exec right away */ 252 253 /* Handles EINTR. Clears out the xlchild so it can be reused. */ 254 pid_t xl_waitpid(xlchildnum, int *status, int flags); 255 256 int xl_child_pid(xlchildnum); /* returns 0 if child struct is not in use */ 257 258 void xl_report_child_exitstatus(xentoollog_level level, 259 xlchildnum child, pid_t pid, int status); 260 /* like libxl_report_child_exitstatus, but uses children[].description */ 261 262 int child_report(xlchildnum child); 263 /* waits and expects child to exit status 0. 264 * otherwise, logs and returns ERROR_FAIL */ 265 266 /* global options */ 267 extern int autoballoon; 268 extern int run_hotplug_scripts; 269 extern int dryrun_only; 270 extern int claim_mode; 271 extern bool progress_use_cr; 272 extern xentoollog_level minmsglevel; 273 #define minmsglevel_default XTL_PROGRESS 274 extern char *lockfile; 275 extern char *default_vifscript; 276 extern char *default_bridge; 277 extern char *default_gatewaydev; 278 extern char *default_vifbackend; 279 extern char *default_remus_netbufscript; 280 extern char *default_colo_proxy_script; 281 extern char *blkdev_start; 282 extern int max_grant_frames; 283 extern int max_maptrack_frames; 284 extern libxl_bitmap global_vm_affinity_mask; 285 extern libxl_bitmap global_hvm_affinity_mask; 286 extern libxl_bitmap global_pv_affinity_mask; 287 extern libxl_domid domid_policy; 288 289 enum output_format { 290 OUTPUT_FORMAT_JSON, 291 OUTPUT_FORMAT_SXP, 292 }; 293 extern enum output_format default_output_format; 294 295 typedef enum { 296 DOMAIN_RESTART_NONE = 0, /* No domain restart */ 297 DOMAIN_RESTART_NORMAL, /* Domain should be restarted */ 298 DOMAIN_RESTART_RENAME, /* Domain should be renamed and restarted */ 299 DOMAIN_RESTART_SOFT_RESET, /* Soft reset should be performed */ 300 } domain_restart_type; 301 302 extern void printf_info_sexp(int domid, libxl_domain_config *d_config, FILE *fh); 303 extern void apply_global_affinity_masks(libxl_domain_type type, 304 libxl_bitmap *vcpu_affinity_array, 305 unsigned int size); 306 307 #define XL_GLOBAL_CONFIG XEN_CONFIG_DIR "/xl.conf" 308 #define XL_LOCK_FILE XEN_LOCK_DIR "/xl" 309 310 #endif /* XL_H */ 311 312 /* 313 * Local variables: 314 * mode: C 315 * c-basic-offset: 4 316 * indent-tabs-mode: nil 317 * End: 318 */ 319