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