* License along with this library; If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef _XC_DOM_H
+#define _XC_DOM_H
+
#include <xen/libelf/libelf.h>
#include <xenguest.h>
return dom->p2m_host[pfn - dom->rambase_pfn];
}
+#endif /* _XC_DOM_H */
+
/*
* Local variables:
* mode: C
unsigned int console_evtchn,
unsigned long *console_mfn);
-/** The same interface, but the dom structure is managed by the caller */
-struct xc_dom_image;
-int xc_dom_linux_build(xc_interface *xch,
- struct xc_dom_image *dom,
- uint32_t domid,
- unsigned int mem_mb,
- const char *image_name,
- const char *ramdisk_name,
- unsigned long flags,
- unsigned int store_evtchn,
- unsigned long *store_mfn,
- unsigned int console_evtchn,
- unsigned long *console_mfn);
-
-/**
- * This function will create a domain for a paravirtualized Linux
- * using buffers for kernel and initrd
- *
- * @parm xch a handle to an open hypervisor interface
- * @parm domid the id of the domain
- * @parm mem_mb memory size in megabytes
- * @parm image_buffer buffer containing kernel image
- * @parm image_size size of the kernel image buffer
- * @parm initrd_buffer name of the ramdisk image file
- * @parm initrd_size size of the ramdisk buffer
- * @parm cmdline command line string
- * @parm flags domain creation flags
- * @parm store_evtchn the store event channel for this domain to use
- * @parm store_mfn returned with the mfn of the store page
- * @parm console_evtchn the console event channel for this domain to use
- * @parm conole_mfn returned with the mfn of the console page
- * @return 0 on success, -1 on failure
- */
-int xc_linux_build_mem(xc_interface *xch,
- uint32_t domid,
- unsigned int mem_mb,
- const char *image_buffer,
- unsigned long image_size,
- const char *initrd_buffer,
- unsigned long initrd_size,
- 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);
-
struct xc_hvm_firmware_module {
uint8_t *data;
uint32_t length;
/* ------------------------------------------------------------------------ */
-static int xc_linux_build_internal(struct xc_dom_image *dom,
- xc_interface *xch, uint32_t domid,
- unsigned int mem_mb,
- unsigned long flags,
- unsigned int store_evtchn,
- unsigned long *store_mfn,
- unsigned int console_evtchn,
- unsigned long *console_mfn)
-{
- int rc;
-
- dom->flags = flags;
- dom->console_evtchn = console_evtchn;
- dom->xenstore_evtchn = store_evtchn;
-
- if ( (rc = xc_dom_boot_xen_init(dom, xch, domid)) != 0 )
- goto out;
- if ( (rc = xc_dom_parse_image(dom)) != 0 )
- goto out;
- if ( (rc = xc_dom_mem_init(dom, mem_mb)) != 0 )
- goto out;
- if ( (rc = xc_dom_boot_mem_init(dom)) != 0 )
- goto out;
- if ( (rc = xc_dom_build_image(dom)) != 0 )
- goto out;
- if ( (rc = xc_dom_boot_image(dom)) != 0 )
- goto out;
- if ( (rc = xc_dom_gnttab_init(dom)) != 0)
- goto out;
-
- *console_mfn = xc_dom_p2m(dom, dom->console_pfn);
- *store_mfn = xc_dom_p2m(dom, dom->xenstore_pfn);
-
- out:
- return rc;
-}
-
-int xc_linux_build_mem(xc_interface *xch, uint32_t domid,
- unsigned int mem_mb,
- const char *image_buffer,
- unsigned long image_size,
- const char *initrd,
- unsigned long initrd_len,
- 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)
+int xc_get_bit_size(xc_interface *xch,
+ const char *image_name, const char *cmdline,
+ const char *features, int *bit_size)
{
struct xc_dom_image *dom;
int rc;
-
- xc_dom_loginit(xch);
+ *bit_size = 0;
dom = xc_dom_allocate(xch, cmdline, features);
if (dom == NULL)
return -1;
- if ( (rc = xc_dom_kernel_mem(dom, image_buffer, image_size)) != 0 )
+ if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
goto out;
- if ( initrd && ((rc = xc_dom_ramdisk_mem(dom, initrd, initrd_len)) != 0) )
+ if ( (rc = xc_dom_parse_image(dom)) != 0 )
goto out;
-
- rc = xc_linux_build_internal(dom, xch, domid,
- mem_mb, flags,
- store_evtchn, store_mfn,
- console_evtchn, console_mfn);
-
+ if( dom->guest_type != NULL){
+ if(strstr(dom->guest_type, "x86_64") != NULL)
+ *bit_size = X86_64_B_SIZE; //64bit Guest
+ if(strstr(dom->guest_type, "x86_32") != NULL)
+ *bit_size = X86_32_B_SIZE; //32bit Guest
+ }
out:
xc_dom_release(dom);
return rc;
((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) )
goto out;
- rc = xc_linux_build_internal(dom, xch, domid,
- mem_mb, flags,
- store_evtchn, store_mfn,
- console_evtchn, console_mfn);
+ dom->flags = flags;
+ dom->console_evtchn = console_evtchn;
+ dom->xenstore_evtchn = store_evtchn;
- out:
- xc_dom_release(dom);
- return rc;
-}
-int xc_get_bit_size(xc_interface *xch,
- const char *image_name, const char *cmdline,
- const char *features, int *bit_size)
-{
- struct xc_dom_image *dom;
- int rc;
- *bit_size = 0;
- dom = xc_dom_allocate(xch, cmdline, features);
- if (dom == NULL)
- return -1;
- if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
+ if ( (rc = xc_dom_boot_xen_init(dom, xch, domid)) != 0 )
goto out;
if ( (rc = xc_dom_parse_image(dom)) != 0 )
goto out;
- if( dom->guest_type != NULL){
- if(strstr(dom->guest_type, "x86_64") != NULL)
- *bit_size = X86_64_B_SIZE; //64bit Guest
- if(strstr(dom->guest_type, "x86_32") != NULL)
- *bit_size = X86_32_B_SIZE; //32bit Guest
- }
+ if ( (rc = xc_dom_mem_init(dom, mem_mb)) != 0 )
+ goto out;
+ if ( (rc = xc_dom_boot_mem_init(dom)) != 0 )
+ goto out;
+ if ( (rc = xc_dom_build_image(dom)) != 0 )
+ goto out;
+ if ( (rc = xc_dom_boot_image(dom)) != 0 )
+ goto out;
+ if ( (rc = xc_dom_gnttab_init(dom)) != 0)
+ goto out;
+
+ *console_mfn = xc_dom_p2m(dom, dom->console_pfn);
+ *store_mfn = xc_dom_p2m(dom, dom->xenstore_pfn);
-out:
+ out:
xc_dom_release(dom);
return rc;
}
-int xc_dom_linux_build(xc_interface *xch,
- struct xc_dom_image *dom,
- uint32_t domid,
- unsigned int mem_mb,
- const char *image_name,
- const char *initrd_name,
- unsigned long flags,
- unsigned int store_evtchn,
- unsigned long *store_mfn,
- unsigned int console_evtchn, unsigned long *console_mfn)
-{
- int rc;
-
- if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
- return rc;
- if ( initrd_name && strlen(initrd_name) &&
- ((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) )
- return rc;
-
- return xc_linux_build_internal(dom, xch, domid,
- mem_mb, flags,
- store_evtchn, store_mfn,
- console_evtchn, console_mfn);
-}
-
/*
* Local variables:
* mode: C
#include <xenstore.h>
#include <xenctrl.h>
#include <xenguest.h>
+#include <xc_dom.h>
#include "xentoollog.h"
#include <Python.h>
#include <xenctrl.h>
#include <xenguest.h>
-#include <zlib.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <arpa/inet.h>
-#include "xenctrl.h"
-#include <xen/elfnote.h>
#include <xen/tmem.h>
#include "xc_dom.h"
#include <xen/hvm/hvm_info_table.h>
return info_type;
}
-static PyObject *pyxc_linux_build(XcObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- uint32_t domid;
- struct xc_dom_image *dom;
- char *image, *ramdisk = NULL, *cmdline = "", *features = NULL;
- int flags = 0;
- int store_evtchn, console_evtchn;
- unsigned int mem_mb;
- unsigned long store_mfn = 0;
- unsigned long console_mfn = 0;
- PyObject* elfnote_dict;
- PyObject* elfnote = NULL;
- PyObject* ret;
- int i;
-
- static char *kwd_list[] = { "domid", "store_evtchn", "memsize",
- "console_evtchn", "image",
- /* optional */
- "ramdisk", "cmdline", "flags",
- "features", NULL };
-
- if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssis", kwd_list,
- &domid, &store_evtchn, &mem_mb,
- &console_evtchn, &image,
- /* optional */
- &ramdisk, &cmdline, &flags, &features) )
- return NULL;
-
- xc_dom_loginit(self->xc_handle);
- if (!(dom = xc_dom_allocate(self->xc_handle, cmdline, features)))
- return pyxc_error_to_exception(self->xc_handle);
-
- if ( xc_dom_linux_build(self->xc_handle, dom, domid, mem_mb, image,
- ramdisk, flags, store_evtchn, &store_mfn,
- console_evtchn, &console_mfn) != 0 ) {
- goto out;
- }
-
- if ( !(elfnote_dict = PyDict_New()) )
- goto out;
-
- for ( i = 0; i < ARRAY_SIZE(dom->parms.elf_notes); i++ )
- {
- switch ( dom->parms.elf_notes[i].type )
- {
- case XEN_ENT_NONE:
- continue;
- case XEN_ENT_LONG:
- elfnote = Py_BuildValue("k", dom->parms.elf_notes[i].data.num);
- break;
- case XEN_ENT_STR:
- elfnote = Py_BuildValue("s", dom->parms.elf_notes[i].data.str);
- break;
- }
- PyDict_SetItemString(elfnote_dict,
- dom->parms.elf_notes[i].name,
- elfnote);
- Py_DECREF(elfnote);
- }
-
- ret = Py_BuildValue("{s:i,s:i,s:N}",
- "store_mfn", store_mfn,
- "console_mfn", console_mfn,
- "notes", elfnote_dict);
-
- if ( dom->arch_hooks->native_protocol )
- {
- PyObject *native_protocol =
- Py_BuildValue("s", dom->arch_hooks->native_protocol);
- PyDict_SetItemString(ret, "native_protocol", native_protocol);
- Py_DECREF(native_protocol);
- }
-
- xc_dom_release(dom);
-
- return ret;
-
- out:
- xc_dom_release(dom);
- return pyxc_error_to_exception(self->xc_handle);
-}
-
static PyObject *pyxc_hvm_param_get(XcObject *self,
PyObject *args,
PyObject *kwds)
" cpumap [int]: Bitmap of CPUs this VCPU can run on\n"
" cpu [int]: CPU that this VCPU is currently bound to\n" },
- { "linux_build",
- (PyCFunction)pyxc_linux_build,
- METH_VARARGS | METH_KEYWORDS, "\n"
- "Build a new Linux guest OS.\n"
- " dom [int]: Identifier of domain to build into.\n"
- " image [str]: Name of kernel image file. May be gzipped.\n"
- " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
- " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
- " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
- "Returns: [int] 0 on success; -1 on error.\n" },
-
{"getBitSize",
(PyCFunction)pyxc_getBitSize,
METH_VARARGS | METH_KEYWORDS, "\n"