direct-io.hg

changeset 6457:b26d8e1b4436

Fix nasty tools race between barking xu_autoreap() and xpopen3.wait() -
save/restore now seems more robust from a tools pov at least.

Signed-off-by: Steven Hand <steven@xensource.com>
author shand@ubuntu.eng.hq.xensource.com
date Sun Aug 28 21:40:36 2005 -0800 (2005-08-28)
parents fb2fae2cc003
children 98de1d5fe5fb
files tools/libxc/xc_linux_save.c tools/python/xen/xend/XendCheckpoint.py tools/python/xen/xend/server/SrvDaemon.py
line diff
     1.1 --- a/tools/libxc/xc_linux_save.c	Sun Aug 28 14:21:08 2005 +0000
     1.2 +++ b/tools/libxc/xc_linux_save.c	Sun Aug 28 21:40:36 2005 -0800
     1.3 @@ -763,8 +763,6 @@ int xc_linux_save(int xc_handle, int io_
     1.4                  batch++;
     1.5              }
     1.6       
     1.7 -//            DPRINTF("batch %d:%d (n=%d)\n", iter, batch, n);
     1.8 -
     1.9              if ( batch == 0 )
    1.10                  goto skip; /* vanishingly unlikely... */
    1.11        
    1.12 @@ -915,7 +913,7 @@ int xc_linux_save(int xc_handle, int io_
    1.13              continue;
    1.14          }
    1.15  
    1.16 -        if ( last_iter ) break;
    1.17 +        if ( last_iter ) break; 
    1.18  
    1.19          if ( live )
    1.20          {
     2.1 --- a/tools/python/xen/xend/XendCheckpoint.py	Sun Aug 28 14:21:08 2005 +0000
     2.2 +++ b/tools/python/xen/xend/XendCheckpoint.py	Sun Aug 28 21:40:36 2005 -0800
     2.3 @@ -51,7 +51,7 @@ def save(xd, fd, dominfo):
     2.4      p = select.poll()
     2.5      p.register(child.fromchild.fileno())
     2.6      p.register(child.childerr.fileno())
     2.7 -    while True:
     2.8 +    while True: 
     2.9          r = p.poll()
    2.10          for (fd, event) in r:
    2.11              if not event & select.POLLIN:
    2.12 @@ -69,8 +69,9 @@ def save(xd, fd, dominfo):
    2.13                          try:
    2.14                              dominfo.db.releaseDomain(dominfo.id)
    2.15                          except Exception, ex:
    2.16 -                            log.warning("error in domain release on xenstore: %s",
    2.17 -                                        ex)
    2.18 +                            log.warning(
    2.19 +                                "error in domain release on xenstore: %s",
    2.20 +                                ex)
    2.21                              pass
    2.22                      dominfo.state_wait("suspended")
    2.23                      log.info("suspend %d done" % dominfo.id)
     3.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Sun Aug 28 14:21:08 2005 +0000
     3.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Sun Aug 28 21:40:36 2005 -0800
     3.3 @@ -42,7 +42,8 @@ class Daemon:
     3.4          self.traceon = 0
     3.5          self.tracefile = None
     3.6          self.traceindent = 0
     3.7 -
     3.8 +        self.child = 0 
     3.9 +        
    3.10      def daemon_pids(self):
    3.11          pids = []
    3.12          pidex = '(?P<pid>\d+)'
    3.13 @@ -140,15 +141,12 @@ class Daemon:
    3.14          else:
    3.15              return 0
    3.16  
    3.17 -    def install_child_reaper(self):
    3.18 -        #signal.signal(signal.SIGCHLD, self.onSIGCHLD)
    3.19 -        # Ensure that zombie children are automatically reaped.
    3.20 -        xu.autoreap()
    3.21 -
    3.22      def onSIGCHLD(self, signum, frame):
    3.23 -        code = 1
    3.24 -        while code > 0:
    3.25 -            code = os.waitpid(-1, os.WNOHANG)
    3.26 +        if self.child > 0: 
    3.27 +            try: 
    3.28 +                pid, sts = os.waitpid(self.child, os.WNOHANG)
    3.29 +            except os.error, ex:
    3.30 +                pass
    3.31  
    3.32      def fork_pid(self, pidfile):
    3.33          """Fork and write the pid of the child to 'pidfile'.
    3.34 @@ -156,13 +154,16 @@ class Daemon:
    3.35          @param pidfile: pid file
    3.36          @return: pid of child in parent, 0 in child
    3.37          """
    3.38 -        pid = os.fork()
    3.39 -        if pid:
    3.40 +
    3.41 +        self.child = os.fork()
    3.42 +
    3.43 +        if self.child:
    3.44              # Parent
    3.45              pidfile = open(pidfile, 'w')
    3.46 -            pidfile.write(str(pid))
    3.47 +            pidfile.write(str(self.child))
    3.48              pidfile.close()
    3.49 -        return pid
    3.50 +
    3.51 +        return self.child
    3.52  
    3.53      def daemonize(self):
    3.54          if not XEND_DAEMONIZE: return
    3.55 @@ -203,8 +204,7 @@ class Daemon:
    3.56              # Trying to run an already-running service is a success.
    3.57              return 0
    3.58  
    3.59 -        self.install_child_reaper()
    3.60 -
    3.61 +        signal.signal(signal.SIGCHLD, self.onSIGCHLD)
    3.62          if self.fork_pid(XEND_PID_FILE):
    3.63              #Parent. Sleep to give child time to start.
    3.64              time.sleep(1)
    3.65 @@ -309,7 +309,7 @@ class Daemon:
    3.66              print >>sys.stderr, 'Exception starting xend:', ex
    3.67              if XEND_DEBUG:
    3.68                  traceback.print_exc()
    3.69 -            log.exception("Exception starting xend")
    3.70 +            log.exception("Exception starting xend (%s)" % ex)
    3.71              self.exit(1)
    3.72              
    3.73      def createFactories(self):