ia64/xen-unstable

changeset 16137:1f893d055c6f

xend: Clean up hvm_build Python wrapper. Python code can get/set hvm
params directly.
Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Tue Oct 16 10:27:55 2007 +0100 (2007-10-16)
parents 05337cb5206f
children 9488d3166553
files tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/image.py
line diff
     1.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Tue Oct 16 09:40:08 2007 +0100
     1.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Tue Oct 16 10:27:55 2007 +0100
     1.3 @@ -498,17 +498,37 @@ static PyObject *pyxc_get_hvm_param(XcOb
     1.4      unsigned long value;
     1.5  
     1.6      static char *kwd_list[] = { "domid", "param", NULL }; 
     1.7 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
     1.8 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list,
     1.9                                        &dom, &param) )
    1.10          return NULL;
    1.11  
    1.12      if ( xc_get_hvm_param(self->xc_handle, dom, param, &value) != 0 )
    1.13          return pyxc_error_to_exception();
    1.14  
    1.15 -    return Py_BuildValue("i", value);
    1.16 +    return PyLong_FromUnsignedLong(value);
    1.17  
    1.18  }
    1.19  
    1.20 +static PyObject *pyxc_set_hvm_param(XcObject *self,
    1.21 +                                    PyObject *args,
    1.22 +                                    PyObject *kwds)
    1.23 +{
    1.24 +    uint32_t dom;
    1.25 +    int param;
    1.26 +    uint64_t value;
    1.27 +
    1.28 +    static char *kwd_list[] = { "domid", "param", "value", NULL }; 
    1.29 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiL", kwd_list,
    1.30 +                                      &dom, &param, &value) )
    1.31 +        return NULL;
    1.32 +
    1.33 +    if ( xc_set_hvm_param(self->xc_handle, dom, param, value) != 0 )
    1.34 +        return pyxc_error_to_exception();
    1.35 +
    1.36 +    Py_INCREF(zero);
    1.37 +    return zero;
    1.38 +}
    1.39 +
    1.40  #ifdef __ia64__
    1.41  static PyObject *pyxc_nvram_init(XcObject *self,
    1.42                                   PyObject *args)
    1.43 @@ -537,15 +557,14 @@ static PyObject *pyxc_hvm_build(XcObject
    1.44      int i;
    1.45  #endif
    1.46      char *image;
    1.47 -    int store_evtchn, memsize, vcpus = 1, pae = 0, acpi = 0, apic = 1;
    1.48 -    unsigned long store_mfn;
    1.49 +    int memsize, vcpus = 1, acpi = 0, apic = 1;
    1.50  
    1.51 -    static char *kwd_list[] = { "domid", "store_evtchn",
    1.52 -				"memsize", "image", "vcpus", "pae", "acpi",
    1.53 +    static char *kwd_list[] = { "domid",
    1.54 +				"memsize", "image", "vcpus", "acpi",
    1.55  				"apic", NULL };
    1.56 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiis|iiii", kwd_list,
    1.57 -                                      &dom, &store_evtchn, &memsize,
    1.58 -                                      &image, &vcpus, &pae, &acpi, &apic) )
    1.59 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|iii", kwd_list,
    1.60 +                                      &dom, &memsize,
    1.61 +                                      &image, &vcpus, &acpi, &apic) )
    1.62          return NULL;
    1.63  
    1.64      if ( xc_hvm_build(self->xc_handle, dom, memsize, image) != 0 )
    1.65 @@ -571,14 +590,7 @@ static PyObject *pyxc_hvm_build(XcObject
    1.66      munmap(va_map, XC_PAGE_SIZE);
    1.67  #endif
    1.68  
    1.69 -    xc_get_hvm_param(self->xc_handle, dom, HVM_PARAM_STORE_PFN, &store_mfn);
    1.70 -#if !defined(__ia64__)
    1.71 -    xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_PAE_ENABLED, pae);
    1.72 -#endif
    1.73 -    xc_set_hvm_param(self->xc_handle, dom, HVM_PARAM_STORE_EVTCHN,
    1.74 -                     store_evtchn);
    1.75 -
    1.76 -    return Py_BuildValue("{s:i}", "store_mfn", store_mfn);
    1.77 +    return Py_BuildValue("{}");
    1.78  }
    1.79  
    1.80  static PyObject *pyxc_evtchn_alloc_unbound(XcObject *self,
    1.81 @@ -1326,7 +1338,16 @@ static PyMethodDef pyxc_methods[] = {
    1.82        "get a parameter of HVM guest OS.\n"
    1.83        " dom     [int]:      Identifier of domain to build into.\n"
    1.84        " param   [int]:      No. of HVM param.\n"
    1.85 -      "Returns: [int] value of the param.\n" },
    1.86 +      "Returns: [long] value of the param.\n" },
    1.87 +
    1.88 +    { "hvm_set_param", 
    1.89 +      (PyCFunction)pyxc_set_hvm_param, 
    1.90 +      METH_VARARGS | METH_KEYWORDS, "\n"
    1.91 +      "set a parameter of HVM guest OS.\n"
    1.92 +      " dom     [int]:      Identifier of domain to build into.\n"
    1.93 +      " param   [int]:      No. of HVM param.\n"
    1.94 +      " value   [long]:     Value of param.\n"
    1.95 +      "Returns: [int] 0 on success.\n" },
    1.96  
    1.97      { "sched_id_get",
    1.98        (PyCFunction)pyxc_sched_id_get,
     2.1 --- a/tools/python/xen/xend/image.py	Tue Oct 16 09:40:08 2007 +0100
     2.2 +++ b/tools/python/xen/xend/image.py	Tue Oct 16 10:27:55 2007 +0100
     2.3 @@ -24,7 +24,7 @@ import time
     2.4  import signal
     2.5  
     2.6  import xen.lowlevel.xc
     2.7 -from xen.xend.XendConstants import REVERSE_DOMAIN_SHUTDOWN_REASONS
     2.8 +from xen.xend.XendConstants import *
     2.9  from xen.xend.XendError import VmError, XendError, HVMRequired
    2.10  from xen.xend.XendLogging import log
    2.11  from xen.xend.XendOptions import instance as xenopts
    2.12 @@ -274,7 +274,6 @@ class HVMImageHandler(ImageHandler):
    2.13  
    2.14          self.pid = None
    2.15  
    2.16 -        self.pae  = int(vmConfig['platform'].get('pae',  0))
    2.17          self.apic = int(vmConfig['platform'].get('apic', 0))
    2.18          self.acpi = int(vmConfig['platform'].get('acpi', 0))
    2.19          
    2.20 @@ -289,19 +288,23 @@ class HVMImageHandler(ImageHandler):
    2.21          log.debug("store_evtchn   = %d", store_evtchn)
    2.22          log.debug("memsize        = %d", mem_mb)
    2.23          log.debug("vcpus          = %d", self.vm.getVCpuCount())
    2.24 -        log.debug("pae            = %d", self.pae)
    2.25          log.debug("acpi           = %d", self.acpi)
    2.26          log.debug("apic           = %d", self.apic)
    2.27  
    2.28          rc = xc.hvm_build(domid          = self.vm.getDomid(),
    2.29                            image          = self.kernel,
    2.30 -                          store_evtchn   = store_evtchn,
    2.31                            memsize        = mem_mb,
    2.32                            vcpus          = self.vm.getVCpuCount(),
    2.33 -                          pae            = self.pae,
    2.34                            acpi           = self.acpi,
    2.35                            apic           = self.apic)
    2.36 +
    2.37          rc['notes'] = { 'SUSPEND_CANCEL': 1 }
    2.38 +
    2.39 +        rc['store_mfn'] = xc.hvm_get_param(self.vm.getDomid(),
    2.40 +                                           HVM_PARAM_STORE_PFN)
    2.41 +        xc.hvm_set_param(self.vm.getDomid(), HVM_PARAM_STORE_EVTCHN,
    2.42 +                         store_evtchn)
    2.43 +
    2.44          return rc
    2.45  
    2.46      # Return a list of cmd line args to the device models based on the
    2.47 @@ -517,6 +520,14 @@ class IA64_HVM_ImageHandler(HVMImageHand
    2.48  
    2.49  class X86_HVM_ImageHandler(HVMImageHandler):
    2.50  
    2.51 +    def configure(self, vmConfig):
    2.52 +        HVMImageHandler.configure(self, vmConfig)
    2.53 +        self.pae = int(vmConfig['platform'].get('pae',  0))
    2.54 +
    2.55 +    def buildDomain(self):
    2.56 +        xc.hvm_set_param(self.vm.getDomid(), HVM_PARAM_PAE_ENABLED, self.pae)
    2.57 +        return HVMImageHandler.buildDomain(self)
    2.58 +
    2.59      def getRequiredAvailableMemory(self, mem_kb):
    2.60          # Add 8 MiB overhead for QEMU's video RAM.
    2.61          return mem_kb + 8192