ia64/xen-unstable

changeset 18977:5b44cfde9666

PoD memory 9/9: xend integration

Xend integration for PoD functionality.
* Add python bindings for xc_hvm_domain_build() and
xc_domain_memory_set_pod_target()
* Always call xc_hvm_domain_build(), with memsize = memory_static_max
and target=memory_dynamic_max
* When setting a new memory target:
+ First make sure we actually have enough free memory for the target
setting to succeed
+ Call set_pod_target() with the new target, to Xen can do the Right
Thing.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jan 05 10:47:03 2009 +0000 (2009-01-05)
parents 2a8ae362a828
children 5ce75a8eec7f
files tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py
line diff
     1.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Mon Jan 05 10:46:37 2009 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Mon Jan 05 10:47:03 2009 +0000
     1.3 @@ -890,17 +890,20 @@ static PyObject *pyxc_hvm_build(XcObject
     1.4      int i;
     1.5  #endif
     1.6      char *image;
     1.7 -    int memsize, vcpus = 1, acpi = 0, apic = 1;
     1.8 +    int memsize, target=-1, vcpus = 1, acpi = 0, apic = 1;
     1.9  
    1.10      static char *kwd_list[] = { "domid",
    1.11 -                                "memsize", "image", "vcpus", "acpi",
    1.12 +                                "memsize", "image", "target", "vcpus", "acpi",
    1.13                                  "apic", NULL };
    1.14 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|iii", kwd_list,
    1.15 -                                      &dom, &memsize,
    1.16 -                                      &image, &vcpus, &acpi, &apic) )
    1.17 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|iiii", kwd_list,
    1.18 +                                      &dom, &memsize, &image, &target, &vcpus,
    1.19 +                                      &acpi, &apic) )
    1.20          return NULL;
    1.21  
    1.22 -    if ( xc_hvm_build(self->xc_handle, dom, memsize, image) != 0 )
    1.23 +    if ( target == -1 )
    1.24 +        target = memsize;
    1.25 +
    1.26 +    if ( xc_hvm_build_target_mem(self->xc_handle, dom, memsize, target, image) != 0 )
    1.27          return pyxc_error_to_exception();
    1.28  
    1.29  #if !defined(__ia64__)
    1.30 @@ -1335,6 +1338,24 @@ static PyObject *pyxc_domain_setmaxmem(X
    1.31      return zero;
    1.32  }
    1.33  
    1.34 +static PyObject *pyxc_domain_set_target_mem(XcObject *self, PyObject *args)
    1.35 +{
    1.36 +    uint32_t dom;
    1.37 +    unsigned int mem_kb, mem_pages;
    1.38 +
    1.39 +    if (!PyArg_ParseTuple(args, "ii", &dom, &mem_kb))
    1.40 +        return NULL;
    1.41 +
    1.42 +    mem_pages = mem_kb / 4; 
    1.43 +
    1.44 +    if (xc_domain_memory_set_pod_target(self->xc_handle, dom, mem_pages,
    1.45 +                                        NULL, NULL, NULL) != 0)
    1.46 +        return pyxc_error_to_exception();
    1.47 +    
    1.48 +    Py_INCREF(zero);
    1.49 +    return zero;
    1.50 +}
    1.51 +
    1.52  static PyObject *pyxc_domain_set_memmap_limit(XcObject *self, PyObject *args)
    1.53  {
    1.54      uint32_t dom;
    1.55 @@ -1815,6 +1836,14 @@ static PyMethodDef pyxc_methods[] = {
    1.56        " maxmem_kb [int]: .\n"
    1.57        "Returns: [int] 0 on success; -1 on error.\n" },
    1.58  
    1.59 +    { "domain_set_target_mem", 
    1.60 +      (PyCFunction)pyxc_domain_set_target_mem, 
    1.61 +      METH_VARARGS, "\n"
    1.62 +      "Set a domain's memory target\n"
    1.63 +      " dom [int]: Identifier of domain.\n"
    1.64 +      " mem_kb [int]: .\n"
    1.65 +      "Returns: [int] 0 on success; -1 on error.\n" },
    1.66 +
    1.67      { "domain_set_memmap_limit", 
    1.68        (PyCFunction)pyxc_domain_set_memmap_limit, 
    1.69        METH_VARARGS, "\n"
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Jan 05 10:46:37 2009 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Jan 05 10:47:03 2009 +0000
     2.3 @@ -1104,10 +1104,10 @@ class XendDomainInfo:
     2.4                    self.info['name_label'], str(self.domid), target)
     2.5          
     2.6          MiB = 1024 * 1024
     2.7 +        memory_cur = self.get_memory_dynamic_max() / MiB
     2.8  
     2.9          if self.domid == 0:
    2.10              dom0_min_mem = xoptions.get_dom0_min_mem()
    2.11 -            memory_cur = self.get_memory_dynamic_max() / MiB
    2.12              if target < memory_cur and dom0_min_mem > target:
    2.13                  raise XendError("memory_dynamic_max too small")
    2.14  
    2.15 @@ -1115,8 +1115,12 @@ class XendDomainInfo:
    2.16          self._safe_set_memory('memory_dynamic_max', target * MiB)
    2.17  
    2.18          if self.domid >= 0:
    2.19 +            if target > memory_cur:
    2.20 +                balloon.free( (target-memory_cur)*1024 )
    2.21              self.storeVm("memory", target)
    2.22              self.storeDom("memory/target", target << 10)
    2.23 +            xc.domain_set_target_mem(self.domid,
    2.24 +                                     (target * 1024))
    2.25          xen.xend.XendDomain.instance().managed_config_save(self)
    2.26  
    2.27      def setMemoryMaximum(self, limit):
     3.1 --- a/tools/python/xen/xend/image.py	Mon Jan 05 10:46:37 2009 +0000
     3.2 +++ b/tools/python/xen/xend/image.py	Mon Jan 05 10:47:03 2009 +0000
     3.3 @@ -799,19 +799,22 @@ class HVMImageHandler(ImageHandler):
     3.4      def buildDomain(self):
     3.5          store_evtchn = self.vm.getStorePort()
     3.6  
     3.7 +        memmax_mb = self.getRequiredMaximumReservation() / 1024
     3.8          mem_mb = self.getRequiredInitialReservation() / 1024
     3.9  
    3.10          log.debug("domid          = %d", self.vm.getDomid())
    3.11          log.debug("image          = %s", self.loader)
    3.12          log.debug("store_evtchn   = %d", store_evtchn)
    3.13 -        log.debug("memsize        = %d", mem_mb)
    3.14 +        log.debug("memsize        = %d", memmax_mb)
    3.15 +        log.debug("target         = %d", mem_mb)
    3.16          log.debug("vcpus          = %d", self.vm.getVCpuCount())
    3.17          log.debug("acpi           = %d", self.acpi)
    3.18          log.debug("apic           = %d", self.apic)
    3.19  
    3.20          rc = xc.hvm_build(domid          = self.vm.getDomid(),
    3.21                            image          = self.loader,
    3.22 -                          memsize        = mem_mb,
    3.23 +                          memsize        = memmax_mb,
    3.24 +                          target         = mem_mb,
    3.25                            vcpus          = self.vm.getVCpuCount(),
    3.26                            acpi           = self.acpi,
    3.27                            apic           = self.apic)