[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] Write the new version of the persisted config to a tempfile and then rename it,



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1166203140 0
# Node ID 7cf33c0856d40596e880391701ddc304ced8b351
# Parent  9fd958cc51224b4890ad10c51f635ac81b1b8d35
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@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/XendDomain.py |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff -r 9fd958cc5122 -r 7cf33c0856d4 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Fri Dec 15 17:18:02 2006 +0000
+++ b/tools/python/xen/xend/XendDomain.py       Fri Dec 15 17:19:00 2006 +0000
@@ -26,6 +26,7 @@ import stat
 import stat
 import shutil
 import socket
+import tempfile
 import threading
 
 import xen.lowlevel.xc
@@ -280,16 +281,20 @@ class XendDomain:
             make_or_raise(domain_config_dir)
 
             try:
-                sxp_cache_file = open(self._managed_config_path(dom_uuid),'w')
-                prettyprint(dominfo.sxpr(), sxp_cache_file, width = 78)
-                sxp_cache_file.close()
+                fd, fn = tempfile.mkstemp()
+                f = os.fdopen(fd, 'w+b')
+                try:
+                    prettyprint(dominfo.sxpr(), f, width = 78)
+                finally:
+                    f.close()
+                try:
+                    os.rename(fn, self._managed_config_path(dom_uuid))
+                except:
+                    log.exception("Renaming %s" % fn)
+                    os.remove(fn)
             except:
                 log.exception("Error occurred saving configuration file " +
                               "to %s" % domain_config_dir)
-                try:
-                    self._managed_domain_remove(dom_uuid)
-                except:
-                    pass
                 raise XendError("Failed to save configuration file to: %s" %
                                 domain_config_dir)
         else:

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.