ia64/xen-unstable

diff tools/python/xen/xend/XendDomain.py @ 12725:36fe7ca48e54

Tidy up the creation of directories that Xend needs. This avoids potential
races in this creation.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Fri Dec 01 11:32:32 2006 +0000 (2006-12-01)
parents 2e5291248789
children 3570295a44cb
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Fri Dec 01 11:08:34 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Fri Dec 01 11:32:32 2006 +0000
     1.3 @@ -23,6 +23,7 @@
     1.4  """
     1.5  
     1.6  import os
     1.7 +import stat
     1.8  import shutil
     1.9  import socket
    1.10  import threading
    1.11 @@ -44,7 +45,7 @@ from xen.xend.XendDevices import XendDev
    1.12  
    1.13  from xen.xend.xenstore.xstransact import xstransact
    1.14  from xen.xend.xenstore.xswatch import xswatch
    1.15 -from xen.util import security
    1.16 +from xen.util import mkdir, security
    1.17  from xen.xend import uuid
    1.18  
    1.19  xc = xen.lowlevel.xc.xc()
    1.20 @@ -99,11 +100,7 @@ class XendDomain:
    1.21          """Singleton initialisation function."""
    1.22  
    1.23          dom_path = self._managed_path()
    1.24 -        try:
    1.25 -            os.stat(dom_path)
    1.26 -        except OSError:
    1.27 -            log.info("Making %s", dom_path)
    1.28 -            os.makedirs(dom_path, 0755)
    1.29 +        mkdir.parents(dom_path, stat.S_IRWXU)
    1.30  
    1.31          xstransact.Mkdir(XS_VMROOT)
    1.32          xstransact.SetPermissions(XS_VMROOT, {'dom': DOM0_ID})
    1.33 @@ -271,25 +268,17 @@ class XendDomain:
    1.34              domains_dir = self._managed_path()
    1.35              dom_uuid = dominfo.get_uuid()            
    1.36              domain_config_dir = self._managed_path(dom_uuid)
    1.37 -        
    1.38 -            # make sure the domain dir exists
    1.39 -            if not os.path.exists(domains_dir):
    1.40 -                os.makedirs(domains_dir, 0755)
    1.41 -            elif not os.path.isdir(domains_dir):
    1.42 -                log.error("xend_domain_dir is not a directory.")
    1.43 -                raise XendError("Unable to save managed configuration "
    1.44 -                                "because %s is not a directory." %
    1.45 -                                domains_dir)
    1.46 -            
    1.47 -            if not os.path.exists(domain_config_dir):
    1.48 +
    1.49 +            def make_or_raise(path):
    1.50                  try:
    1.51 -                    os.makedirs(domain_config_dir, 0755)
    1.52 -                except IOError:
    1.53 -                    log.exception("Failed to create directory: %s" %
    1.54 -                                  domain_config_dir)
    1.55 -                    raise XendError("Failed to create directory: %s" %
    1.56 -                                    domain_config_dir)
    1.57 -                
    1.58 +                    mkdir.parents(path, stat.S_IRWXU)
    1.59 +                except:
    1.60 +                    log.exception("%s could not be created." % path)
    1.61 +                    raise XendError("%s could not be created." % path)
    1.62 +
    1.63 +            make_or_raise(domains_dir)
    1.64 +            make_or_raise(domain_config_dir)
    1.65 +
    1.66              try:
    1.67                  sxp_cache_file = open(self._managed_config_path(dom_uuid),'w')
    1.68                  prettyprint(dominfo.sxpr(), sxp_cache_file, width = 78)