1 |
/* |
2 |
* Cisco router 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 "cpu.h" |
27 |
#include "vm.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_gen_t *find_cpu(hypervisor_conn_t *conn,vm_instance_t *vm, |
48 |
u_int cpu_id) |
49 |
{ |
50 |
cpu_gen_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 |
/* Enable/disable use of sparse memory */ |
167 |
static int cmd_set_sparse_mem(hypervisor_conn_t *conn,int argc,char *argv[]) |
168 |
{ |
169 |
vm_instance_t *vm; |
170 |
|
171 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
172 |
return(-1); |
173 |
|
174 |
vm->sparse_mem = atoi(argv[1]); |
175 |
|
176 |
vm_release(vm); |
177 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
178 |
return(0); |
179 |
} |
180 |
|
181 |
/* Set the clock divisor */ |
182 |
static int cmd_set_clock_divisor(hypervisor_conn_t *conn,int argc,char *argv[]) |
183 |
{ |
184 |
vm_instance_t *vm; |
185 |
u_int clock_div; |
186 |
|
187 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
188 |
return(-1); |
189 |
|
190 |
if ((clock_div = atoi(argv[1])) != 0) |
191 |
vm->clock_divisor = clock_div; |
192 |
|
193 |
vm_release(vm); |
194 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
195 |
return(0); |
196 |
} |
197 |
|
198 |
/* Enable/disable use of block direct jump (compatibility option) */ |
199 |
static int cmd_set_blk_direct_jump(hypervisor_conn_t *conn, |
200 |
int argc,char *argv[]) |
201 |
{ |
202 |
vm_instance_t *vm; |
203 |
|
204 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
205 |
return(-1); |
206 |
|
207 |
vm->exec_blk_direct_jump = atoi(argv[1]); |
208 |
|
209 |
vm_release(vm); |
210 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
211 |
return(0); |
212 |
} |
213 |
|
214 |
/* Set the idle PC */ |
215 |
static int cmd_set_idle_pc(hypervisor_conn_t *conn,int argc,char *argv[]) |
216 |
{ |
217 |
vm_instance_t *vm; |
218 |
|
219 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
220 |
return(-1); |
221 |
|
222 |
vm->idle_pc = strtoull(argv[1],NULL,0); |
223 |
|
224 |
vm_release(vm); |
225 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
226 |
return(0); |
227 |
} |
228 |
|
229 |
/* Set the idle PC value when the CPU is online */ |
230 |
static int cmd_set_idle_pc_online(hypervisor_conn_t *conn, |
231 |
int argc,char *argv[]) |
232 |
{ |
233 |
vm_instance_t *vm; |
234 |
cpu_gen_t *cpu; |
235 |
|
236 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
237 |
return(-1); |
238 |
|
239 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
240 |
return(-1); |
241 |
|
242 |
cpu->set_idle_pc(cpu,strtoull(argv[2],NULL,0)); |
243 |
|
244 |
vm_release(vm); |
245 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
246 |
return(0); |
247 |
} |
248 |
|
249 |
/* Get the idle PC proposals */ |
250 |
static int cmd_get_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[]) |
251 |
{ |
252 |
vm_instance_t *vm; |
253 |
cpu_gen_t *cpu; |
254 |
int i; |
255 |
|
256 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
257 |
return(-1); |
258 |
|
259 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
260 |
return(-1); |
261 |
|
262 |
cpu->get_idling_pc(cpu); |
263 |
|
264 |
for(i=0;i<cpu->idle_pc_prop_count;i++) { |
265 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]", |
266 |
cpu->idle_pc_prop[i].pc, |
267 |
cpu->idle_pc_prop[i].count); |
268 |
} |
269 |
|
270 |
vm_release(vm); |
271 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
272 |
return(0); |
273 |
} |
274 |
|
275 |
/* Dump the idle PC proposals */ |
276 |
static int cmd_show_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[]) |
277 |
{ |
278 |
vm_instance_t *vm; |
279 |
cpu_gen_t *cpu; |
280 |
int i; |
281 |
|
282 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
283 |
return(-1); |
284 |
|
285 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
286 |
return(-1); |
287 |
|
288 |
for(i=0;i<cpu->idle_pc_prop_count;i++) { |
289 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]", |
290 |
cpu->idle_pc_prop[i].pc, |
291 |
cpu->idle_pc_prop[i].count); |
292 |
} |
293 |
|
294 |
vm_release(vm); |
295 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
296 |
return(0); |
297 |
} |
298 |
|
299 |
/* Set CPU idle max value */ |
300 |
static int cmd_set_idle_max(hypervisor_conn_t *conn,int argc,char *argv[]) |
301 |
{ |
302 |
vm_instance_t *vm; |
303 |
cpu_gen_t *cpu; |
304 |
|
305 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
306 |
return(-1); |
307 |
|
308 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
309 |
return(-1); |
310 |
|
311 |
cpu->idle_max = atoi(argv[2]); |
312 |
|
313 |
vm_release(vm); |
314 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
315 |
return(0); |
316 |
} |
317 |
|
318 |
/* Set CPU idle sleep time value */ |
319 |
static int cmd_set_idle_sleep_time(hypervisor_conn_t *conn, |
320 |
int argc,char *argv[]) |
321 |
{ |
322 |
vm_instance_t *vm; |
323 |
cpu_gen_t *cpu; |
324 |
|
325 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
326 |
return(-1); |
327 |
|
328 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
329 |
return(-1); |
330 |
|
331 |
cpu->idle_sleep_time = atoi(argv[2]); |
332 |
|
333 |
vm_release(vm); |
334 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
335 |
return(0); |
336 |
} |
337 |
|
338 |
/* Show info about potential timer drift */ |
339 |
static int cmd_show_timer_drift(hypervisor_conn_t *conn, |
340 |
int argc,char *argv[]) |
341 |
{ |
342 |
vm_instance_t *vm; |
343 |
cpu_gen_t *cpu; |
344 |
|
345 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
346 |
return(-1); |
347 |
|
348 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
349 |
return(-1); |
350 |
|
351 |
if (cpu->type == CPU_TYPE_MIPS64) { |
352 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Timer Drift: %u", |
353 |
CPU_MIPS64(cpu)->timer_drift); |
354 |
|
355 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Pending Timer IRQ: %u", |
356 |
CPU_MIPS64(cpu)->timer_irq_pending); |
357 |
} |
358 |
|
359 |
vm_release(vm); |
360 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
361 |
return(0); |
362 |
} |
363 |
|
364 |
/* Set the exec area size */ |
365 |
static int cmd_set_exec_area(hypervisor_conn_t *conn,int argc,char *argv[]) |
366 |
{ |
367 |
vm_instance_t *vm; |
368 |
|
369 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
370 |
return(-1); |
371 |
|
372 |
vm->exec_area_size = atoi(argv[1]); |
373 |
|
374 |
vm_release(vm); |
375 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
376 |
return(0); |
377 |
} |
378 |
|
379 |
/* Set ghost RAM file */ |
380 |
static int cmd_set_ghost_file(hypervisor_conn_t *conn,int argc,char *argv[]) |
381 |
{ |
382 |
vm_instance_t *vm; |
383 |
|
384 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
385 |
return(-1); |
386 |
|
387 |
vm->ghost_ram_filename = strdup(argv[1]); |
388 |
|
389 |
vm_release(vm); |
390 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
391 |
return(0); |
392 |
} |
393 |
|
394 |
/* Set ghost RAM status */ |
395 |
static int cmd_set_ghost_status(hypervisor_conn_t *conn,int argc,char *argv[]) |
396 |
{ |
397 |
vm_instance_t *vm; |
398 |
|
399 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
400 |
return(-1); |
401 |
|
402 |
vm->ghost_status = atoi(argv[1]); |
403 |
|
404 |
vm_release(vm); |
405 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
406 |
return(0); |
407 |
} |
408 |
|
409 |
|
410 |
/* Set PCMCIA ATA disk0 size */ |
411 |
static int cmd_set_disk0(hypervisor_conn_t *conn,int argc,char *argv[]) |
412 |
{ |
413 |
vm_instance_t *vm; |
414 |
|
415 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
416 |
return(-1); |
417 |
|
418 |
vm->pcmcia_disk_size[0] = atoi(argv[1]); |
419 |
vm_release(vm); |
420 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
421 |
return(0); |
422 |
} |
423 |
|
424 |
/* Set PCMCIA ATA disk1 size */ |
425 |
static int cmd_set_disk1(hypervisor_conn_t *conn,int argc,char *argv[]) |
426 |
{ |
427 |
vm_instance_t *vm; |
428 |
|
429 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
430 |
return(-1); |
431 |
|
432 |
vm->pcmcia_disk_size[1] = atoi(argv[1]); |
433 |
vm_release(vm); |
434 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
435 |
return(0); |
436 |
} |
437 |
|
438 |
/* Set the config register used at startup */ |
439 |
static int cmd_set_conf_reg(hypervisor_conn_t *conn,int argc,char *argv[]) |
440 |
{ |
441 |
vm_instance_t *vm; |
442 |
|
443 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
444 |
return(-1); |
445 |
|
446 |
vm->conf_reg_setup = strtol(argv[1],NULL,0); |
447 |
vm_release(vm); |
448 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
449 |
return(0); |
450 |
} |
451 |
|
452 |
/* Set TCP port for console */ |
453 |
static int cmd_set_con_tcp_port(hypervisor_conn_t *conn,int argc,char *argv[]) |
454 |
{ |
455 |
vm_instance_t *vm; |
456 |
|
457 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
458 |
return(-1); |
459 |
|
460 |
vm->vtty_con_type = VTTY_TYPE_TCP; |
461 |
vm->vtty_con_tcp_port = atoi(argv[1]); |
462 |
|
463 |
vm_release(vm); |
464 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
465 |
return(0); |
466 |
} |
467 |
|
468 |
/* Set TCP port for AUX port */ |
469 |
static int cmd_set_aux_tcp_port(hypervisor_conn_t *conn,int argc,char *argv[]) |
470 |
{ |
471 |
vm_instance_t *vm; |
472 |
|
473 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
474 |
return(-1); |
475 |
|
476 |
vm->vtty_aux_type = VTTY_TYPE_TCP; |
477 |
vm->vtty_aux_tcp_port = atoi(argv[1]); |
478 |
|
479 |
vm_release(vm); |
480 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
481 |
return(0); |
482 |
} |
483 |
|
484 |
/* Read an IOS configuration file from a given router */ |
485 |
static int cmd_extract_config(hypervisor_conn_t *conn,int argc,char *argv[]) |
486 |
{ |
487 |
vm_instance_t *vm; |
488 |
char *cfg_buffer,*cfg_base64; |
489 |
ssize_t cfg_len; |
490 |
|
491 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
492 |
return(-1); |
493 |
|
494 |
if (!vm->nvram_extract_config) |
495 |
goto err_no_extract_method; |
496 |
|
497 |
/* Extract the IOS configuration */ |
498 |
if (((cfg_len = vm->nvram_extract_config(vm,&cfg_buffer)) < 0) || |
499 |
(cfg_buffer == NULL)) |
500 |
goto err_nvram_extract; |
501 |
|
502 |
/* |
503 |
* Convert config to base64. base64 is about 1/3 larger than input, |
504 |
* let's be on the safe side with twice longer. |
505 |
*/ |
506 |
if (!(cfg_base64 = malloc(cfg_len * 2))) |
507 |
goto err_alloc_base64; |
508 |
|
509 |
base64_encode(cfg_base64,cfg_buffer,cfg_len); |
510 |
|
511 |
vm_release(vm); |
512 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"conf '%s' %s",argv[0],cfg_base64); |
513 |
|
514 |
free(cfg_buffer); |
515 |
free(cfg_base64); |
516 |
return(0); |
517 |
|
518 |
err_alloc_base64: |
519 |
free(cfg_buffer); |
520 |
err_nvram_extract: |
521 |
err_no_extract_method: |
522 |
vm_release(vm); |
523 |
hypervisor_send_reply(conn,HSC_ERR_CREATE,1, |
524 |
"unable to extract config of VM '%s'",argv[0]); |
525 |
return(-1); |
526 |
} |
527 |
|
528 |
/* Push an IOS configuration file */ |
529 |
static int cmd_push_config(hypervisor_conn_t *conn,int argc,char *argv[]) |
530 |
{ |
531 |
vm_instance_t *vm; |
532 |
char *cfg_buffer; |
533 |
ssize_t len; |
534 |
|
535 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
536 |
return(-1); |
537 |
|
538 |
if (!vm->nvram_push_config) |
539 |
goto err_no_push_method; |
540 |
|
541 |
/* Convert base64 input to standard text */ |
542 |
if (!(cfg_buffer = malloc(3 * strlen(argv[1])))) |
543 |
goto err_alloc_base64; |
544 |
|
545 |
if ((len = base64_decode(cfg_buffer,argv[1],0)) < 0) |
546 |
goto err_decode_base64; |
547 |
|
548 |
/* Push configuration */ |
549 |
if (vm->nvram_push_config(vm,cfg_buffer,len) < 0) |
550 |
goto err_nvram_push; |
551 |
|
552 |
free(cfg_buffer); |
553 |
vm_release(vm); |
554 |
hypervisor_send_reply(conn,HSC_INFO_OK,1, |
555 |
"IOS config file pushed tm VM '%s'", |
556 |
argv[0]); |
557 |
return(0); |
558 |
|
559 |
err_nvram_push: |
560 |
err_decode_base64: |
561 |
free(cfg_buffer); |
562 |
err_alloc_base64: |
563 |
err_no_push_method: |
564 |
vm_release(vm); |
565 |
hypervisor_send_reply(conn,HSC_ERR_CREATE,1, |
566 |
"unable to push IOS config for VM '%s'", |
567 |
argv[0]); |
568 |
return(-1); |
569 |
} |
570 |
|
571 |
/* Show info about the specified CPU */ |
572 |
static int cmd_show_cpu_info(hypervisor_conn_t *conn,int argc,char *argv[]) |
573 |
{ |
574 |
vm_instance_t *vm; |
575 |
cpu_gen_t *cpu; |
576 |
|
577 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
578 |
return(-1); |
579 |
|
580 |
cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1])); |
581 |
|
582 |
if (cpu) { |
583 |
cpu->reg_dump(cpu); |
584 |
cpu->mmu_dump(cpu); |
585 |
} |
586 |
|
587 |
vm_release(vm); |
588 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
589 |
return(0); |
590 |
} |
591 |
|
592 |
/* Suspend a VM instance */ |
593 |
static int cmd_suspend(hypervisor_conn_t *conn,int argc,char *argv[]) |
594 |
{ |
595 |
vm_instance_t *vm; |
596 |
|
597 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
598 |
return(-1); |
599 |
|
600 |
vm_suspend(vm); |
601 |
|
602 |
vm_release(vm); |
603 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"VM '%s' suspended",argv[0]); |
604 |
return(0); |
605 |
} |
606 |
|
607 |
/* Resume a VM instance */ |
608 |
static int cmd_resume(hypervisor_conn_t *conn,int argc,char *argv[]) |
609 |
{ |
610 |
vm_instance_t *vm; |
611 |
|
612 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
613 |
return(-1); |
614 |
|
615 |
vm_resume(vm); |
616 |
|
617 |
vm_release(vm); |
618 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"VM '%s' resumed",argv[0]); |
619 |
return(0); |
620 |
} |
621 |
|
622 |
/* Send a message on the console */ |
623 |
static int cmd_send_con_msg(hypervisor_conn_t *conn,int argc,char *argv[]) |
624 |
{ |
625 |
vm_instance_t *vm; |
626 |
|
627 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
628 |
return(-1); |
629 |
|
630 |
vtty_store_str(vm->vtty_con,argv[1]); |
631 |
|
632 |
vm_release(vm); |
633 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
634 |
return(0); |
635 |
} |
636 |
|
637 |
/* Send a message on the AUX port */ |
638 |
static int cmd_send_aux_msg(hypervisor_conn_t *conn,int argc,char *argv[]) |
639 |
{ |
640 |
vm_instance_t *vm; |
641 |
|
642 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
643 |
return(-1); |
644 |
|
645 |
vtty_store_str(vm->vtty_aux,argv[1]); |
646 |
|
647 |
vm_release(vm); |
648 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
649 |
return(0); |
650 |
} |
651 |
|
652 |
/* Show info about VM object */ |
653 |
static void cmd_show_vm_list(registry_entry_t *entry,void *opt,int *err) |
654 |
{ |
655 |
hypervisor_conn_t *conn = opt; |
656 |
vm_instance_t *vm = entry->data; |
657 |
|
658 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s (%s)", |
659 |
entry->name,vm_get_type(vm)); |
660 |
} |
661 |
|
662 |
/* VM List */ |
663 |
static int cmd_vm_list(hypervisor_conn_t *conn,int argc,char *argv[]) |
664 |
{ |
665 |
int err = 0; |
666 |
registry_foreach_type(OBJ_TYPE_VM,cmd_show_vm_list,conn,&err); |
667 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
668 |
return(0); |
669 |
} |
670 |
|
671 |
/* Show console TCP port info about VM object */ |
672 |
static void cmd_show_vm_list_con_ports(registry_entry_t *entry,void *opt, |
673 |
int *err) |
674 |
{ |
675 |
hypervisor_conn_t *conn = opt; |
676 |
vm_instance_t *vm = entry->data; |
677 |
|
678 |
if (vm->vtty_con_type == VTTY_TYPE_TCP) |
679 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s (%d)", |
680 |
vm->name,vm->vtty_con_tcp_port); |
681 |
} |
682 |
|
683 |
/* VM console TCP port list */ |
684 |
static int cmd_vm_list_con_ports(hypervisor_conn_t *conn,int argc,char *argv[]) |
685 |
{ |
686 |
int err = 0; |
687 |
registry_foreach_type(OBJ_TYPE_VM,cmd_show_vm_list_con_ports,conn,&err); |
688 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
689 |
return(0); |
690 |
} |
691 |
|
692 |
/* VM commands */ |
693 |
static hypervisor_cmd_t vm_cmd_array[] = { |
694 |
{ "set_debug_level", 2, 2, cmd_set_debug_level, NULL }, |
695 |
{ "set_ios", 2, 2, cmd_set_ios, NULL }, |
696 |
{ "set_config", 2, 2, cmd_set_config, NULL }, |
697 |
{ "set_ram", 2, 2, cmd_set_ram, NULL }, |
698 |
{ "set_nvram", 2, 2, cmd_set_nvram, NULL }, |
699 |
{ "set_ram_mmap", 2, 2, cmd_set_ram_mmap, NULL }, |
700 |
{ "set_sparse_mem", 2, 2, cmd_set_sparse_mem, NULL }, |
701 |
{ "set_clock_divisor", 2, 2, cmd_set_clock_divisor, NULL }, |
702 |
{ "set_blk_direct_jump", 2, 2, cmd_set_blk_direct_jump, NULL }, |
703 |
{ "set_exec_area", 2, 2, cmd_set_exec_area, NULL }, |
704 |
{ "set_disk0", 2, 2, cmd_set_disk0, NULL }, |
705 |
{ "set_disk1", 2, 2, cmd_set_disk1, NULL }, |
706 |
{ "set_conf_reg", 2, 2, cmd_set_conf_reg, NULL }, |
707 |
{ "set_idle_pc", 2, 2, cmd_set_idle_pc, NULL }, |
708 |
{ "set_idle_pc_online", 3, 3, cmd_set_idle_pc_online, NULL }, |
709 |
{ "get_idle_pc_prop", 2, 2, cmd_get_idle_pc_prop, NULL }, |
710 |
{ "show_idle_pc_prop", 2, 2, cmd_show_idle_pc_prop, NULL }, |
711 |
{ "set_idle_max", 3, 3, cmd_set_idle_max, NULL }, |
712 |
{ "set_idle_sleep_time", 3, 3, cmd_set_idle_sleep_time, NULL }, |
713 |
{ "show_timer_drift", 2, 2, cmd_show_timer_drift, NULL }, |
714 |
{ "set_ghost_file", 2, 2, cmd_set_ghost_file, NULL }, |
715 |
{ "set_ghost_status", 2, 2, cmd_set_ghost_status, NULL }, |
716 |
{ "set_con_tcp_port", 2, 2, cmd_set_con_tcp_port, NULL }, |
717 |
{ "set_aux_tcp_port", 2, 2, cmd_set_aux_tcp_port, NULL }, |
718 |
{ "extract_config", 1, 1, cmd_extract_config, NULL }, |
719 |
{ "push_config", 2, 2, cmd_push_config, NULL }, |
720 |
{ "cpu_info", 2, 2, cmd_show_cpu_info, NULL }, |
721 |
{ "suspend", 1, 1, cmd_suspend, NULL }, |
722 |
{ "resume", 1, 1, cmd_resume, NULL }, |
723 |
{ "send_con_msg", 2, 2, cmd_send_con_msg, NULL }, |
724 |
{ "send_aux_msg", 2, 2, cmd_send_aux_msg, NULL }, |
725 |
{ "list", 0, 0, cmd_vm_list, NULL }, |
726 |
{ "list_con_ports", 0, 0, cmd_vm_list_con_ports, NULL }, |
727 |
{ NULL, -1, -1, NULL, NULL }, |
728 |
}; |
729 |
|
730 |
/* Hypervisor VM initialization */ |
731 |
int hypervisor_vm_init(void) |
732 |
{ |
733 |
hypervisor_module_t *module; |
734 |
|
735 |
module = hypervisor_register_module("vm"); |
736 |
assert(module != NULL); |
737 |
|
738 |
hypervisor_register_cmd_array(module,vm_cmd_array); |
739 |
return(0); |
740 |
} |