[Libguestfs] [PATCH] Enable autosync by default.

Richard W.M. Jones rjones at redhat.com
Mon Oct 25 12:27:04 UTC 2010


By a very strict reading, this is an API change.

Matt argues (and I agree) that if you really depend on autosync being
off by default, then you were depending on the undefined behaviour
that happens when you kill the qemu container without first doing
sync.  ie. Data might or might not have been written, depending on how
fast the kernel was writing to disk versus how soon the container got
killed.

On the other hand, this is a frequent cause of problems when using the
API (see http://libguestfs.org/guestfs.3.html#libguestfs_gotchas) and
changing the default means this problem goes away.

You can revert to the old behaviour by adding:

  guestfs_set_autosync (g, 0);

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://et.redhat.com/~rjones/libguestfs/
See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
-------------- next part --------------
>From c95daea3f74bb85691ea6738bbb285cf1fde1b66 Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones <rjones at redhat.com>
Date: Mon, 25 Oct 2010 13:22:17 +0100
Subject: [PATCH] Enable autosync by default.

---
 TODO                           |    1 -
 fish/fish.c                    |    2 --
 fuse/guestmount.c              |    1 -
 generator/generator_actions.ml |    6 +++---
 src/guestfs.c                  |    1 +
 src/guestfs.pod                |    3 +++
 6 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/TODO b/TODO
index e9716f2..6ab6dc6 100644
--- a/TODO
+++ b/TODO
@@ -181,7 +181,6 @@ To mount read-only, add C<ro =E<gt> 1> like this:
 which is equivalent to the following sequence of calls:
 
  $h = Sys::Guestfs->new ();
- $h->set_autosync (1);
  $h->add_drive_ro ($filename);
  $h->launch ();
  $h->mount_ro (\"/dev/sda1\", \"/\");
diff --git a/fish/fish.c b/fish/fish.c
index 7cb2e71..8da4ffd 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -230,8 +230,6 @@ main (int argc, char *argv[])
     exit (EXIT_FAILURE);
   }
 
-  guestfs_set_autosync (g, 1);
-
   /* If developing, add ./appliance to the path.  Note that libtools
    * interferes with this because uninstalled guestfish is a shell
    * script that runs the real program with an absolute path.  Detect
diff --git a/fuse/guestmount.c b/fuse/guestmount.c
index 9665059..d17982a 100644
--- a/fuse/guestmount.c
+++ b/fuse/guestmount.c
@@ -982,7 +982,6 @@ main (int argc, char *argv[])
     exit (EXIT_FAILURE);
   }
 
-  guestfs_set_autosync (g, 1);
   guestfs_set_recovery_proc (g, 0);
 
   ADD_FUSE_ARG (program_name);
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index 38f1db3..8add55f 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -286,11 +286,11 @@ best effort attempt to run C<guestfs_umount_all> followed by
 C<guestfs_sync> when the handle is closed
 (also if the program exits without closing handles).
 
-This is disabled by default (except in guestfish where it is
-enabled by default).");
+This is enabled by default (since libguestfs 1.5.24, previously it was
+disabled by default).");
 
   ("get_autosync", (RBool "autosync", [], []), -1, [],
-   [InitNone, Always, TestRun (
+   [InitNone, Always, TestOutputTrue (
       [["get_autosync"]])],
    "get autosync mode",
    "\
diff --git a/src/guestfs.c b/src/guestfs.c
index f79aaed..245f10c 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -99,6 +99,7 @@ guestfs_create (void)
   g->error_cb_data = NULL;
 
   g->recovery_proc = 1;
+  g->autosync = 1;
 
   str = getenv ("LIBGUESTFS_DEBUG");
   g->verbose = str != NULL && STREQ (str, "1");
diff --git a/src/guestfs.pod b/src/guestfs.pod
index c1e595c..305aa38 100644
--- a/src/guestfs.pod
+++ b/src/guestfs.pod
@@ -701,6 +701,9 @@ Note that in L<guestfish(3)> autosync is the default.  So quick and
 dirty guestfish scripts that forget to sync will work just fine, which
 can make this very puzzling if you are trying to debug a problem.
 
+Update: Autosync is enabled by default for all API users starting from
+libguestfs 1.5.24.
+
 =item Mount option C<-o sync> should not be the default.
 
 If you use L</guestfs_mount>, then C<-o sync,noatime> are added
-- 
1.7.3.1



More information about the Libguestfs mailing list