debuggers.hg

view tools/libxc/xc_dom_compat_linux.c @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
parents 4ed3b9b1de3f
children 3ffdb094c2c0
line source
1 /*
2 * Xen domain builder -- compatibility code.
3 *
4 * Replacements for xc_linux_build & friends,
5 * as example code and to make the new builder
6 * usable as drop-in replacement.
7 *
8 * This code is licenced under the GPL.
9 * written 2006 by Gerd Hoffmann <kraxel@suse.de>.
10 *
11 */
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <inttypes.h>
16 #include <zlib.h>
18 #include "xenctrl.h"
19 #include "xg_private.h"
20 #include "xc_dom.h"
22 /* ------------------------------------------------------------------------ */
24 static int xc_linux_build_internal(struct xc_dom_image *dom,
25 int xc_handle, uint32_t domid,
26 unsigned int mem_mb,
27 unsigned long flags,
28 unsigned int store_evtchn,
29 unsigned long *store_mfn,
30 unsigned int console_evtchn,
31 unsigned long *console_mfn)
32 {
33 int rc;
35 dom->flags = flags;
36 dom->console_evtchn = console_evtchn;
37 dom->xenstore_evtchn = store_evtchn;
39 if ( (rc = xc_dom_boot_xen_init(dom, xc_handle, domid)) != 0 )
40 goto out;
41 if ( (rc = xc_dom_parse_image(dom)) != 0 )
42 goto out;
43 if ( (rc = xc_dom_mem_init(dom, mem_mb)) != 0 )
44 goto out;
45 if ( (rc = xc_dom_boot_mem_init(dom)) != 0 )
46 goto out;
47 if ( (rc = xc_dom_build_image(dom)) != 0 )
48 goto out;
49 if ( (rc = xc_dom_boot_image(dom)) != 0 )
50 goto out;
52 *console_mfn = xc_dom_p2m_host(dom, dom->console_pfn);
53 *store_mfn = xc_dom_p2m_host(dom, dom->xenstore_pfn);
55 out:
56 return rc;
57 }
59 int xc_linux_build_mem(int xc_handle, uint32_t domid,
60 unsigned int mem_mb,
61 const char *image_buffer,
62 unsigned long image_size,
63 const char *initrd,
64 unsigned long initrd_len,
65 const char *cmdline,
66 const char *features,
67 unsigned long flags,
68 unsigned int store_evtchn,
69 unsigned long *store_mfn,
70 unsigned int console_evtchn,
71 unsigned long *console_mfn)
72 {
73 struct xc_dom_image *dom;
74 int rc;
76 xc_dom_loginit();
77 dom = xc_dom_allocate(cmdline, features);
78 if ( (rc = xc_dom_kernel_mem(dom, image_buffer, image_size)) != 0 )
79 goto out;
80 if ( initrd && ((rc = xc_dom_ramdisk_mem(dom, initrd, initrd_len)) != 0) )
81 goto out;
83 rc = xc_linux_build_internal(dom, xc_handle, domid,
84 mem_mb, flags,
85 store_evtchn, store_mfn,
86 console_evtchn, console_mfn);
88 out:
89 xc_dom_release(dom);
90 return rc;
91 }
93 int xc_linux_build(int xc_handle, uint32_t domid,
94 unsigned int mem_mb,
95 const char *image_name,
96 const char *initrd_name,
97 const char *cmdline,
98 const char *features,
99 unsigned long flags,
100 unsigned int store_evtchn,
101 unsigned long *store_mfn,
102 unsigned int console_evtchn,
103 unsigned long *console_mfn)
104 {
105 struct xc_dom_image *dom;
106 int rc;
108 xc_dom_loginit();
109 dom = xc_dom_allocate(cmdline, features);
110 if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
111 goto out;
112 if ( initrd_name && strlen(initrd_name) &&
113 ((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) )
114 goto out;
116 rc = xc_linux_build_internal(dom, xc_handle, domid,
117 mem_mb, flags,
118 store_evtchn, store_mfn,
119 console_evtchn, console_mfn);
121 out:
122 xc_dom_release(dom);
123 return rc;
124 }
125 int xc_get_bit_size(const char *image_name, const char *cmdline,
126 const char *features, int *bit_size)
127 {
128 struct xc_dom_image *dom;
129 int rc;
130 *bit_size = 0;
131 dom = xc_dom_allocate(cmdline, features);
132 if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
133 goto out;
134 if ( (rc = xc_dom_parse_image(dom)) != 0 )
135 goto out;
136 if( dom->guest_type != NULL){
137 if(strstr(dom->guest_type, "x86_64") != NULL)
138 *bit_size = X86_64_B_SIZE; //64bit Guest
139 if(strstr(dom->guest_type, "x86_32") != NULL)
140 *bit_size = X86_32_B_SIZE; //32bit Guest
141 }
143 out:
144 xc_dom_release(dom);
145 return rc;
146 }
148 int xc_dom_linux_build(int xc_handle,
149 struct xc_dom_image *dom,
150 uint32_t domid,
151 unsigned int mem_mb,
152 const char *image_name,
153 const char *initrd_name,
154 unsigned long flags,
155 unsigned int store_evtchn,
156 unsigned long *store_mfn,
157 unsigned int console_evtchn, unsigned long *console_mfn)
158 {
159 int rc;
161 if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
162 return rc;
163 if ( initrd_name && strlen(initrd_name) &&
164 ((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) )
165 return rc;
167 return xc_linux_build_internal(dom, xc_handle, domid,
168 mem_mb, flags,
169 store_evtchn, store_mfn,
170 console_evtchn, console_mfn);
171 }
173 /*
174 * Local variables:
175 * mode: C
176 * c-set-style: "BSD"
177 * c-basic-offset: 4
178 * tab-width: 4
179 * indent-tabs-mode: nil
180 * End:
181 */