| [34] | 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> |
|---|
| 17 | |
|---|
| 18 | #include "xenctrl.h" |
|---|
| 19 | #include "xg_private.h" |
|---|
| 20 | #include "xc_dom.h" |
|---|
| 21 | |
|---|
| 22 | /* ------------------------------------------------------------------------ */ |
|---|
| 23 | |
|---|
| 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; |
|---|
| 34 | |
|---|
| 35 | dom->flags = flags; |
|---|
| 36 | dom->console_evtchn = console_evtchn; |
|---|
| 37 | dom->xenstore_evtchn = store_evtchn; |
|---|
| 38 | |
|---|
| 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; |
|---|
| 51 | |
|---|
| 52 | *console_mfn = xc_dom_p2m_host(dom, dom->console_pfn); |
|---|
| 53 | *store_mfn = xc_dom_p2m_host(dom, dom->xenstore_pfn); |
|---|
| 54 | |
|---|
| 55 | out: |
|---|
| 56 | return rc; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 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, unsigned long *console_mfn) |
|---|
| 71 | { |
|---|
| 72 | struct xc_dom_image *dom; |
|---|
| 73 | int rc; |
|---|
| 74 | |
|---|
| 75 | xc_dom_loginit(); |
|---|
| 76 | dom = xc_dom_allocate(cmdline, features); |
|---|
| 77 | if ( (rc = xc_dom_kernel_mem(dom, image_buffer, image_size)) != 0 ) |
|---|
| 78 | goto out; |
|---|
| 79 | if ( initrd && ((rc = xc_dom_ramdisk_mem(dom, initrd, initrd_len)) != 0) ) |
|---|
| 80 | goto out; |
|---|
| 81 | |
|---|
| 82 | rc = xc_linux_build_internal(dom, xc_handle, domid, |
|---|
| 83 | mem_mb, flags, |
|---|
| 84 | store_evtchn, store_mfn, |
|---|
| 85 | console_evtchn, console_mfn); |
|---|
| 86 | |
|---|
| 87 | out: |
|---|
| 88 | xc_dom_release(dom); |
|---|
| 89 | return rc; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | int xc_linux_build(int xc_handle, uint32_t domid, |
|---|
| 93 | unsigned int mem_mb, |
|---|
| 94 | const char *image_name, |
|---|
| 95 | const char *initrd_name, |
|---|
| 96 | const char *cmdline, |
|---|
| 97 | const char *features, |
|---|
| 98 | unsigned long flags, |
|---|
| 99 | unsigned int store_evtchn, |
|---|
| 100 | unsigned long *store_mfn, |
|---|
| 101 | unsigned int console_evtchn, unsigned long *console_mfn) |
|---|
| 102 | { |
|---|
| 103 | struct xc_dom_image *dom; |
|---|
| 104 | int rc; |
|---|
| 105 | |
|---|
| 106 | xc_dom_loginit(); |
|---|
| 107 | dom = xc_dom_allocate(cmdline, features); |
|---|
| 108 | if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 ) |
|---|
| 109 | goto out; |
|---|
| 110 | if ( initrd_name && strlen(initrd_name) && |
|---|
| 111 | ((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) ) |
|---|
| 112 | goto out; |
|---|
| 113 | |
|---|
| 114 | rc = xc_linux_build_internal(dom, xc_handle, domid, |
|---|
| 115 | mem_mb, flags, |
|---|
| 116 | store_evtchn, store_mfn, |
|---|
| 117 | console_evtchn, console_mfn); |
|---|
| 118 | |
|---|
| 119 | out: |
|---|
| 120 | xc_dom_release(dom); |
|---|
| 121 | return rc; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | int xc_dom_linux_build(int xc_handle, |
|---|
| 125 | struct xc_dom_image *dom, |
|---|
| 126 | uint32_t domid, |
|---|
| 127 | unsigned int mem_mb, |
|---|
| 128 | const char *image_name, |
|---|
| 129 | const char *initrd_name, |
|---|
| 130 | unsigned long flags, |
|---|
| 131 | unsigned int store_evtchn, |
|---|
| 132 | unsigned long *store_mfn, |
|---|
| 133 | unsigned int console_evtchn, unsigned long *console_mfn) |
|---|
| 134 | { |
|---|
| 135 | int rc; |
|---|
| 136 | |
|---|
| 137 | if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 ) |
|---|
| 138 | return rc; |
|---|
| 139 | if ( initrd_name && strlen(initrd_name) && |
|---|
| 140 | ((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) ) |
|---|
| 141 | return rc; |
|---|
| 142 | |
|---|
| 143 | return xc_linux_build_internal(dom, xc_handle, domid, |
|---|
| 144 | mem_mb, flags, |
|---|
| 145 | store_evtchn, store_mfn, |
|---|
| 146 | console_evtchn, console_mfn); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | /* |
|---|
| 150 | * Local variables: |
|---|
| 151 | * mode: C |
|---|
| 152 | * c-set-style: "BSD" |
|---|
| 153 | * c-basic-offset: 4 |
|---|
| 154 | * tab-width: 4 |
|---|
| 155 | * indent-tabs-mode: nil |
|---|
| 156 | * End: |
|---|
| 157 | */ |
|---|