ia64/xen-unstable

changeset 6116:fb619858dfa9

Handle VMX domains correctly across xend restarts

This patch remembers the device model pid across xend restarts and
avoids creating duplicate device model processes.

Also, device models don't inherit socket fds from xend (which are closed
on exec now), which used to prevent xend restarting.

Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Signed-off-by: Xiaohui Xin <xiaohui.xin@intel.com>
Signed-off-by: Arun Sharma <arun.sharma@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Aug 11 21:02:51 2005 +0000 (2005-08-11)
parents bf98996dded2
children 2b9e3795a523
files tools/python/xen/web/connection.py tools/python/xen/web/reactor.py tools/python/xen/web/tcp.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py tools/python/xen/xend/server/relocate.py
line diff
     1.1 --- a/tools/python/xen/web/connection.py	Thu Aug 11 21:01:36 2005 +0000
     1.2 +++ b/tools/python/xen/web/connection.py	Thu Aug 11 21:02:51 2005 +0000
     1.3 @@ -20,6 +20,7 @@ import sys
     1.4  import threading
     1.5  import select
     1.6  import socket
     1.7 +import fcntl
     1.8  
     1.9  from errno import EAGAIN, EINTR, EWOULDBLOCK
    1.10  
    1.11 @@ -152,6 +153,9 @@ class SocketListener:
    1.12      def createSocket(self):
    1.13          raise NotImplementedError()
    1.14  
    1.15 +    def setCloExec(self):
    1.16 +        fcntl.fcntl(self.sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
    1.17 +
    1.18      def acceptConnection(self, sock, protocol, addr):
    1.19          return SocketServerConnection(sock, protocol, addr, self)
    1.20  
     2.1 --- a/tools/python/xen/web/reactor.py	Thu Aug 11 21:01:36 2005 +0000
     2.2 +++ b/tools/python/xen/web/reactor.py	Thu Aug 11 21:02:51 2005 +0000
     2.3 @@ -16,4 +16,4 @@
     2.4  #============================================================================
     2.5  
     2.6  from unix import listenUNIX, connectUNIX
     2.7 -from tcp import listenTCP, connectTCP
     2.8 +from tcp import listenTCP, connectTCP, SetCloExec
     3.1 --- a/tools/python/xen/web/tcp.py	Thu Aug 11 21:01:36 2005 +0000
     3.2 +++ b/tools/python/xen/web/tcp.py	Thu Aug 11 21:02:51 2005 +0000
     3.3 @@ -85,6 +85,9 @@ def listenTCP(port, factory, interface='
     3.4      l.startListening()
     3.5      return l
     3.6  
     3.7 +def SetCloExec(SocketListener):
     3.8 +    SocketListener.SetCloExec()
     3.9 +
    3.10  def connectTCP(host, port, factory, timeout=None, bindAddress=None):
    3.11      c = TCPConnector(host, port, factory, timeout=timeout, bindAddress=bindAddress)
    3.12      c.connect()
     4.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Aug 11 21:01:36 2005 +0000
     4.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Aug 11 21:02:51 2005 +0000
     4.3 @@ -231,6 +231,7 @@ class XendDomainInfo:
     4.4          DBVar('restart_time',  ty='float'),
     4.5          DBVar('restart_count', ty='int'),
     4.6          DBVar('target',        ty='long', path="memory/target"),
     4.7 +        DBVar('device_model_pid', ty='int'),
     4.8          ]
     4.9      
    4.10      def __init__(self, db):
    4.11 @@ -275,6 +276,7 @@ class XendDomainInfo:
    4.12          self.vcpus = 1
    4.13          self.vcpusdb = {}
    4.14          self.bootloader = None
    4.15 +        self.device_model_pid = 0
    4.16  
    4.17      def setDB(self, db):
    4.18          self.db = db
    4.19 @@ -457,6 +459,8 @@ class XendDomainInfo:
    4.20              sxpr.append(devs)
    4.21          if self.config:
    4.22              sxpr.append(['config', self.config])
    4.23 +        if self.device_model_pid:
    4.24 +            sxpr.append(['device_model_pid',self.device_model_pid])
    4.25          return sxpr
    4.26  
    4.27      def sxpr_devices(self):
    4.28 @@ -739,7 +743,8 @@ class XendDomainInfo:
    4.29                  ctrl.initController(reboot=True)
    4.30          else:
    4.31              self.create_configured_devices()
    4.32 -        self.image.createDeviceModel()
    4.33 +        if not self.device_model_pid:
    4.34 +            self.device_model_pid = self.image.createDeviceModel()
    4.35  
    4.36      def device_create(self, dev_config):
    4.37          """Create a new device.
     5.1 --- a/tools/python/xen/xend/image.py	Thu Aug 11 21:01:36 2005 +0000
     5.2 +++ b/tools/python/xen/xend/image.py	Thu Aug 11 21:02:51 2005 +0000
     5.3 @@ -262,7 +262,7 @@ class VmxImageHandler(ImageHandler):
     5.4      memmap = None
     5.5      memmap_value = []
     5.6      device_channel = None
     5.7 -
     5.8 +    pid = 0
     5.9      def createImage(self):
    5.10          """Create a VM for the VMX environment.
    5.11          """
    5.12 @@ -379,6 +379,7 @@ class VmxImageHandler(ImageHandler):
    5.13          log.info("spawning device models: %s %s", device_model, args)
    5.14          self.pid = os.spawnve(os.P_NOWAIT, device_model, args, env)
    5.15          log.info("device model pid: %d", self.pid)
    5.16 +        return self.pid
    5.17  
    5.18      def vncParams(self):
    5.19          # see if a vncviewer was specified
    5.20 @@ -398,8 +399,11 @@ class VmxImageHandler(ImageHandler):
    5.21      def destroy(self):
    5.22          channel.eventChannelClose(self.device_channel)
    5.23          import signal
    5.24 +        if not self.pid:
    5.25 +            self.pid = self.vm.device_model_pid
    5.26          os.kill(self.pid, signal.SIGKILL)
    5.27          (pid, status) = os.waitpid(self.pid, 0)
    5.28 +        self.pid = 0
    5.29  
    5.30      def getDomainMemory(self, mem_mb):
    5.31          # for ioreq_t and xenstore
     6.1 --- a/tools/python/xen/xend/server/relocate.py	Thu Aug 11 21:01:36 2005 +0000
     6.2 +++ b/tools/python/xen/xend/server/relocate.py	Thu Aug 11 21:02:51 2005 +0000
     6.3 @@ -140,7 +140,8 @@ def listenRelocation():
     6.4      if xroot.get_xend_relocation_server():
     6.5          port = xroot.get_xend_relocation_port()
     6.6          interface = xroot.get_xend_relocation_address()
     6.7 -        reactor.listenTCP(port, factory, interface=interface)
     6.8 +        l = reactor.listenTCP(port, factory, interface=interface)
     6.9 +        l.setCloExec()
    6.10  
    6.11  def setupRelocation(dst, port):
    6.12      try: