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-unstable] Write the new version of the persisted co

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Write the new version of the persisted config to a tempfile and then rename it,
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sat, 16 Dec 2006 09:14:07 -0800
Delivery-date: Sat, 16 Dec 2006 09:33:20 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
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/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/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 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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Write the new version of the persisted config to a tempfile and then rename it,, Xen patchbot-unstable <=