WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-3.4-testing] xend: fix migration hangs by closing f

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-3.4-testing] xend: fix migration hangs by closing fds on exec
From: "Xen patchbot-3.4-testing" <patchbot-3.4-testing@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 29 Jul 2009 01:30:32 -0700
Delivery-date: Wed, 29 Jul 2009 01:30:53 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1248855838 -3600
# Node ID 28c79a5dd4e446370cac875fb09b0fcf84d5694b
# Parent  0ae681bbd70bd27e0473472dbd7aa3b65765db19
xend: fix migration hangs by closing fds on exec

Signed-off-by: Zhigang Wang <zhigang.x.wang@xxxxxxxxxx>
Reviewed-by: Xiaowei Hu <xiaowei.hu@xxxxxxxxxx>
xen-unstable changeset:   19990:38dd208e1d95
xen-unstable date:        Tue Jul 28 16:33:46 2009 +0100
---
 tools/python/xen/util/oshelp.py         |   13 +++++++++++++
 tools/python/xen/util/xpopen.py         |   24 +++++++++++++++++++-----
 tools/python/xen/util/xsm/acm/acm.py    |    4 ++--
 tools/python/xen/xend/Vifctl.py         |    5 ++---
 tools/python/xen/xend/XendBootloader.py |    3 ++-
 tools/python/xen/xend/image.py          |    4 +---
 6 files changed, 39 insertions(+), 14 deletions(-)

diff -r 0ae681bbd70b -r 28c79a5dd4e4 tools/python/xen/util/oshelp.py
--- a/tools/python/xen/util/oshelp.py   Tue Jul 28 17:04:24 2009 +0100
+++ b/tools/python/xen/util/oshelp.py   Wed Jul 29 09:23:58 2009 +0100
@@ -1,5 +1,18 @@ import fcntl
 import fcntl
 import os
+
+def close_fds(pass_fds=()):
+    try:
+        MAXFD = os.sysconf('SC_OPEN_MAX')
+    except:
+        MAXFD = 256
+    for i in range(3, MAXFD):
+        if i in pass_fds:
+            continue
+        try:
+            os.close(i)
+        except OSError:
+            pass
 
 def fcntl_setfd_cloexec(file, bool):
         f = fcntl.fcntl(file, fcntl.F_GETFD)
diff -r 0ae681bbd70b -r 28c79a5dd4e4 tools/python/xen/util/xpopen.py
--- a/tools/python/xen/util/xpopen.py   Tue Jul 28 17:04:24 2009 +0100
+++ b/tools/python/xen/util/xpopen.py   Wed Jul 29 09:23:58 2009 +0100
@@ -85,7 +85,7 @@ class xPopen3:
 
     sts = -1                    # Child not completed yet
 
-    def __init__(self, cmd, capturestderr=False, bufsize=-1, passfd=()):
+    def __init__(self, cmd, capturestderr=False, bufsize=-1, passfd=(), 
env=None):
         """The parameter 'cmd' is the shell command to execute in a
         sub-process.  The 'capturestderr' flag, if true, specifies that
         the object should capture standard error output of the child process.
@@ -128,6 +128,10 @@ class xPopen3:
                 pass
         try:
             os.execvp(cmd[0], cmd)
+            if env is None:
+                os.execvp(cmd[0], cmd)
+            else:
+                os.execvpe(cmd[0], cmd, env)
         finally:
             os._exit(127)
 
@@ -154,16 +158,26 @@ class xPopen3:
         return self.sts
 
 
-def xpopen2(cmd, bufsize=-1, mode='t', passfd=[]):
+def xpopen2(cmd, bufsize=-1, mode='t', passfd=[], env=None):
     """Execute the shell command 'cmd' in a sub-process.  If 'bufsize' is
     specified, it sets the buffer size for the I/O pipes.  The file objects
     (child_stdout, child_stdin) are returned."""
-    inst = xPopen3(cmd, False, bufsize, passfd)
+    inst = xPopen3(cmd, False, bufsize, passfd, env)
     return inst.fromchild, inst.tochild
 
-def xpopen3(cmd, bufsize=-1, mode='t', passfd=[]):
+def xpopen3(cmd, bufsize=-1, mode='t', passfd=[], env=None):
     """Execute the shell command 'cmd' in a sub-process.  If 'bufsize' is
     specified, it sets the buffer size for the I/O pipes.  The file objects
     (child_stdout, child_stdin, child_stderr) are returned."""
-    inst = xPopen3(cmd, True, bufsize, passfd)
+    inst = xPopen3(cmd, True, bufsize, passfd, env)
     return inst.fromchild, inst.tochild, inst.childerr
+
+def call(*popenargs, **kwargs):
+    """Run command with arguments.  Wait for command to complete, then
+    return the status.
+
+    The arguments are the same as for the xPopen3 constructor.  Example:
+
+    status = call("ls -l")
+    """
+    return xPopen3(*popenargs, **kwargs).wait()
diff -r 0ae681bbd70b -r 28c79a5dd4e4 tools/python/xen/util/xsm/acm/acm.py
--- a/tools/python/xen/util/xsm/acm/acm.py      Tue Jul 28 17:04:24 2009 +0100
+++ b/tools/python/xen/util/xsm/acm/acm.py      Wed Jul 29 09:23:58 2009 +0100
@@ -31,7 +31,7 @@ from xen.xend import XendOptions
 from xen.xend import XendOptions
 from xen.xend.XendLogging import log
 from xen.xend.XendError import VmError
-from xen.util import dictio, xsconstants
+from xen.util import dictio, xsconstants, xpopen
 from xen.xend.XendConstants import *
 
 #global directories and tools for security management
@@ -1710,7 +1710,7 @@ def run_resource_label_change_script(res
                 log.info("Running resource label change script %s: %s" %
                          (script, parms))
                 parms.update(os.environ)
-                os.spawnve(os.P_WAIT, script[0], script, parms)
+                xpopen.call(" ".join(script, params))
         else:
             log.info("No script given for relabeling of resources.")
     if not __script_runner:
diff -r 0ae681bbd70b -r 28c79a5dd4e4 tools/python/xen/xend/Vifctl.py
--- a/tools/python/xen/xend/Vifctl.py   Tue Jul 28 17:04:24 2009 +0100
+++ b/tools/python/xen/xend/Vifctl.py   Wed Jul 29 09:23:58 2009 +0100
@@ -18,10 +18,9 @@
 
 """Xend interface to networking control scripts.
 """
-import os
 
 import XendOptions
-
+from xen.util import xpopen
 
 def network(op):
     """Call a network control script.
@@ -33,4 +32,4 @@ def network(op):
     script = XendOptions.instance().get_network_script()
     if script:
         script.insert(1, op)
-        os.spawnv(os.P_WAIT, script[0], script)
+        xpopen.call(script)
diff -r 0ae681bbd70b -r 28c79a5dd4e4 tools/python/xen/xend/XendBootloader.py
--- a/tools/python/xen/xend/XendBootloader.py   Tue Jul 28 17:04:24 2009 +0100
+++ b/tools/python/xen/xend/XendBootloader.py   Wed Jul 29 09:23:58 2009 +0100
@@ -17,7 +17,7 @@ import shlex
 import shlex
 from xen.xend import sxp
 
-from xen.util import mkdir
+from xen.util import mkdir, oshelp
 from XendLogging import log
 from XendError import VmError
 
@@ -113,6 +113,7 @@ def bootloader(blexec, disk, dom, quiet 
             log.debug("Launching bootloader as %s." % str(args))
             env = os.environ.copy()
             env['TERM'] = 'vt100'
+            oshelp.close_fds()
             os.execvpe(args[0], args, env)
         except OSError, e:
             print e
diff -r 0ae681bbd70b -r 28c79a5dd4e4 tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py    Tue Jul 28 17:04:24 2009 +0100
+++ b/tools/python/xen/xend/image.py    Wed Jul 29 09:23:58 2009 +0100
@@ -423,9 +423,7 @@ class ImageHandler:
                 os.dup2(null, 0)
                 os.dup2(logfd, 1)
                 os.dup2(logfd, 2)
-                os.close(null)
-                os.close(logfd)
-                self.sentinel_fifo.close()
+                oshelp.close_fds((sentinel_write.fileno(),))
                 try:
                     os.execve(self.device_model, args, env)
                 except Exception, e:

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-3.4-testing] xend: fix migration hangs by closing fds on exec, Xen patchbot-3.4-testing <=