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 library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation;
11  * version 2.1 of the License.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; If not, see <http://www.gnu.org/licenses/>.
20  *
21  * written 2006 by Gerd Hoffmann <kraxel@suse.de>.
22  *
23  */
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <inttypes.h>
29 #include <zlib.h>
30 
31 #include "xenctrl.h"
32 #include "xg_private.h"
33 
34 /* ------------------------------------------------------------------------ */
35 
xc_linux_build(xc_interface * xch,uint32_t domid,unsigned int mem_mb,const char * image_name,const char * initrd_name,const char * cmdline,const char * features,unsigned long flags,unsigned int store_evtchn,unsigned long * store_mfn,unsigned int console_evtchn,unsigned long * console_mfn)36 int xc_linux_build(xc_interface *xch, uint32_t domid,
37                    unsigned int mem_mb,
38                    const char *image_name,
39                    const char *initrd_name,
40                    const char *cmdline,
41                    const char *features,
42                    unsigned long flags,
43                    unsigned int store_evtchn,
44                    unsigned long *store_mfn,
45                    unsigned int console_evtchn,
46                    unsigned long *console_mfn)
47 {
48     struct xc_dom_image *dom;
49     int rc;
50 
51     xc_dom_loginit(xch);
52     dom = xc_dom_allocate(xch, cmdline, features);
53     if (dom == NULL)
54         return -1;
55     if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
56         goto out;
57     if ( initrd_name && strlen(initrd_name) &&
58          ((rc = xc_dom_module_file(dom, initrd_name, NULL)) != 0) )
59         goto out;
60 
61     dom->flags |= flags;
62     dom->console_evtchn = console_evtchn;
63     dom->xenstore_evtchn = store_evtchn;
64 
65     if ( (rc = xc_dom_boot_xen_init(dom, xch, domid)) != 0 )
66         goto out;
67     if ( (rc = xc_dom_parse_image(dom)) != 0 )
68         goto out;
69     if ( (rc = xc_dom_mem_init(dom, mem_mb)) != 0 )
70         goto out;
71     if ( (rc = xc_dom_boot_mem_init(dom)) != 0 )
72         goto out;
73     if ( (rc = xc_dom_build_image(dom)) != 0 )
74         goto out;
75     if ( (rc = xc_dom_boot_image(dom)) != 0 )
76         goto out;
77     if ( (rc = xc_dom_gnttab_init(dom)) != 0)
78         goto out;
79 
80     *console_mfn = xc_dom_p2m(dom, dom->console_pfn);
81     *store_mfn = xc_dom_p2m(dom, dom->xenstore_pfn);
82 
83  out:
84     xc_dom_release(dom);
85     return rc;
86 }
87 
88 /*
89  * Local variables:
90  * mode: C
91  * c-file-style: "BSD"
92  * c-basic-offset: 4
93  * tab-width: 4
94  * indent-tabs-mode: nil
95  * End:
96  */
97