1 |
/* |
2 |
* Cisco 7200 (Predator) simulation platform. |
3 |
* Copyright (c) 2006 Christophe Fillot (cf@utc.fr) |
4 |
* |
5 |
* Hypervisor generic VM routines. |
6 |
*/ |
7 |
|
8 |
#include <stdio.h> |
9 |
#include <stdlib.h> |
10 |
#include <unistd.h> |
11 |
#include <string.h> |
12 |
#include <sys/types.h> |
13 |
#include <sys/stat.h> |
14 |
#include <sys/mman.h> |
15 |
#include <signal.h> |
16 |
#include <fcntl.h> |
17 |
#include <errno.h> |
18 |
#include <assert.h> |
19 |
#include <stdarg.h> |
20 |
#include <sys/ioctl.h> |
21 |
#include <sys/types.h> |
22 |
#include <sys/socket.h> |
23 |
#include <arpa/inet.h> |
24 |
#include <pthread.h> |
25 |
|
26 |
#include "mips64.h" |
27 |
#include "cp0.h" |
28 |
#include "dynamips.h" |
29 |
#include "device.h" |
30 |
#include "dev_c7200.h" |
31 |
#include "dev_vtty.h" |
32 |
#include "utils.h" |
33 |
#include "base64.h" |
34 |
#include "net.h" |
35 |
#include "atm.h" |
36 |
#include "frame_relay.h" |
37 |
#include "crc.h" |
38 |
#include "net_io.h" |
39 |
#include "net_io_bridge.h" |
40 |
#ifdef GEN_ETH |
41 |
#include "gen_eth.h" |
42 |
#endif |
43 |
#include "registry.h" |
44 |
#include "hypervisor.h" |
45 |
|
46 |
/* Find the specified CPU */ |
47 |
static cpu_mips_t *find_cpu(hypervisor_conn_t *conn,vm_instance_t *vm, |
48 |
u_int cpu_id) |
49 |
{ |
50 |
cpu_mips_t *cpu; |
51 |
|
52 |
cpu = cpu_group_find_id(vm->cpu_group,cpu_id); |
53 |
|
54 |
if (!cpu) { |
55 |
vm_release(vm); |
56 |
hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"Bad CPU specified"); |
57 |
return NULL; |
58 |
} |
59 |
|
60 |
return cpu; |
61 |
} |
62 |
|
63 |
/* Set debugging level */ |
64 |
static int cmd_set_debug_level(hypervisor_conn_t *conn,int argc,char *argv[]) |
65 |
{ |
66 |
vm_instance_t *vm; |
67 |
|
68 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
69 |
return(-1); |
70 |
|
71 |
vm->debug_level = atoi(argv[1]); |
72 |
|
73 |
vm_release(vm); |
74 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"O",argv[0]); |
75 |
return(0); |
76 |
} |
77 |
|
78 |
/* Set IOS image filename */ |
79 |
static int cmd_set_ios(hypervisor_conn_t *conn,int argc,char *argv[]) |
80 |
{ |
81 |
vm_instance_t *vm; |
82 |
|
83 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
84 |
return(-1); |
85 |
|
86 |
if (vm_ios_set_image(vm,argv[1]) == -1) { |
87 |
vm_release(vm); |
88 |
hypervisor_send_reply(conn,HSC_ERR_CREATE,1, |
89 |
"unable to store IOS image name for router '%s'", |
90 |
argv[0]); |
91 |
return(-1); |
92 |
} |
93 |
|
94 |
vm_release(vm); |
95 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"IOS image set for '%s'",argv[0]); |
96 |
return(0); |
97 |
} |
98 |
|
99 |
/* Set IOS configuration filename to load at startup */ |
100 |
static int cmd_set_config(hypervisor_conn_t *conn,int argc,char *argv[]) |
101 |
{ |
102 |
vm_instance_t *vm; |
103 |
|
104 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
105 |
return(-1); |
106 |
|
107 |
if (vm_ios_set_config(vm,argv[1]) == -1) { |
108 |
vm_release(vm); |
109 |
hypervisor_send_reply(conn,HSC_ERR_CREATE,1, |
110 |
"unable to store IOS config for router '%s'", |
111 |
argv[0]); |
112 |
return(-1); |
113 |
} |
114 |
|
115 |
vm_release(vm); |
116 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"IOS config file set for '%s'", |
117 |
argv[0]); |
118 |
return(0); |
119 |
} |
120 |
|
121 |
/* Set RAM size */ |
122 |
static int cmd_set_ram(hypervisor_conn_t *conn,int argc,char *argv[]) |
123 |
{ |
124 |
vm_instance_t *vm; |
125 |
|
126 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
127 |
return(-1); |
128 |
|
129 |
vm->ram_size = atoi(argv[1]); |
130 |
|
131 |
vm_release(vm); |
132 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
133 |
return(0); |
134 |
} |
135 |
|
136 |
/* Set NVRAM size */ |
137 |
static int cmd_set_nvram(hypervisor_conn_t *conn,int argc,char *argv[]) |
138 |
{ |
139 |
vm_instance_t *vm; |
140 |
|
141 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
142 |
return(-1); |
143 |
|
144 |
vm->nvram_size = atoi(argv[1]); |
145 |
|
146 |
vm_release(vm); |
147 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
148 |
return(0); |
149 |
} |
150 |
|
151 |
/* Enable/disable use of a memory-mapped file to simulate RAM */ |
152 |
static int cmd_set_ram_mmap(hypervisor_conn_t *conn,int argc,char *argv[]) |
153 |
{ |
154 |
vm_instance_t *vm; |
155 |
|
156 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
157 |
return(-1); |
158 |
|
159 |
vm->ram_mmap = atoi(argv[1]); |
160 |
|
161 |
vm_release(vm); |
162 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
163 |
return(0); |
164 |
} |
165 |
|
166 |
/* Set the clock divisor */ |
167 |
static int cmd_set_clock_divisor(hypervisor_conn_t *conn,int argc,char *argv[]) |
168 |
{ |
169 |
vm_instance_t *vm; |
170 |
u_int clock_div; |
171 |
|
172 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
173 |
return(-1); |
174 |
|
175 |
if ((clock_div = atoi(argv[1])) != 0) |
176 |
vm->clock_divisor = clock_div; |
177 |
|
178 |
vm_release(vm); |
179 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
180 |
return(0); |
181 |
} |
182 |
|
183 |
/* Set the idle PC */ |
184 |
static int cmd_set_idle_pc(hypervisor_conn_t *conn,int argc,char *argv[]) |
185 |
{ |
186 |
vm_instance_t *vm; |
187 |
|
188 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
189 |
return(-1); |
190 |
|
191 |
vm->idle_pc = strtoull(argv[1],NULL,0); |
192 |
|
193 |
vm_release(vm); |
194 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
195 |
return(0); |
196 |
} |
197 |
|
198 |
/* Set the idle PC value when the CPU is online */ |
199 |
static int cmd_set_idle_pc_online(hypervisor_conn_t *conn, |
200 |
int argc,char *argv[]) |
201 |
{ |
202 |
vm_instance_t *vm; |
203 |
cpu_mips_t *cpu; |
204 |
|
205 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
206 |
return(-1); |
207 |
|
208 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
209 |
return(-1); |
210 |
|
211 |
cpu->idle_pc = strtoull(argv[2],NULL,0); |
212 |
|
213 |
vm_release(vm); |
214 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
215 |
return(0); |
216 |
} |
217 |
|
218 |
/* Get the idle PC proposals */ |
219 |
static int cmd_get_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[]) |
220 |
{ |
221 |
vm_instance_t *vm; |
222 |
cpu_mips_t *cpu; |
223 |
int i; |
224 |
|
225 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
226 |
return(-1); |
227 |
|
228 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
229 |
return(-1); |
230 |
|
231 |
mips64_get_idling_pc(cpu); |
232 |
|
233 |
for(i=0;i<cpu->idle_pc_prop_count;i++) { |
234 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]", |
235 |
cpu->idle_pc_prop[i].pc, |
236 |
cpu->idle_pc_prop[i].count); |
237 |
} |
238 |
|
239 |
vm_release(vm); |
240 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
241 |
return(0); |
242 |
} |
243 |
|
244 |
/* Dump the idle PC proposals */ |
245 |
static int cmd_show_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[]) |
246 |
{ |
247 |
vm_instance_t *vm; |
248 |
cpu_mips_t *cpu; |
249 |
int i; |
250 |
|
251 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
252 |
return(-1); |
253 |
|
254 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
255 |
return(-1); |
256 |
|
257 |
for(i=0;i<cpu->idle_pc_prop_count;i++) { |
258 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]", |
259 |
cpu->idle_pc_prop[i].pc, |
260 |
cpu->idle_pc_prop[i].count); |
261 |
} |
262 |
|
263 |
vm_release(vm); |
264 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
265 |
return(0); |
266 |
} |
267 |
|
268 |
/* Set CPU idle max value */ |
269 |
static int cmd_set_idle_max(hypervisor_conn_t *conn,int argc,char *argv[]) |
270 |
{ |
271 |
vm_instance_t *vm; |
272 |
cpu_mips_t *cpu; |
273 |
|
274 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
275 |
return(-1); |
276 |
|
277 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
278 |
return(-1); |
279 |
|
280 |
cpu->idle_max = atoi(argv[2]); |
281 |
|
282 |
vm_release(vm); |
283 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
284 |
return(0); |
285 |
} |
286 |
|
287 |
/* Set CPU idle sleep time value */ |
288 |
static int cmd_set_idle_sleep_time(hypervisor_conn_t *conn, |
289 |
int argc,char *argv[]) |
290 |
{ |
291 |
vm_instance_t *vm; |
292 |
cpu_mips_t *cpu; |
293 |
|
294 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
295 |
return(-1); |
296 |
|
297 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
298 |
return(-1); |
299 |
|
300 |
cpu->idle_sleep_time = atoi(argv[2]); |
301 |
|
302 |
vm_release(vm); |
303 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
304 |
return(0); |
305 |
} |
306 |
|
307 |
/* Show info about potential timer drift */ |
308 |
static int cmd_show_timer_drift(hypervisor_conn_t *conn, |
309 |
int argc,char *argv[]) |
310 |
{ |
311 |
vm_instance_t *vm; |
312 |
cpu_mips_t *cpu; |
313 |
|
314 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
315 |
return(-1); |
316 |
|
317 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
318 |
return(-1); |
319 |
|
320 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Timer Drift: %u", |
321 |
cpu->timer_drift); |
322 |
|
323 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Pending Timer IRQ: %u", |
324 |
cpu->timer_irq_pending); |
325 |
|
326 |
vm_release(vm); |
327 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
328 |
return(0); |
329 |
} |
330 |
|
331 |
/* Set the exec area size */ |
332 |
static int cmd_set_exec_area(hypervisor_conn_t *conn,int argc,char *argv[]) |
333 |
{ |
334 |
vm_instance_t *vm; |
335 |
|
336 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
337 |
return(-1); |
338 |
|
339 |
vm->exec_area_size = atoi(argv[1]); |
340 |
|
341 |
vm_release(vm); |
342 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
343 |
return(0); |
344 |
} |
345 |
|
346 |
/* Set ghost RAM file */ |
347 |
static int cmd_set_ghost_file(hypervisor_conn_t *conn,int argc,char *argv[]) |
348 |
{ |
349 |
vm_instance_t *vm; |
350 |
|
351 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
352 |
return(-1); |
353 |
|
354 |
vm->ghost_ram_filename = strdup(argv[1]); |
355 |
|
356 |
vm_release(vm); |
357 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
358 |
return(0); |
359 |
} |
360 |
|
361 |
/* Set ghost RAM status */ |
362 |
static int cmd_set_ghost_status(hypervisor_conn_t *conn,int argc,char *argv[]) |
363 |
{ |
364 |
vm_instance_t *vm; |
365 |
|
366 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
367 |
return(-1); |
368 |
|
369 |
vm->ghost_status = atoi(argv[1]); |
370 |
|
371 |
vm_release(vm); |
372 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
373 |
return(0); |
374 |
} |
375 |
|
376 |
|
377 |
/* Set PCMCIA ATA disk0 size */ |
378 |
static int cmd_set_disk0(hypervisor_conn_t *conn,int argc,char *argv[]) |
379 |
{ |
380 |
vm_instance_t *vm; |
381 |
|
382 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
383 |
return(-1); |
384 |
|
385 |
vm->pcmcia_disk_size[0] = atoi(argv[1]); |
386 |
vm_release(vm); |
387 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
388 |
return(0); |
389 |
} |
390 |
|
391 |
/* Set PCMCIA ATA disk1 size */ |
392 |
static int cmd_set_disk1(hypervisor_conn_t *conn,int argc,char *argv[]) |
393 |
{ |
394 |
vm_instance_t *vm; |
395 |
|
396 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
397 |
return(-1); |
398 |
|
399 |
vm->pcmcia_disk_size[1] = atoi(argv[1]); |
400 |
vm_release(vm); |
401 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
402 |
return(0); |
403 |
} |
404 |
|
405 |
/* Set the config register used at startup */ |
406 |
static int cmd_set_conf_reg(hypervisor_conn_t *conn,int argc,char *argv[]) |
407 |
{ |
408 |
vm_instance_t *vm; |
409 |
|
410 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
411 |
return(-1); |
412 |
|
413 |
vm->conf_reg_setup = strtol(argv[1],NULL,0); |
414 |
vm_release(vm); |
415 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
416 |
return(0); |
417 |
} |
418 |
|
419 |
/* Set TCP port for console */ |
420 |
static int cmd_set_con_tcp_port(hypervisor_conn_t *conn,int argc,char *argv[]) |
421 |
{ |
422 |
vm_instance_t *vm; |
423 |
|
424 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
425 |
return(-1); |
426 |
|
427 |
vm->vtty_con_type = VTTY_TYPE_TCP; |
428 |
vm->vtty_con_tcp_port = atoi(argv[1]); |
429 |
|
430 |
vm_release(vm); |
431 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
432 |
return(0); |
433 |
} |
434 |
|
435 |
/* Set TCP port for AUX port */ |
436 |
static int cmd_set_aux_tcp_port(hypervisor_conn_t *conn,int argc,char *argv[]) |
437 |
{ |
438 |
vm_instance_t *vm; |
439 |
|
440 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
441 |
return(-1); |
442 |
|
443 |
vm->vtty_aux_type = VTTY_TYPE_TCP; |
444 |
vm->vtty_aux_tcp_port = atoi(argv[1]); |
445 |
|
446 |
vm_release(vm); |
447 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
448 |
return(0); |
449 |
} |
450 |
|
451 |
/* Read an IOS configuration file from a given router */ |
452 |
static int cmd_extract_config(hypervisor_conn_t *conn,int argc,char *argv[]) |
453 |
{ |
454 |
vm_instance_t *vm; |
455 |
char *cfg_buffer,*cfg_base64; |
456 |
ssize_t cfg_len; |
457 |
|
458 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
459 |
return(-1); |
460 |
|
461 |
if (!vm->nvram_extract_config) |
462 |
goto err_no_extract_method; |
463 |
|
464 |
/* Extract the IOS configuration */ |
465 |
if (((cfg_len = vm->nvram_extract_config(vm,&cfg_buffer)) < 0) || |
466 |
(cfg_buffer == NULL)) |
467 |
goto err_nvram_extract; |
468 |
|
469 |
/* |
470 |
* Convert config to base64. base64 is about 1/3 larger than input, |
471 |
* let's be on the safe side with twice longer. |
472 |
*/ |
473 |
if (!(cfg_base64 = malloc(cfg_len * 2))) |
474 |
goto err_alloc_base64; |
475 |
|
476 |
base64_encode(cfg_base64,cfg_buffer,cfg_len); |
477 |
|
478 |
vm_release(vm); |
479 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"conf '%s' %s",argv[0],cfg_base64); |
480 |
|
481 |
free(cfg_buffer); |
482 |
free(cfg_base64); |
483 |
return(0); |
484 |
|
485 |
err_alloc_base64: |
486 |
free(cfg_buffer); |
487 |
err_nvram_extract: |
488 |
err_no_extract_method: |
489 |
vm_release(vm); |
490 |
hypervisor_send_reply(conn,HSC_ERR_CREATE,1, |
491 |
"unable to extract config of VM '%s'",argv[0]); |
492 |
return(-1); |
493 |
} |
494 |
|
495 |
/* Push an IOS configuration file */ |
496 |
static int cmd_push_config(hypervisor_conn_t *conn,int argc,char *argv[]) |
497 |
{ |
498 |
vm_instance_t *vm; |
499 |
char *cfg_buffer; |
500 |
ssize_t len; |
501 |
|
502 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
503 |
return(-1); |
504 |
|
505 |
if (!vm->nvram_push_config) |
506 |
goto err_no_push_method; |
507 |
|
508 |
/* Convert base64 input to standard text */ |
509 |
if (!(cfg_buffer = malloc(3 * strlen(argv[1])))) |
510 |
goto err_alloc_base64; |
511 |
|
512 |
if ((len = base64_decode(cfg_buffer,argv[1],0)) < 0) |
513 |
goto err_decode_base64; |
514 |
|
515 |
/* Push configuration */ |
516 |
if (vm->nvram_push_config(vm,cfg_buffer,len) < 0) |
517 |
goto err_nvram_push; |
518 |
|
519 |
free(cfg_buffer); |
520 |
vm_release(vm); |
521 |
hypervisor_send_reply(conn,HSC_INFO_OK,1, |
522 |
"IOS config file pushed tm VM '%s'", |
523 |
argv[0]); |
524 |
return(0); |
525 |
|
526 |
err_nvram_push: |
527 |
err_decode_base64: |
528 |
free(cfg_buffer); |
529 |
err_alloc_base64: |
530 |
err_no_push_method: |
531 |
vm_release(vm); |
532 |
hypervisor_send_reply(conn,HSC_ERR_CREATE,1, |
533 |
"unable to push IOS config for VM '%s'", |
534 |
argv[0]); |
535 |
return(-1); |
536 |
} |
537 |
|
538 |
/* Show info about the specified CPU */ |
539 |
static int cmd_show_cpu_info(hypervisor_conn_t *conn,int argc,char *argv[]) |
540 |
{ |
541 |
vm_instance_t *vm; |
542 |
cpu_mips_t *cpu; |
543 |
|
544 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
545 |
return(-1); |
546 |
|
547 |
cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1])); |
548 |
|
549 |
if (cpu) { |
550 |
mips64_dump_regs(cpu); |
551 |
tlb_dump(cpu); |
552 |
} |
553 |
|
554 |
vm_release(vm); |
555 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
556 |
return(0); |
557 |
} |
558 |
|
559 |
/* Suspend a VM instance */ |
560 |
static int cmd_suspend(hypervisor_conn_t *conn,int argc,char *argv[]) |
561 |
{ |
562 |
vm_instance_t *vm; |
563 |
|
564 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
565 |
return(-1); |
566 |
|
567 |
vm_suspend(vm); |
568 |
|
569 |
vm_release(vm); |
570 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"VM '%s' suspended",argv[0]); |
571 |
return(0); |
572 |
} |
573 |
|
574 |
/* Resume a VM instance */ |
575 |
static int cmd_resume(hypervisor_conn_t *conn,int argc,char *argv[]) |
576 |
{ |
577 |
vm_instance_t *vm; |
578 |
|
579 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
580 |
return(-1); |
581 |
|
582 |
vm_resume(vm); |
583 |
|
584 |
vm_release(vm); |
585 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"VM '%s' resumed",argv[0]); |
586 |
return(0); |
587 |
} |
588 |
|
589 |
/* Send a message on the console */ |
590 |
static int cmd_send_con_msg(hypervisor_conn_t *conn,int argc,char *argv[]) |
591 |
{ |
592 |
vm_instance_t *vm; |
593 |
|
594 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
595 |
return(-1); |
596 |
|
597 |
vtty_store_str(vm->vtty_con,argv[1]); |
598 |
|
599 |
vm_release(vm); |
600 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
601 |
return(0); |
602 |
} |
603 |
|
604 |
/* Send a message on the AUX port */ |
605 |
static int cmd_send_aux_msg(hypervisor_conn_t *conn,int argc,char *argv[]) |
606 |
{ |
607 |
vm_instance_t *vm; |
608 |
|
609 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
610 |
return(-1); |
611 |
|
612 |
vtty_store_str(vm->vtty_aux,argv[1]); |
613 |
|
614 |
vm_release(vm); |
615 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
616 |
return(0); |
617 |
} |
618 |
|
619 |
/* Show info about VM object */ |
620 |
static void cmd_show_vm_list(registry_entry_t *entry,void *opt,int *err) |
621 |
{ |
622 |
hypervisor_conn_t *conn = opt; |
623 |
vm_instance_t *vm = entry->data; |
624 |
|
625 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s (%s)", |
626 |
entry->name,vm_get_type(vm)); |
627 |
} |
628 |
|
629 |
/* VM List */ |
630 |
static int cmd_vm_list(hypervisor_conn_t *conn,int argc,char *argv[]) |
631 |
{ |
632 |
int err = 0; |
633 |
registry_foreach_type(OBJ_TYPE_VM,cmd_show_vm_list,conn,&err); |
634 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
635 |
return(0); |
636 |
} |
637 |
|
638 |
/* VM commands */ |
639 |
static hypervisor_cmd_t vm_cmd_array[] = { |
640 |
{ "set_debug_level", 2, 2, cmd_set_debug_level, NULL }, |
641 |
{ "set_ios", 2, 2, cmd_set_ios, NULL }, |
642 |
{ "set_config", 2, 2, cmd_set_config, NULL }, |
643 |
{ "set_ram", 2, 2, cmd_set_ram, NULL }, |
644 |
{ "set_nvram", 2, 2, cmd_set_nvram, NULL }, |
645 |
{ "set_ram_mmap", 2, 2, cmd_set_ram_mmap, NULL }, |
646 |
{ "set_clock_divisor", 2, 2, cmd_set_clock_divisor, NULL }, |
647 |
{ "set_exec_area", 2, 2, cmd_set_exec_area, NULL }, |
648 |
{ "set_disk0", 2, 2, cmd_set_disk0, NULL }, |
649 |
{ "set_disk1", 2, 2, cmd_set_disk1, NULL }, |
650 |
{ "set_conf_reg", 2, 2, cmd_set_conf_reg, NULL }, |
651 |
{ "set_idle_pc", 2, 2, cmd_set_idle_pc, NULL }, |
652 |
{ "set_idle_pc_online", 3, 3, cmd_set_idle_pc_online, NULL }, |
653 |
{ "get_idle_pc_prop", 2, 2, cmd_get_idle_pc_prop, NULL }, |
654 |
{ "show_idle_pc_prop", 2, 2, cmd_show_idle_pc_prop, NULL }, |
655 |
{ "set_idle_max", 3, 3, cmd_set_idle_max, NULL }, |
656 |
{ "set_idle_sleep_time", 3, 3, cmd_set_idle_sleep_time, NULL }, |
657 |
{ "show_timer_drift", 2, 2, cmd_show_timer_drift, NULL }, |
658 |
{ "set_ghost_file", 3, 3, cmd_set_ghost_file, NULL }, |
659 |
{ "set_ghost_status", 3, 3, cmd_set_ghost_status, NULL }, |
660 |
{ "set_con_tcp_port", 2, 2, cmd_set_con_tcp_port, NULL }, |
661 |
{ "set_aux_tcp_port", 2, 2, cmd_set_aux_tcp_port, NULL }, |
662 |
{ "extract_config", 1, 1, cmd_extract_config, NULL }, |
663 |
{ "push_config", 2, 2, cmd_push_config, NULL }, |
664 |
{ "cpu_info", 2, 2, cmd_show_cpu_info, NULL }, |
665 |
{ "suspend", 1, 1, cmd_suspend, NULL }, |
666 |
{ "resume", 1, 1, cmd_resume, NULL }, |
667 |
{ "send_con_msg", 2, 2, cmd_send_con_msg, NULL }, |
668 |
{ "send_aux_msg", 2, 2, cmd_send_aux_msg, NULL }, |
669 |
{ "list", 0, 0, cmd_vm_list, NULL }, |
670 |
{ NULL, -1, -1, NULL, NULL }, |
671 |
}; |
672 |
|
673 |
/* Hypervisor VM initialization */ |
674 |
int hypervisor_vm_init(void) |
675 |
{ |
676 |
hypervisor_module_t *module; |
677 |
|
678 |
module = hypervisor_register_module("vm"); |
679 |
assert(module != NULL); |
680 |
|
681 |
hypervisor_register_cmd_array(module,vm_cmd_array); |
682 |
return(0); |
683 |
} |