ia64/xen-unstable

changeset 7024:f5e33f4d0238

Move initDomain out of image.py and into XendDomainInfo. The only thing that
needed any of the state of image.py was the bootloader code, which says there,
but all the rest was doing something that belonged more properly in
XendDomainInfo, with all the other generic domain initialisation code.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Sep 22 17:52:07 2005 +0100 (2005-09-22)
parents 4be4126911dc
children 40a0f049e344
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Sep 22 17:50:29 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Sep 22 17:52:07 2005 +0100
     1.3 @@ -706,32 +706,14 @@ class XendDomainInfo:
     1.4          """
     1.5          # todo - add support for scheduling params?
     1.6          try:
     1.7 -            # Initial domain create.
     1.8              if 'image' not in self.info:
     1.9                  raise VmError('Missing image in configuration')
    1.10  
    1.11 -            self.image = ImageHandler.create(self, self.info['image'],
    1.12 +            self.image = ImageHandler.create(self,
    1.13 +                                             self.info['image'],
    1.14                                               self.info['device'])
    1.15  
    1.16 -            log.debug('XendDomainInfo.construct: '
    1.17 -                      'calling initDomain(%s %s %s %s %s)',
    1.18 -                      str(self.domid),
    1.19 -                      str(self.info['memory_KiB']),
    1.20 -                      str(self.info['ssidref']),
    1.21 -                      str(self.info['cpu']),
    1.22 -                      str(self.info['cpu_weight']))
    1.23 -
    1.24 -            self.setDomid(self.image.initDomain(self.domid,
    1.25 -                                                self.info['memory_KiB'],
    1.26 -                                                self.info['ssidref'],
    1.27 -                                                self.info['cpu'],
    1.28 -                                                self.info['cpu_weight'],
    1.29 -                                                self.info['bootloader']))
    1.30 -            
    1.31 -            self.info['start_time'] = time.time()
    1.32 -
    1.33 -            log.debug('init_domain> Created domain=%d name=%s memory=%d',
    1.34 -                      self.domid, self.info['name'], self.info['memory_KiB'])
    1.35 +            self.initDomain()
    1.36  
    1.37              # Create domain devices.
    1.38              self.construct_image()
    1.39 @@ -745,6 +727,38 @@ class XendDomainInfo:
    1.40              self.destroy()
    1.41              raise
    1.42  
    1.43 +
    1.44 +    def initDomain(self):
    1.45 +        log.debug('XendDomainInfo.initDomain: %s %s %s %s)',
    1.46 +                  str(self.domid),
    1.47 +                  str(self.info['memory_KiB']),
    1.48 +                  str(self.info['ssidref']),
    1.49 +                  str(self.info['cpu_weight']))
    1.50 +
    1.51 +        self.domid = xc.domain_create(dom = self.domid or 0,
    1.52 +                                      ssidref = self.info['ssidref'])
    1.53 +        if self.domid <= 0:
    1.54 +            raise VmError('Creating domain failed: name=%s' %
    1.55 +                          self.vm.getName())
    1.56 +
    1.57 +        if self.info['bootloader']:
    1.58 +            self.image.handleBootloading()
    1.59 +
    1.60 +        xc.domain_setcpuweight(self.domid, self.info['cpu_weight'])
    1.61 +        m = self.image.getDomainMemory(self.info['memory_KiB'])
    1.62 +        xc.domain_setmaxmem(self.domid, m)
    1.63 +        xc.domain_memory_increase_reservation(self.domid, m, 0, 0)
    1.64 +
    1.65 +        cpu = self.info['cpu']
    1.66 +        if cpu is not None and cpu != -1:
    1.67 +            xc.domain_pincpu(self.domid, 0, 1 << cpu)
    1.68 +
    1.69 +        self.info['start_time'] = time.time()
    1.70 +
    1.71 +        log.debug('init_domain> Created domain=%d name=%s memory=%d',
    1.72 +                  self.domid, self.info['name'], self.info['memory_KiB'])
    1.73 +
    1.74 +
    1.75      def configure_vcpus(self, vcpus):
    1.76          d = {}
    1.77          for v in range(0, vcpus):
     2.1 --- a/tools/python/xen/xend/image.py	Thu Sep 22 17:50:29 2005 +0100
     2.2 +++ b/tools/python/xen/xend/image.py	Thu Sep 22 17:52:07 2005 +0100
     2.3 @@ -36,9 +36,6 @@ MAX_GUEST_CMDLINE = 1024
     2.4  class ImageHandler:
     2.5      """Abstract base class for image handlers.
     2.6  
     2.7 -    initDomain() is called to initialise the domain memory and parse
     2.8 -    the configuration.
     2.9 -    
    2.10      createImage() is called to configure and build the domain from its
    2.11      kernel image and ramdisk etc.
    2.12  
    2.13 @@ -132,6 +129,12 @@ class ImageHandler:
    2.14                          ("image/cmdline", self.cmdline),
    2.15                          ("image/ramdisk", self.ramdisk))
    2.16  
    2.17 +
    2.18 +    def handleBootloading():
    2.19 +        self.unlink(self.kernel)
    2.20 +        self.unlink(self.ramdisk)
    2.21 +
    2.22 +
    2.23      def unlink(self, f):
    2.24          if not f: return
    2.25          try:
    2.26 @@ -139,37 +142,6 @@ class ImageHandler:
    2.27          except OSError, ex:
    2.28              log.warning("error removing bootloader file '%s': %s", f, ex)
    2.29  
    2.30 -    def initDomain(self, dom, memory, ssidref, cpu, cpu_weight, bootloading):
    2.31 -        """Initial domain create.
    2.32 -
    2.33 -        @param memory In KiB
    2.34 -        @return domain id
    2.35 -        """
    2.36 -
    2.37 -        mem_kb = self.getDomainMemory(memory)
    2.38 -        dom = xc.domain_create(dom = dom or 0, ssidref = ssidref)
    2.39 -        # if bootloader, unlink here. But should go after buildDomain() ?
    2.40 -        if bootloading:
    2.41 -            self.unlink(self.kernel)
    2.42 -            self.unlink(self.ramdisk)
    2.43 -        if dom <= 0:
    2.44 -            raise VmError('Creating domain failed: name=%s' %
    2.45 -                          self.vm.getName())
    2.46 -        if cpu is None:
    2.47 -            cpu = -1;
    2.48 -        log.debug("initDomain: cpu=%d mem_kb=%d ssidref=%d dom=%d", cpu, mem_kb, ssidref, dom)
    2.49 -        xc.domain_setcpuweight(dom, cpu_weight)
    2.50 -        xc.domain_setmaxmem(dom, mem_kb)
    2.51 -
    2.52 -        try:
    2.53 -            xc.domain_memory_increase_reservation(dom, mem_kb, 0, 0)
    2.54 -        except:
    2.55 -            xc.domain_destroy(dom)
    2.56 -            raise
    2.57 -
    2.58 -        if cpu != -1:
    2.59 -            xc.domain_pincpu(dom, 0, 1<<int(cpu))
    2.60 -        return dom
    2.61  
    2.62      def createImage(self):
    2.63          """Entry point to create domain memory image.