ia64/xen-unstable
changeset 13073:7cf33c0856d4
Write the new version of the persisted config to a tempfile and then rename it,
to avoid corrupting the file on failure.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
to avoid corrupting the file on failure.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | Ewan Mellor <ewan@xensource.com> |
---|---|
date | Fri Dec 15 17:19:00 2006 +0000 (2006-12-15) |
parents | 9fd958cc5122 |
children | 63e72c3254da |
files | tools/python/xen/xend/XendDomain.py |
line diff
1.1 --- a/tools/python/xen/xend/XendDomain.py Fri Dec 15 17:18:02 2006 +0000 1.2 +++ b/tools/python/xen/xend/XendDomain.py Fri Dec 15 17:19:00 2006 +0000 1.3 @@ -26,6 +26,7 @@ import os 1.4 import stat 1.5 import shutil 1.6 import socket 1.7 +import tempfile 1.8 import threading 1.9 1.10 import xen.lowlevel.xc 1.11 @@ -280,16 +281,20 @@ class XendDomain: 1.12 make_or_raise(domain_config_dir) 1.13 1.14 try: 1.15 - sxp_cache_file = open(self._managed_config_path(dom_uuid),'w') 1.16 - prettyprint(dominfo.sxpr(), sxp_cache_file, width = 78) 1.17 - sxp_cache_file.close() 1.18 + fd, fn = tempfile.mkstemp() 1.19 + f = os.fdopen(fd, 'w+b') 1.20 + try: 1.21 + prettyprint(dominfo.sxpr(), f, width = 78) 1.22 + finally: 1.23 + f.close() 1.24 + try: 1.25 + os.rename(fn, self._managed_config_path(dom_uuid)) 1.26 + except: 1.27 + log.exception("Renaming %s" % fn) 1.28 + os.remove(fn) 1.29 except: 1.30 log.exception("Error occurred saving configuration file " + 1.31 "to %s" % domain_config_dir) 1.32 - try: 1.33 - self._managed_domain_remove(dom_uuid) 1.34 - except: 1.35 - pass 1.36 raise XendError("Failed to save configuration file to: %s" % 1.37 domain_config_dir) 1.38 else: