ia64/xen-unstable
changeset 13824:7a50ba45bbf3
Improved the example to show creation of a VNC console, and the difference
between HVM and PV domains.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
between HVM and PV domains.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | Ewan Mellor <ewan@xensource.com> |
---|---|
date | Thu Feb 01 19:02:55 2007 +0000 (2007-02-01) |
parents | 0fb5df09de94 |
children | c3c7119a6178 |
files | tools/libxen/test/test_bindings.c |
line diff
1.1 --- a/tools/libxen/test/test_bindings.c Thu Feb 01 19:02:13 2007 +0000 1.2 +++ b/tools/libxen/test/test_bindings.c Thu Feb 01 19:02:55 2007 +0000 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2006 XenSource, Inc. 1.6 + * Copyright (c) 2006-2007 XenSource, Inc. 1.7 * 1.8 * This library is free software; you can redistribute it and/or 1.9 * modify it under the terms of the GNU Lesser General Public 1.10 @@ -29,6 +29,7 @@ 1.11 #include "xen_sr.h" 1.12 #include "xen_vbd.h" 1.13 #include "xen_vdi.h" 1.14 +#include "xen_console.h" 1.15 #include "xen_vm.h" 1.16 1.17 1.18 @@ -58,7 +59,7 @@ typedef struct 1.19 } xen_comms; 1.20 1.21 1.22 -static xen_vm create_new_vm(xen_session *session); 1.23 +static xen_vm create_new_vm(xen_session *session, bool hvm); 1.24 static void print_vm_power_state(xen_session *session, xen_vm vm); 1.25 1.26 1.27 @@ -245,7 +246,7 @@ int main(int argc, char **argv) 1.28 xen_string_string_map_free(versions); 1.29 1.30 1.31 - xen_vm new_vm = create_new_vm(session); 1.32 + xen_vm new_vm = create_new_vm(session, true); 1.33 if (!session->ok) 1.34 { 1.35 /* Error has been logged, just clean up. */ 1.36 @@ -275,15 +276,28 @@ int main(int argc, char **argv) 1.37 * allocation patterns can be used, as long as the allocation and free are 1.38 * paired correctly. 1.39 */ 1.40 -static xen_vm create_new_vm(xen_session *session) 1.41 +static xen_vm create_new_vm(xen_session *session, bool hvm) 1.42 { 1.43 xen_string_string_map *vcpus_params = xen_string_string_map_alloc(1); 1.44 vcpus_params->contents[0].key = strdup("weight"); 1.45 vcpus_params->contents[0].val = strdup("300"); 1.46 + 1.47 + xen_string_string_map *hvm_boot_params; 1.48 + if (hvm) 1.49 + { 1.50 + hvm_boot_params = xen_string_string_map_alloc(1); 1.51 + hvm_boot_params->contents[0].key = strdup("order"); 1.52 + hvm_boot_params->contents[0].val = strdup("cd"); 1.53 + } 1.54 + else 1.55 + { 1.56 + hvm_boot_params = NULL; 1.57 + } 1.58 + 1.59 xen_vm_record vm_record = 1.60 { 1.61 - .name_label = "NewVM", 1.62 - .name_description = "New VM Description", 1.63 + .name_label = hvm ? "NewHVM" : "NewPV", 1.64 + .name_description = hvm ? "New HVM VM" : "New PV VM", 1.65 .user_version = 1, 1.66 .is_a_template = false, 1.67 .memory_static_max = 256, 1.68 @@ -296,20 +310,17 @@ static xen_vm create_new_vm(xen_session 1.69 .actions_after_shutdown = XEN_ON_NORMAL_EXIT_DESTROY, 1.70 .actions_after_reboot = XEN_ON_NORMAL_EXIT_RESTART, 1.71 .actions_after_crash = XEN_ON_CRASH_BEHAVIOUR_PRESERVE, 1.72 - .hvm_boot_policy = NULL, 1.73 - .hvm_boot_params = NULL, 1.74 - .pv_bootloader = "pygrub", 1.75 - .pv_kernel = "/boot/vmlinuz-2.6.16.33-xen", 1.76 - .pv_ramdisk = "", 1.77 - .pv_args = "root=/dev/sda1 ro", 1.78 - .pv_bootloader_args = "" 1.79 + .hvm_boot_policy = hvm ? "BIOS order" : NULL, 1.80 + .hvm_boot_params = hvm ? hvm_boot_params : NULL, 1.81 + .pv_bootloader = hvm ? NULL : "pygrub", 1.82 + .pv_kernel = hvm ? NULL : "/boot/vmlinuz-2.6.16.33-xen", 1.83 }; 1.84 1.85 - 1.86 xen_vm vm; 1.87 xen_vm_create(session, &vm, &vm_record); 1.88 1.89 xen_string_string_map_free(vcpus_params); 1.90 + xen_string_string_map_free(hvm_boot_params); 1.91 1.92 if (!session->ok) 1.93 { 1.94 @@ -343,7 +354,6 @@ static xen_vm create_new_vm(xen_session 1.95 .sr = &sr_record, 1.96 .virtual_size = (1 << 21), // 1GiB / 512 bytes/sector 1.97 .sector_size = 512, 1.98 - .location = "file:/root/gentoo.amd64.img", 1.99 .type = XEN_VDI_TYPE_SYSTEM, 1.100 .sharable = false, 1.101 .read_only = false 1.102 @@ -373,7 +383,7 @@ static xen_vm create_new_vm(xen_session 1.103 { 1.104 .vm = &vm_record_opt, 1.105 .vdi = &vdi0_record_opt, 1.106 - .device = "sda1", 1.107 + .device = "xvda1", 1.108 .mode = XEN_VBD_MODE_RW, 1.109 .bootable = 1, 1.110 }; 1.111 @@ -390,13 +400,38 @@ static xen_vm create_new_vm(xen_session 1.112 return NULL; 1.113 } 1.114 1.115 + xen_console vnc_console = NULL; 1.116 + if (hvm) { 1.117 + xen_console_record vnc_console_record = 1.118 + { 1.119 + .protocol = XEN_CONSOLE_PROTOCOL_RFB, 1.120 + .vm = &vm_record_opt, 1.121 + }; 1.122 + 1.123 + if (!xen_console_create(session, &vnc_console, &vnc_console_record)) 1.124 + { 1.125 + fprintf(stderr, "VNC console creation failed.\n"); 1.126 + print_error(session); 1.127 + 1.128 + xen_vbd_free(vbd0); 1.129 + xen_vdi_free(vdi0); 1.130 + xen_sr_set_free(srs); 1.131 + xen_vm_free(vm); 1.132 + return NULL; 1.133 + } 1.134 + } 1.135 + 1.136 char *vm_uuid; 1.137 char *vdi0_uuid; 1.138 char *vbd0_uuid; 1.139 + char *vnc_uuid = NULL; 1.140 1.141 xen_vm_get_uuid(session, &vm_uuid, vm); 1.142 xen_vdi_get_uuid(session, &vdi0_uuid, vdi0); 1.143 xen_vbd_get_uuid(session, &vbd0_uuid, vbd0); 1.144 + if (hvm) { 1.145 + xen_console_get_uuid(session, &vnc_uuid, vnc_console); 1.146 + } 1.147 1.148 if (!session->ok) 1.149 { 1.150 @@ -406,22 +441,35 @@ static xen_vm create_new_vm(xen_session 1.151 xen_uuid_free(vm_uuid); 1.152 xen_uuid_free(vdi0_uuid); 1.153 xen_uuid_free(vbd0_uuid); 1.154 + xen_uuid_free(vnc_uuid); 1.155 xen_vbd_free(vbd0); 1.156 xen_vdi_free(vdi0); 1.157 + xen_console_free(vnc_console); 1.158 xen_sr_set_free(srs); 1.159 xen_vm_free(vm); 1.160 return NULL; 1.161 } 1.162 1.163 - fprintf(stderr, 1.164 - "Created a new VM, with UUID %s, VDI UUID %s, and VBD UUID %s.\n", 1.165 - vm_uuid, vdi0_uuid, vbd0_uuid); 1.166 + if (hvm) { 1.167 + fprintf(stderr, 1.168 + "Created a new HVM VM, with UUID %s, VDI UUID %s, VBD " 1.169 + "UUID %s, and VNC console UUID %s.\n", 1.170 + vm_uuid, vdi0_uuid, vbd0_uuid, vnc_uuid); 1.171 + } 1.172 + else { 1.173 + fprintf(stderr, 1.174 + "Created a new PV VM, with UUID %s, VDI UUID %s, and VBD " 1.175 + "UUID %s.\n", 1.176 + vm_uuid, vdi0_uuid, vbd0_uuid); 1.177 + } 1.178 1.179 xen_uuid_free(vm_uuid); 1.180 xen_uuid_free(vdi0_uuid); 1.181 xen_uuid_free(vbd0_uuid); 1.182 + xen_uuid_free(vnc_uuid); 1.183 xen_vbd_free(vbd0); 1.184 xen_vdi_free(vdi0); 1.185 + xen_console_free(vnc_console); 1.186 xen_sr_set_free(srs); 1.187 1.188 return vm;