/[dynamips]/trunk/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

Diff of /trunk/hv_vm.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/dynamips-0.2.6-RC1/hv_vm.c revision 2 by dpavlin, Sat Oct 6 16:03:58 2007 UTC upstream/dynamips-0.2.8-RC1/hv_vm.c revision 11 by dpavlin, Sat Oct 6 16:33:40 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   * Cisco 7200 (Predator) simulation platform.   * Cisco router simulation platform.
3   * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)   * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4   *   *
5   * Hypervisor generic VM routines.   * Hypervisor generic VM routines.
# Line 23  Line 23 
23  #include <arpa/inet.h>  #include <arpa/inet.h>
24  #include <pthread.h>  #include <pthread.h>
25    
26  #include "mips64.h"  #include "cpu.h"
27  #include "cp0.h"  #include "vm.h"
28  #include "dynamips.h"  #include "dynamips.h"
29  #include "device.h"  #include "device.h"
30  #include "dev_c7200.h"  #include "dev_c7200.h"
# Line 43  Line 43 
43  #include "registry.h"  #include "registry.h"
44  #include "hypervisor.h"  #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 */  /* Set debugging level */
149  static int cmd_set_debug_level(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_debug_level(hypervisor_conn_t *conn,int argc,char *argv[])
150  {  {
# Line 146  static int cmd_set_ram_mmap(hypervisor_c Line 248  static int cmd_set_ram_mmap(hypervisor_c
248     return(0);     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 */  /* Set the clock divisor */
267  static int cmd_set_clock_divisor(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_clock_divisor(hypervisor_conn_t *conn,int argc,char *argv[])
268  {  {
# Line 163  static int cmd_set_clock_divisor(hypervi Line 280  static int cmd_set_clock_divisor(hypervi
280     return(0);     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 */  /* Set the idle PC */
300  static int cmd_set_idle_pc(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_idle_pc(hypervisor_conn_t *conn,int argc,char *argv[])
301  {  {
# Line 178  static int cmd_set_idle_pc(hypervisor_co Line 311  static int cmd_set_idle_pc(hypervisor_co
311     return(0);     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 */  /* Set the exec area size */
460  static int cmd_set_exec_area(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_exec_area(hypervisor_conn_t *conn,int argc,char *argv[])
461  {  {
# Line 193  static int cmd_set_exec_area(hypervisor_ Line 471  static int cmd_set_exec_area(hypervisor_
471     return(0);     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 */  /* Set PCMCIA ATA disk0 size */
506  static int cmd_set_disk0(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_disk0(hypervisor_conn_t *conn,int argc,char *argv[])
507  {  {
# Line 271  static int cmd_set_aux_tcp_port(hypervis Line 580  static int cmd_set_aux_tcp_port(hypervis
580  static int cmd_extract_config(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_extract_config(hypervisor_conn_t *conn,int argc,char *argv[])
581  {  {
582     vm_instance_t *vm;     vm_instance_t *vm;
583     char *cfg_buffer,*cfg_base64;     u_char *cfg_buffer,*cfg_base64;
584     ssize_t cfg_len;     ssize_t cfg_len;
585    
586     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
587        return(-1);        return(-1);
588    
589     if (!vm->nvram_extract_config)     if (!vm->platform->nvram_extract_config)
590        goto err_no_extract_method;        goto err_no_extract_method;
591    
592     /* Extract the IOS configuration */     /* Extract the IOS configuration */
593     if (((cfg_len = vm->nvram_extract_config(vm,&cfg_buffer)) < 0) ||     if (((cfg_len = vm->platform->nvram_extract_config(vm,&cfg_buffer)) < 0) ||
594         (cfg_buffer == NULL))         (cfg_buffer == NULL))
595        goto err_nvram_extract;        goto err_nvram_extract;
596    
# Line 315  static int cmd_extract_config(hypervisor Line 624  static int cmd_extract_config(hypervisor
624  static int cmd_push_config(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_push_config(hypervisor_conn_t *conn,int argc,char *argv[])
625  {  {
626     vm_instance_t *vm;     vm_instance_t *vm;
627     char *cfg_buffer;     u_char *cfg_buffer;
628     ssize_t len;     ssize_t len;
629    
630     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
631        return(-1);        return(-1);
632    
633     if (!vm->nvram_push_config)     if (!vm->platform->nvram_push_config)
634        goto err_no_push_method;        goto err_no_push_method;
635    
636     /* Convert base64 input to standard text */     /* Convert base64 input to standard text */
637     if (!(cfg_buffer = malloc(3 * strlen(argv[1]))))     if (!(cfg_buffer = malloc(3 * strlen(argv[1]))))
638        goto err_alloc_base64;        goto err_alloc_base64;
639    
640     if ((len = base64_decode(cfg_buffer,argv[1],0)) < 0)     if ((len = base64_decode(cfg_buffer,(u_char *)argv[1],0)) < 0)
641        goto err_decode_base64;        goto err_decode_base64;
642    
643     /* Push configuration */     /* Push configuration */
644     if (vm->nvram_push_config(vm,cfg_buffer,len) < 0)     if (vm->platform->nvram_push_config(vm,cfg_buffer,len) < 0)
645        goto err_nvram_push;        goto err_nvram_push;
646    
647     free(cfg_buffer);     free(cfg_buffer);
# Line 358  static int cmd_push_config(hypervisor_co Line 667  static int cmd_push_config(hypervisor_co
667  static int cmd_show_cpu_info(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_show_cpu_info(hypervisor_conn_t *conn,int argc,char *argv[])
668  {  {
669     vm_instance_t *vm;     vm_instance_t *vm;
670     cpu_mips_t *cpu;     cpu_gen_t *cpu;
671    
672     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
673        return(-1);        return(-1);
# Line 366  static int cmd_show_cpu_info(hypervisor_ Line 675  static int cmd_show_cpu_info(hypervisor_
675     cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]));     cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]));
676    
677     if (cpu) {     if (cpu) {
678        mips64_dump_regs(cpu);        cpu->reg_dump(cpu);
679        tlb_dump(cpu);        cpu->mmu_dump(cpu);
680     }     }
681    
682     vm_release(vm);     vm_release(vm);
# Line 405  static int cmd_resume(hypervisor_conn_t Line 714  static int cmd_resume(hypervisor_conn_t
714     return(0);     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 */  /* Show info about VM object */
973  static void cmd_show_vm_list(registry_entry_t *entry,void *opt,int *err)  static void cmd_show_vm_list(registry_entry_t *entry,void *opt,int *err)
974  {  {
# Line 424  static int cmd_vm_list(hypervisor_conn_t Line 988  static int cmd_vm_list(hypervisor_conn_t
988     return(0);     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 */  /* VM commands */
1013  static hypervisor_cmd_t vm_cmd_array[] = {  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 },     { "set_debug_level", 2, 2, cmd_set_debug_level, NULL },
1019     { "set_ios", 2, 2, cmd_set_ios, NULL },     { "set_ios", 2, 2, cmd_set_ios, NULL },
1020     { "set_config", 2, 2, cmd_set_config, NULL },     { "set_config", 2, 2, cmd_set_config, NULL },
1021     { "set_ram", 2, 2, cmd_set_ram, NULL },     { "set_ram", 2, 2, cmd_set_ram, NULL },
1022     { "set_nvram", 2, 2, cmd_set_nvram, NULL },     { "set_nvram", 2, 2, cmd_set_nvram, NULL },
1023     { "set_ram_mmap", 2, 2, cmd_set_ram_mmap, NULL },     { "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 },     { "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 },     { "set_exec_area", 2, 2, cmd_set_exec_area, NULL },
1028     { "set_disk0", 2, 2, cmd_set_disk0, NULL },     { "set_disk0", 2, 2, cmd_set_disk0, NULL },
1029     { "set_disk1", 2, 2, cmd_set_disk1, NULL },     { "set_disk1", 2, 2, cmd_set_disk1, NULL },
1030     { "set_conf_reg", 2, 2, cmd_set_conf_reg, NULL },     { "set_conf_reg", 2, 2, cmd_set_conf_reg, NULL },
1031     { "set_idle_pc", 2, 2, cmd_set_idle_pc, NULL },     { "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 },     { "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 },     { "set_aux_tcp_port", 2, 2, cmd_set_aux_tcp_port, NULL },
1042     { "extract_config", 1, 1, cmd_extract_config, NULL },     { "extract_config", 1, 1, cmd_extract_config, NULL },
# Line 445  static hypervisor_cmd_t vm_cmd_array[] = Line 1044  static hypervisor_cmd_t vm_cmd_array[] =
1044     { "cpu_info", 2, 2, cmd_show_cpu_info, NULL },     { "cpu_info", 2, 2, cmd_show_cpu_info, NULL },
1045     { "suspend", 1, 1, cmd_suspend, NULL },     { "suspend", 1, 1, cmd_suspend, NULL },
1046     { "resume", 1, 1, cmd_resume, NULL },     { "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 },     { "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 },     { NULL, -1, -1, NULL, NULL },
1060  };  };
1061    
# Line 454  int hypervisor_vm_init(void) Line 1064  int hypervisor_vm_init(void)
1064  {  {
1065     hypervisor_module_t *module;     hypervisor_module_t *module;
1066    
1067     module = hypervisor_register_module("vm");     module = hypervisor_register_module("vm",NULL);
1068     assert(module != NULL);     assert(module != NULL);
1069    
1070     hypervisor_register_cmd_array(module,vm_cmd_array);     hypervisor_register_cmd_array(module,vm_cmd_array);

Legend:
Removed from v.2  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26