/[dynamips]/upstream/dynamips-0.2.8-RC1/hv_vm.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/dynamips-0.2.8-RC1/hv_vm.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations)
Sat Oct 6 16:33:40 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 28484 byte(s)
dynamips-0.2.8-RC1

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 /* Create a VM instance */
64 static int cmd_create(hypervisor_conn_t *conn,int argc,char *argv[])
65 {
66 vm_instance_t *vm;
67
68 if (!(vm = vm_create_instance(argv[0],atoi(argv[1]),argv[2]))) {
69 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
70 "unable to create VM instance '%s'",
71 argv[0]);
72 return(-1);
73 }
74
75 vm->vtty_con_type = VTTY_TYPE_NONE;
76 vm->vtty_aux_type = VTTY_TYPE_NONE;
77
78 vm_release(vm);
79 hypervisor_send_reply(conn,HSC_INFO_OK,1,"VM '%s' created",argv[0]);
80 return(0);
81 }
82
83 /* Delete a VM instance */
84 static int cmd_delete(hypervisor_conn_t *conn,int argc,char *argv[])
85 {
86 int res;
87
88 res = vm_delete_instance(argv[0]);
89
90 if (res == 1) {
91 hypervisor_send_reply(conn,HSC_INFO_OK,1,"VM '%s' deleted",argv[0]);
92 } else {
93 hypervisor_send_reply(conn,HSC_ERR_DELETE,1,
94 "unable to delete VM '%s'",argv[0]);
95 }
96
97 return(res);
98 }
99
100 /* Start a VM instance */
101 static int cmd_start(hypervisor_conn_t *conn,int argc,char *argv[])
102 {
103 vm_instance_t *vm;
104
105 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
106 return(-1);
107
108 if (vm->vtty_con_type == VTTY_TYPE_NONE) {
109 hypervisor_send_reply(conn,HSC_INFO_MSG,0,
110 "Warning: no console port defined for "
111 "VM '%s'",argv[0]);
112 }
113
114 if (vm_init_instance(vm) == -1) {
115 vm_release(vm);
116 hypervisor_send_reply(conn,HSC_ERR_START,1,
117 "unable to start VM instance '%s'",
118 argv[0]);
119 return(-1);
120 }
121
122 vm_release(vm);
123 hypervisor_send_reply(conn,HSC_INFO_OK,1,"VM '%s' started",argv[0]);
124 return(0);
125 }
126
127 /* Stop a VM instance */
128 static int cmd_stop(hypervisor_conn_t *conn,int argc,char *argv[])
129 {
130 vm_instance_t *vm;
131
132 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
133 return(-1);
134
135 if (vm_stop_instance(vm) == -1) {
136 vm_release(vm);
137 hypervisor_send_reply(conn,HSC_ERR_STOP,1,
138 "unable to stop VM instance '%s'",
139 argv[0]);
140 return(-1);
141 }
142
143 vm_release(vm);
144 hypervisor_send_reply(conn,HSC_INFO_OK,1,"VM '%s' stopped",argv[0]);
145 return(0);
146 }
147
148 /* Set debugging level */
149 static int cmd_set_debug_level(hypervisor_conn_t *conn,int argc,char *argv[])
150 {
151 vm_instance_t *vm;
152
153 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
154 return(-1);
155
156 vm->debug_level = atoi(argv[1]);
157
158 vm_release(vm);
159 hypervisor_send_reply(conn,HSC_INFO_OK,1,"O",argv[0]);
160 return(0);
161 }
162
163 /* Set IOS image filename */
164 static int cmd_set_ios(hypervisor_conn_t *conn,int argc,char *argv[])
165 {
166 vm_instance_t *vm;
167
168 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
169 return(-1);
170
171 if (vm_ios_set_image(vm,argv[1]) == -1) {
172 vm_release(vm);
173 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
174 "unable to store IOS image name for router '%s'",
175 argv[0]);
176 return(-1);
177 }
178
179 vm_release(vm);
180 hypervisor_send_reply(conn,HSC_INFO_OK,1,"IOS image set for '%s'",argv[0]);
181 return(0);
182 }
183
184 /* Set IOS configuration filename to load at startup */
185 static int cmd_set_config(hypervisor_conn_t *conn,int argc,char *argv[])
186 {
187 vm_instance_t *vm;
188
189 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
190 return(-1);
191
192 if (vm_ios_set_config(vm,argv[1]) == -1) {
193 vm_release(vm);
194 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
195 "unable to store IOS config for router '%s'",
196 argv[0]);
197 return(-1);
198 }
199
200 vm_release(vm);
201 hypervisor_send_reply(conn,HSC_INFO_OK,1,"IOS config file set for '%s'",
202 argv[0]);
203 return(0);
204 }
205
206 /* Set RAM size */
207 static int cmd_set_ram(hypervisor_conn_t *conn,int argc,char *argv[])
208 {
209 vm_instance_t *vm;
210
211 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
212 return(-1);
213
214 vm->ram_size = atoi(argv[1]);
215
216 vm_release(vm);
217 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
218 return(0);
219 }
220
221 /* Set NVRAM size */
222 static int cmd_set_nvram(hypervisor_conn_t *conn,int argc,char *argv[])
223 {
224 vm_instance_t *vm;
225
226 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
227 return(-1);
228
229 vm->nvram_size = atoi(argv[1]);
230
231 vm_release(vm);
232 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
233 return(0);
234 }
235
236 /* Enable/disable use of a memory-mapped file to simulate RAM */
237 static int cmd_set_ram_mmap(hypervisor_conn_t *conn,int argc,char *argv[])
238 {
239 vm_instance_t *vm;
240
241 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
242 return(-1);
243
244 vm->ram_mmap = atoi(argv[1]);
245
246 vm_release(vm);
247 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
248 return(0);
249 }
250
251 /* Enable/disable use of sparse memory */
252 static int cmd_set_sparse_mem(hypervisor_conn_t *conn,int argc,char *argv[])
253 {
254 vm_instance_t *vm;
255
256 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
257 return(-1);
258
259 vm->sparse_mem = atoi(argv[1]);
260
261 vm_release(vm);
262 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
263 return(0);
264 }
265
266 /* Set the clock divisor */
267 static int cmd_set_clock_divisor(hypervisor_conn_t *conn,int argc,char *argv[])
268 {
269 vm_instance_t *vm;
270 u_int clock_div;
271
272 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
273 return(-1);
274
275 if ((clock_div = atoi(argv[1])) != 0)
276 vm->clock_divisor = clock_div;
277
278 vm_release(vm);
279 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
280 return(0);
281 }
282
283 /* Enable/disable use of block direct jump (compatibility option) */
284 static int cmd_set_blk_direct_jump(hypervisor_conn_t *conn,
285 int argc,char *argv[])
286 {
287 vm_instance_t *vm;
288
289 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
290 return(-1);
291
292 vm->exec_blk_direct_jump = atoi(argv[1]);
293
294 vm_release(vm);
295 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
296 return(0);
297 }
298
299 /* Set the idle PC */
300 static int cmd_set_idle_pc(hypervisor_conn_t *conn,int argc,char *argv[])
301 {
302 vm_instance_t *vm;
303
304 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
305 return(-1);
306
307 vm->idle_pc = strtoull(argv[1],NULL,0);
308
309 vm_release(vm);
310 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
311 return(0);
312 }
313
314 /* Set the idle PC value when the CPU is online */
315 static int cmd_set_idle_pc_online(hypervisor_conn_t *conn,
316 int argc,char *argv[])
317 {
318 vm_instance_t *vm;
319 cpu_gen_t *cpu;
320
321 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
322 return(-1);
323
324 if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
325 return(-1);
326
327 cpu->set_idle_pc(cpu,strtoull(argv[2],NULL,0));
328
329 vm_release(vm);
330 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
331 return(0);
332 }
333
334 /* Get the idle PC proposals */
335 static int cmd_get_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[])
336 {
337 vm_instance_t *vm;
338 cpu_gen_t *cpu;
339 int i;
340
341 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
342 return(-1);
343
344 if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
345 return(-1);
346
347 cpu->get_idling_pc(cpu);
348
349 for(i=0;i<cpu->idle_pc_prop_count;i++) {
350 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]",
351 cpu->idle_pc_prop[i].pc,
352 cpu->idle_pc_prop[i].count);
353 }
354
355 vm_release(vm);
356 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
357 return(0);
358 }
359
360 /* Dump the idle PC proposals */
361 static int cmd_show_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[])
362 {
363 vm_instance_t *vm;
364 cpu_gen_t *cpu;
365 int i;
366
367 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
368 return(-1);
369
370 if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
371 return(-1);
372
373 for(i=0;i<cpu->idle_pc_prop_count;i++) {
374 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]",
375 cpu->idle_pc_prop[i].pc,
376 cpu->idle_pc_prop[i].count);
377 }
378
379 vm_release(vm);
380 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
381 return(0);
382 }
383
384 /* Set CPU idle max value */
385 static int cmd_set_idle_max(hypervisor_conn_t *conn,int argc,char *argv[])
386 {
387 vm_instance_t *vm;
388 cpu_gen_t *cpu;
389
390 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
391 return(-1);
392
393 if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
394 return(-1);
395
396 cpu->idle_max = atoi(argv[2]);
397
398 vm_release(vm);
399 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
400 return(0);
401 }
402
403 /* Set CPU idle sleep time value */
404 static int cmd_set_idle_sleep_time(hypervisor_conn_t *conn,
405 int argc,char *argv[])
406 {
407 vm_instance_t *vm;
408 cpu_gen_t *cpu;
409
410 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
411 return(-1);
412
413 if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
414 return(-1);
415
416 cpu->idle_sleep_time = atoi(argv[2]);
417
418 vm_release(vm);
419 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
420 return(0);
421 }
422
423 /* Show info about potential timer drift */
424 static int cmd_show_timer_drift(hypervisor_conn_t *conn,
425 int argc,char *argv[])
426 {
427 vm_instance_t *vm;
428 cpu_gen_t *cpu;
429
430 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
431 return(-1);
432
433 if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
434 return(-1);
435
436 switch(cpu->type) {
437 case CPU_TYPE_MIPS64:
438 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Timer Drift: %u",
439 CPU_MIPS64(cpu)->timer_drift);
440
441 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Pending Timer IRQ: %u",
442 CPU_MIPS64(cpu)->timer_irq_pending);
443 break;
444
445 case CPU_TYPE_PPC32:
446 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Timer Drift: %u",
447 CPU_PPC32(cpu)->timer_drift);
448
449 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Pending Timer IRQ: %u",
450 CPU_PPC32(cpu)->timer_irq_pending);
451 break;
452 }
453
454 vm_release(vm);
455 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
456 return(0);
457 }
458
459 /* Set the exec area size */
460 static int cmd_set_exec_area(hypervisor_conn_t *conn,int argc,char *argv[])
461 {
462 vm_instance_t *vm;
463
464 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
465 return(-1);
466
467 vm->exec_area_size = atoi(argv[1]);
468
469 vm_release(vm);
470 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
471 return(0);
472 }
473
474 /* Set ghost RAM file */
475 static int cmd_set_ghost_file(hypervisor_conn_t *conn,int argc,char *argv[])
476 {
477 vm_instance_t *vm;
478
479 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
480 return(-1);
481
482 vm->ghost_ram_filename = strdup(argv[1]);
483
484 vm_release(vm);
485 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
486 return(0);
487 }
488
489 /* Set ghost RAM status */
490 static int cmd_set_ghost_status(hypervisor_conn_t *conn,int argc,char *argv[])
491 {
492 vm_instance_t *vm;
493
494 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
495 return(-1);
496
497 vm->ghost_status = atoi(argv[1]);
498
499 vm_release(vm);
500 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
501 return(0);
502 }
503
504
505 /* Set PCMCIA ATA disk0 size */
506 static int cmd_set_disk0(hypervisor_conn_t *conn,int argc,char *argv[])
507 {
508 vm_instance_t *vm;
509
510 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
511 return(-1);
512
513 vm->pcmcia_disk_size[0] = atoi(argv[1]);
514 vm_release(vm);
515 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
516 return(0);
517 }
518
519 /* Set PCMCIA ATA disk1 size */
520 static int cmd_set_disk1(hypervisor_conn_t *conn,int argc,char *argv[])
521 {
522 vm_instance_t *vm;
523
524 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
525 return(-1);
526
527 vm->pcmcia_disk_size[1] = atoi(argv[1]);
528 vm_release(vm);
529 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
530 return(0);
531 }
532
533 /* Set the config register used at startup */
534 static int cmd_set_conf_reg(hypervisor_conn_t *conn,int argc,char *argv[])
535 {
536 vm_instance_t *vm;
537
538 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
539 return(-1);
540
541 vm->conf_reg_setup = strtol(argv[1],NULL,0);
542 vm_release(vm);
543 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
544 return(0);
545 }
546
547 /* Set TCP port for console */
548 static int cmd_set_con_tcp_port(hypervisor_conn_t *conn,int argc,char *argv[])
549 {
550 vm_instance_t *vm;
551
552 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
553 return(-1);
554
555 vm->vtty_con_type = VTTY_TYPE_TCP;
556 vm->vtty_con_tcp_port = atoi(argv[1]);
557
558 vm_release(vm);
559 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
560 return(0);
561 }
562
563 /* Set TCP port for AUX port */
564 static int cmd_set_aux_tcp_port(hypervisor_conn_t *conn,int argc,char *argv[])
565 {
566 vm_instance_t *vm;
567
568 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
569 return(-1);
570
571 vm->vtty_aux_type = VTTY_TYPE_TCP;
572 vm->vtty_aux_tcp_port = atoi(argv[1]);
573
574 vm_release(vm);
575 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
576 return(0);
577 }
578
579 /* Read an IOS configuration file from a given router */
580 static int cmd_extract_config(hypervisor_conn_t *conn,int argc,char *argv[])
581 {
582 vm_instance_t *vm;
583 u_char *cfg_buffer,*cfg_base64;
584 ssize_t cfg_len;
585
586 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
587 return(-1);
588
589 if (!vm->platform->nvram_extract_config)
590 goto err_no_extract_method;
591
592 /* Extract the IOS configuration */
593 if (((cfg_len = vm->platform->nvram_extract_config(vm,&cfg_buffer)) < 0) ||
594 (cfg_buffer == NULL))
595 goto err_nvram_extract;
596
597 /*
598 * Convert config to base64. base64 is about 1/3 larger than input,
599 * let's be on the safe side with twice longer.
600 */
601 if (!(cfg_base64 = malloc(cfg_len * 2)))
602 goto err_alloc_base64;
603
604 base64_encode(cfg_base64,cfg_buffer,cfg_len);
605
606 vm_release(vm);
607 hypervisor_send_reply(conn,HSC_INFO_OK,1,"conf '%s' %s",argv[0],cfg_base64);
608
609 free(cfg_buffer);
610 free(cfg_base64);
611 return(0);
612
613 err_alloc_base64:
614 free(cfg_buffer);
615 err_nvram_extract:
616 err_no_extract_method:
617 vm_release(vm);
618 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
619 "unable to extract config of VM '%s'",argv[0]);
620 return(-1);
621 }
622
623 /* Push an IOS configuration file */
624 static int cmd_push_config(hypervisor_conn_t *conn,int argc,char *argv[])
625 {
626 vm_instance_t *vm;
627 u_char *cfg_buffer;
628 ssize_t len;
629
630 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
631 return(-1);
632
633 if (!vm->platform->nvram_push_config)
634 goto err_no_push_method;
635
636 /* Convert base64 input to standard text */
637 if (!(cfg_buffer = malloc(3 * strlen(argv[1]))))
638 goto err_alloc_base64;
639
640 if ((len = base64_decode(cfg_buffer,(u_char *)argv[1],0)) < 0)
641 goto err_decode_base64;
642
643 /* Push configuration */
644 if (vm->platform->nvram_push_config(vm,cfg_buffer,len) < 0)
645 goto err_nvram_push;
646
647 free(cfg_buffer);
648 vm_release(vm);
649 hypervisor_send_reply(conn,HSC_INFO_OK,1,
650 "IOS config file pushed tm VM '%s'",
651 argv[0]);
652 return(0);
653
654 err_nvram_push:
655 err_decode_base64:
656 free(cfg_buffer);
657 err_alloc_base64:
658 err_no_push_method:
659 vm_release(vm);
660 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
661 "unable to push IOS config for VM '%s'",
662 argv[0]);
663 return(-1);
664 }
665
666 /* Show info about the specified CPU */
667 static int cmd_show_cpu_info(hypervisor_conn_t *conn,int argc,char *argv[])
668 {
669 vm_instance_t *vm;
670 cpu_gen_t *cpu;
671
672 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
673 return(-1);
674
675 cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]));
676
677 if (cpu) {
678 cpu->reg_dump(cpu);
679 cpu->mmu_dump(cpu);
680 }
681
682 vm_release(vm);
683 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
684 return(0);
685 }
686
687 /* Suspend a VM instance */
688 static int cmd_suspend(hypervisor_conn_t *conn,int argc,char *argv[])
689 {
690 vm_instance_t *vm;
691
692 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
693 return(-1);
694
695 vm_suspend(vm);
696
697 vm_release(vm);
698 hypervisor_send_reply(conn,HSC_INFO_OK,1,"VM '%s' suspended",argv[0]);
699 return(0);
700 }
701
702 /* Resume a VM instance */
703 static int cmd_resume(hypervisor_conn_t *conn,int argc,char *argv[])
704 {
705 vm_instance_t *vm;
706
707 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
708 return(-1);
709
710 vm_resume(vm);
711
712 vm_release(vm);
713 hypervisor_send_reply(conn,HSC_INFO_OK,1,"VM '%s' resumed",argv[0]);
714 return(0);
715 }
716
717 /* Send a message on the console */
718 static int cmd_send_con_msg(hypervisor_conn_t *conn,int argc,char *argv[])
719 {
720 vm_instance_t *vm;
721
722 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
723 return(-1);
724
725 vtty_store_str(vm->vtty_con,argv[1]);
726
727 vm_release(vm);
728 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
729 return(0);
730 }
731
732 /* Send a message on the AUX port */
733 static int cmd_send_aux_msg(hypervisor_conn_t *conn,int argc,char *argv[])
734 {
735 vm_instance_t *vm;
736
737 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
738 return(-1);
739
740 vtty_store_str(vm->vtty_aux,argv[1]);
741
742 vm_release(vm);
743 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
744 return(0);
745 }
746
747
748 /* Show slot bindings */
749 static int cmd_slot_bindings(hypervisor_conn_t *conn,int argc,char *argv[])
750 {
751 struct cisco_card *card,*sc;
752 vm_instance_t *vm;
753 int i,j;
754
755 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
756 return(-1);
757
758 for(i=0;i<vm->nr_slots;i++) {
759 if (!(card = vm_slot_get_card_ptr(vm,i)))
760 continue;
761
762 /* main module */
763 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u/%u: %s",
764 card->slot_id,card->subslot_id,card->dev_type);
765
766 /* sub-slots */
767 for(j=0;j<CISCO_CARD_MAX_SUBSLOTS;j++) {
768 if (!(sc = card->sub_slots[j]))
769 continue;
770
771 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u/%u: %s",
772 card->slot_id,card->subslot_id,card->dev_type);
773 }
774 }
775
776 vm_release(vm);
777 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
778 return(0);
779 }
780
781 /* Show NIO bindings for the specified slot */
782 static int cmd_slot_nio_bindings(hypervisor_conn_t *conn,int argc,char *argv[])
783 {
784 struct cisco_nio_binding *nb;
785 struct cisco_card *card,*sc;
786 vm_instance_t *vm;
787 u_int i,slot;
788
789 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
790 return(-1);
791
792 slot = atoi(argv[1]);
793
794 if ((card = vm_slot_get_card_ptr(vm,slot)))
795 {
796 /* main module */
797 for(nb=card->nio_list;nb;nb=nb->next) {
798 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u: %s",
799 nb->port_id,nb->nio->name);
800 }
801
802 /* sub-slots */
803 for(i=0;i<CISCO_CARD_MAX_SUBSLOTS;i++) {
804 if (!(sc = card->sub_slots[i]))
805 continue;
806
807 for(nb=sc->nio_list;nb;nb=nb->next) {
808 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u: %s",
809 nb->port_id,nb->nio->name);
810 }
811 }
812 }
813
814 vm_release(vm);
815 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
816 return(0);
817 }
818
819 /* Add a slot binding */
820 static int cmd_slot_add_binding(hypervisor_conn_t *conn,int argc,char *argv[])
821 {
822 vm_instance_t *vm;
823 u_int slot,port;
824
825 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
826 return(-1);
827
828 slot = atoi(argv[1]);
829 port = atoi(argv[2]);
830
831 if (vm_slot_add_binding(vm,argv[3],slot,port) == -1) {
832 vm_release(vm);
833 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
834 "VM %s: unable to add binding for slot %u/%u",
835 argv[0],slot,port);
836 return(-1);
837 }
838
839 vm_release(vm);
840 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
841 return(0);
842 }
843
844 /* Remove a slot binding */
845 static int cmd_slot_remove_binding(hypervisor_conn_t *conn,
846 int argc,char *argv[])
847 {
848 vm_instance_t *vm;
849 u_int slot,port;
850
851 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
852 return(-1);
853
854 slot = atoi(argv[1]);
855 port = atoi(argv[2]);
856
857 if (vm_slot_remove_binding(vm,slot,port) == -1) {
858 vm_release(vm);
859 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
860 "VM %s: unable to remove binding for slot %u/%u",
861 argv[0],slot,port);
862 return(-1);
863 }
864
865 vm_release(vm);
866 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
867 return(0);
868 }
869
870 /* Add a NIO binding for a slot/port */
871 static int cmd_slot_add_nio_binding(hypervisor_conn_t *conn,
872 int argc,char *argv[])
873 {
874 vm_instance_t *vm;
875 u_int slot,port;
876
877 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
878 return(-1);
879
880 slot = atoi(argv[1]);
881 port = atoi(argv[2]);
882
883 if (vm_slot_add_nio_binding(vm,slot,port,argv[3]) == -1) {
884 vm_release(vm);
885 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
886 "VM %s: unable to add binding "
887 "for slot %u/%u",argv[0],slot,port);
888 return(-1);
889 }
890
891 vm_release(vm);
892 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
893 return(0);
894 }
895
896 /* Remove a NIO binding for a slot/port */
897 static int cmd_slot_remove_nio_binding(hypervisor_conn_t *conn,
898 int argc,char *argv[])
899 {
900 vm_instance_t *vm;
901 u_int slot,port;
902
903 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
904 return(-1);
905
906 slot = atoi(argv[1]);
907 port = atoi(argv[2]);
908
909 if (vm_slot_remove_nio_binding(vm,slot,port) == -1) {
910 vm_release(vm);
911 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
912 "VM %s: unable to remove NIO binding "
913 "for slot %u/%u",argv[0],slot,port);
914 return(-1);
915 }
916
917 vm_release(vm);
918 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
919 return(0);
920 }
921
922 /* Enable NIO of the specified slot/port */
923 static int cmd_slot_enable_nio(hypervisor_conn_t *conn,int argc,char *argv[])
924 {
925 vm_instance_t *vm;
926 u_int slot,port;
927
928 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
929 return(-1);
930
931 slot = atoi(argv[1]);
932 port = atoi(argv[2]);
933
934 if (vm_slot_enable_nio(vm,slot,port) == -1) {
935 vm_release(vm);
936 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
937 "VM %s: unable to enable NIO for slot %u/%u",
938 argv[0],slot,port);
939 return(-1);
940 }
941
942 vm_release(vm);
943 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
944 return(0);
945 }
946
947 /* Disable NIO of the specified slot/port */
948 static int cmd_slot_disable_nio(hypervisor_conn_t *conn,int argc,char *argv[])
949 {
950 vm_instance_t *vm;
951 u_int slot,port;
952
953 if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
954 return(-1);
955
956 slot = atoi(argv[1]);
957 port = atoi(argv[2]);
958
959 if (vm_slot_disable_nio(vm,slot,port) == -1) {
960 vm_release(vm);
961 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
962 "VM %s: unable to disable NIO for slot %u/%u",
963 argv[0],slot,port);
964 return(-1);
965 }
966
967 vm_release(vm);
968 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
969 return(0);
970 }
971
972 /* Show info about VM object */
973 static void cmd_show_vm_list(registry_entry_t *entry,void *opt,int *err)
974 {
975 hypervisor_conn_t *conn = opt;
976 vm_instance_t *vm = entry->data;
977
978 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s (%s)",
979 entry->name,vm_get_type(vm));
980 }
981
982 /* VM List */
983 static int cmd_vm_list(hypervisor_conn_t *conn,int argc,char *argv[])
984 {
985 int err = 0;
986 registry_foreach_type(OBJ_TYPE_VM,cmd_show_vm_list,conn,&err);
987 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
988 return(0);
989 }
990
991 /* Show console TCP port info about VM object */
992 static void cmd_show_vm_list_con_ports(registry_entry_t *entry,void *opt,
993 int *err)
994 {
995 hypervisor_conn_t *conn = opt;
996 vm_instance_t *vm = entry->data;
997
998 if (vm->vtty_con_type == VTTY_TYPE_TCP)
999 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s (%d)",
1000 vm->name,vm->vtty_con_tcp_port);
1001 }
1002
1003 /* VM console TCP port list */
1004 static int cmd_vm_list_con_ports(hypervisor_conn_t *conn,int argc,char *argv[])
1005 {
1006 int err = 0;
1007 registry_foreach_type(OBJ_TYPE_VM,cmd_show_vm_list_con_ports,conn,&err);
1008 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
1009 return(0);
1010 }
1011
1012 /* VM commands */
1013 static hypervisor_cmd_t vm_cmd_array[] = {
1014 { "create", 3, 3, cmd_create, NULL },
1015 { "delete", 1, 1, cmd_delete, NULL },
1016 { "start", 1, 1, cmd_start, NULL },
1017 { "stop", 1, 1, cmd_stop, NULL },
1018 { "set_debug_level", 2, 2, cmd_set_debug_level, NULL },
1019 { "set_ios", 2, 2, cmd_set_ios, NULL },
1020 { "set_config", 2, 2, cmd_set_config, NULL },
1021 { "set_ram", 2, 2, cmd_set_ram, NULL },
1022 { "set_nvram", 2, 2, cmd_set_nvram, NULL },
1023 { "set_ram_mmap", 2, 2, cmd_set_ram_mmap, NULL },
1024 { "set_sparse_mem", 2, 2, cmd_set_sparse_mem, NULL },
1025 { "set_clock_divisor", 2, 2, cmd_set_clock_divisor, NULL },
1026 { "set_blk_direct_jump", 2, 2, cmd_set_blk_direct_jump, NULL },
1027 { "set_exec_area", 2, 2, cmd_set_exec_area, NULL },
1028 { "set_disk0", 2, 2, cmd_set_disk0, NULL },
1029 { "set_disk1", 2, 2, cmd_set_disk1, NULL },
1030 { "set_conf_reg", 2, 2, cmd_set_conf_reg, NULL },
1031 { "set_idle_pc", 2, 2, cmd_set_idle_pc, NULL },
1032 { "set_idle_pc_online", 3, 3, cmd_set_idle_pc_online, NULL },
1033 { "get_idle_pc_prop", 2, 2, cmd_get_idle_pc_prop, NULL },
1034 { "show_idle_pc_prop", 2, 2, cmd_show_idle_pc_prop, NULL },
1035 { "set_idle_max", 3, 3, cmd_set_idle_max, NULL },
1036 { "set_idle_sleep_time", 3, 3, cmd_set_idle_sleep_time, NULL },
1037 { "show_timer_drift", 2, 2, cmd_show_timer_drift, NULL },
1038 { "set_ghost_file", 2, 2, cmd_set_ghost_file, NULL },
1039 { "set_ghost_status", 2, 2, cmd_set_ghost_status, NULL },
1040 { "set_con_tcp_port", 2, 2, cmd_set_con_tcp_port, NULL },
1041 { "set_aux_tcp_port", 2, 2, cmd_set_aux_tcp_port, NULL },
1042 { "extract_config", 1, 1, cmd_extract_config, NULL },
1043 { "push_config", 2, 2, cmd_push_config, NULL },
1044 { "cpu_info", 2, 2, cmd_show_cpu_info, NULL },
1045 { "suspend", 1, 1, cmd_suspend, NULL },
1046 { "resume", 1, 1, cmd_resume, NULL },
1047 { "send_con_msg", 2, 2, cmd_send_con_msg, NULL },
1048 { "send_aux_msg", 2, 2, cmd_send_aux_msg, NULL },
1049 { "slot_bindings", 1, 1, cmd_slot_bindings, NULL },
1050 { "slot_nio_bindings", 2, 2, cmd_slot_nio_bindings, NULL },
1051 { "slot_add_binding", 4, 4, cmd_slot_add_binding, NULL },
1052 { "slot_remove_binding", 3, 3, cmd_slot_remove_binding, NULL },
1053 { "slot_add_nio_binding", 4, 4, cmd_slot_add_nio_binding, NULL },
1054 { "slot_remove_nio_binding", 3, 3, cmd_slot_remove_nio_binding, NULL },
1055 { "slot_enable_nio", 3, 3, cmd_slot_enable_nio, NULL },
1056 { "slot_disable_nio", 3, 3, cmd_slot_disable_nio, NULL },
1057 { "list", 0, 0, cmd_vm_list, NULL },
1058 { "list_con_ports", 0, 0, cmd_vm_list_con_ports, NULL },
1059 { NULL, -1, -1, NULL, NULL },
1060 };
1061
1062 /* Hypervisor VM initialization */
1063 int hypervisor_vm_init(void)
1064 {
1065 hypervisor_module_t *module;
1066
1067 module = hypervisor_register_module("vm",NULL);
1068 assert(module != NULL);
1069
1070 hypervisor_register_cmd_array(module,vm_cmd_array);
1071 return(0);
1072 }

  ViewVC Help
Powered by ViewVC 1.1.26