[libvirt] [PATCH] Make saving domain XML more robust
Daniel P. Berrange
berrange at redhat.com
Thu Oct 6 10:54:28 UTC 2011
On Thu, Oct 06, 2011 at 12:22:01PM +0200, Jiri Denemark wrote:
> When saving domain XML (either config or status) we just overwrite old
> content of the file. In case something fails during that process (e.g.
> disk gets full) we lose both old and new content. This patch makes the
> process more robust by writing the new content into a separate file and
> only if that succeeds the original file is atomically replaced with the
> new one.
> ---
> src/conf/domain_conf.c | 25 +++++++++++++++++++++----
> 1 files changed, 21 insertions(+), 4 deletions(-)
By doing this you've almost addressed this BZ...
https://bugzilla.redhat.com/show_bug.cgi?id=489946
...almost...
Checkout slides 78 -> 119 of the presentation linked there,
paying note to the horrible tales of woe about OS-X and fsync() :-(
We probably want to add some kind of virFileSync(int fd) API call
that does the neccessary black magic.
>
> if (VIR_CLOSE(fd) < 0) {
> virReportSystemError(errno,
> _("cannot save config file '%s'"),
> - configFile);
> + newfile);
> + goto cleanup;
> + }
> +
> + if (rename(newfile, configFile) < 0) {
> + virReportSystemError(errno,
> + _("cannot rename config file '%s' as '%s'"),
> + newfile, configFile);
> goto cleanup;
> }
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list