60 |
return cpu; |
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 |
{ |
{ |
433 |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
434 |
return(-1); |
return(-1); |
435 |
|
|
436 |
if (cpu->type == CPU_TYPE_MIPS64) { |
switch(cpu->type) { |
437 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Timer Drift: %u", |
case CPU_TYPE_MIPS64: |
438 |
CPU_MIPS64(cpu)->timer_drift); |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Timer Drift: %u", |
439 |
|
CPU_MIPS64(cpu)->timer_drift); |
440 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Pending Timer IRQ: %u", |
|
441 |
CPU_MIPS64(cpu)->timer_irq_pending); |
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); |
vm_release(vm); |
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 |
|
|
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); |
744 |
return(0); |
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 |
{ |
{ |
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 }, |
1046 |
{ "resume", 1, 1, cmd_resume, NULL }, |
{ "resume", 1, 1, cmd_resume, NULL }, |
1047 |
{ "send_con_msg", 2, 2, cmd_send_con_msg, NULL }, |
{ "send_con_msg", 2, 2, cmd_send_con_msg, NULL }, |
1048 |
{ "send_aux_msg", 2, 2, cmd_send_aux_msg, NULL }, |
{ "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 }, |
{ "list_con_ports", 0, 0, cmd_vm_list_con_ports, NULL }, |
1059 |
{ NULL, -1, -1, NULL, NULL }, |
{ NULL, -1, -1, NULL, NULL }, |
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); |