Implemented autosync, make it the default for guestfish.
authorRichard Jones <rjones@redhat.com>
Sat, 4 Apr 2009 09:41:34 +0000 (10:41 +0100)
committerRichard Jones <rjones@redhat.com>
Sat, 4 Apr 2009 09:41:34 +0000 (10:41 +0100)
fish/fish.c
guestfs.pod
src/guestfs.c
src/guestfs.h

index fbb26de..90f3a10 100644 (file)
@@ -82,6 +82,7 @@ usage (void)
           "  -h|--cmd-help cmd   Display detailed help on 'cmd'\n"
           "  -a image            Add image\n"
           "  -m dev[:mnt]        Mount dev on mnt (if omitted, /)\n"
           "  -h|--cmd-help cmd   Display detailed help on 'cmd'\n"
           "  -a image            Add image\n"
           "  -m dev[:mnt]        Mount dev on mnt (if omitted, /)\n"
+          "  -n|--no-sync        Don't autosync\n"
           /*"  --ro|-r             All mounts are read-only\n"*/
           "  -v|--verbose        Verbose messages\n"
           "For more information, see the manpage guestfish(1).\n");
           /*"  --ro|-r             All mounts are read-only\n"*/
           "  -v|--verbose        Verbose messages\n"
           "For more information, see the manpage guestfish(1).\n");
@@ -96,6 +97,7 @@ main (int argc, char *argv[])
     { "cmd-help", 2, 0, 'h' },
     { "help", 0, 0, '?' },
     { "mount", 1, 0, 'm' },
     { "cmd-help", 2, 0, 'h' },
     { "help", 0, 0, '?' },
     { "mount", 1, 0, 'm' },
+    { "no-sync", 0, 0, 'n' },
     { "verbose", 0, 0, 'v' },
     { 0, 0, 0, 0 }
   };
     { "verbose", 0, 0, 'v' },
     { 0, 0, 0, 0 }
   };
@@ -113,6 +115,8 @@ main (int argc, char *argv[])
     exit (1);
   }
 
     exit (1);
   }
 
+  guestfs_set_autosync (g, 1);
+
   for (;;) {
     c = getopt_long (argc, argv, options, long_options, NULL);
     if (c == -1) break;
   for (;;) {
     c = getopt_long (argc, argv, options, long_options, NULL);
     if (c == -1) break;
@@ -153,6 +157,10 @@ main (int argc, char *argv[])
       mps = mp->next;
       break;
 
       mps = mp->next;
       break;
 
+    case 'n':
+      guestfs_set_autosync (g, 0);
+      break;
+
     case 'v':
       verbose++;
       guestfs_set_verbose (g, verbose);
     case 'v':
       verbose++;
       guestfs_set_verbose (g, verbose);
index 70082da..129c681 100644 (file)
@@ -237,6 +237,22 @@ situations.
 
 This returns the current out of memory handler.
 
 
 This returns the current out of memory handler.
 
+=head1 AUTOSYNC
+
+=head2 guestfs_set_autosync
+
+ void guestfs_set_autosync (guestfs_h *handle, int autosync);
+
+If C<autosync> is true, this enables autosync.  Libguestfs will make a
+best effort attempt to run C<guestfs_sync> when the handle is closed
+(also if the program exits without closing handles).
+
+=head2 guestfs_get_autosync
+
+ int guestfs_get_autosync (guestfs_h *handle);
+
+Get the autosync flag.
+
 =head1 VERBOSE MESSAGES
 
 =head2 guestfs_set_verbose
 =head1 VERBOSE MESSAGES
 
 =head2 guestfs_set_verbose
index 0c0a37f..747aae5 100644 (file)
@@ -116,6 +116,7 @@ struct guestfs_h
   int cmdline_size;
 
   int verbose;
   int cmdline_size;
 
   int verbose;
+  int autosync;
 
   /* Callbacks. */
   guestfs_abort_cb           abort_cb;
 
   /* Callbacks. */
   guestfs_abort_cb           abort_cb;
@@ -216,6 +217,10 @@ guestfs_close (guestfs_h *g)
   if (g->verbose)
     fprintf (stderr, "closing guestfs handle %p (state %d)\n", g, g->state);
 
   if (g->verbose)
     fprintf (stderr, "closing guestfs handle %p (state %d)\n", g, g->state);
 
+  /* Try to sync if autosync flag is set. */
+  if (g->autosync && g->state == READY)
+    guestfs_sync (g);
+
   /* Remove any handlers that might be called back before we kill the
    * subprocess.
    */
   /* Remove any handlers that might be called back before we kill the
    * subprocess.
    */
@@ -378,6 +383,18 @@ guestfs_get_verbose (guestfs_h *g)
   return g->verbose;
 }
 
   return g->verbose;
 }
 
+void
+guestfs_set_autosync (guestfs_h *g, int a)
+{
+  g->autosync = a;
+}
+
+int
+guestfs_get_autosync (guestfs_h *g)
+{
+  return g->autosync;
+}
+
 /* Add a string to the current command line. */
 static void
 incr_cmdline_size (guestfs_h *g)
 /* Add a string to the current command line. */
 static void
 incr_cmdline_size (guestfs_h *g)
index fbfcb3c..3a09b95 100644 (file)
@@ -51,8 +51,11 @@ extern guestfs_error_handler_cb guestfs_get_error_handler (guestfs_h *g, void **
 extern void guestfs_set_out_of_memory_handler (guestfs_h *g, guestfs_abort_cb);
 extern guestfs_abort_cb guestfs_get_out_of_memory_handler (guestfs_h *g);
 
 extern void guestfs_set_out_of_memory_handler (guestfs_h *g, guestfs_abort_cb);
 extern guestfs_abort_cb guestfs_get_out_of_memory_handler (guestfs_h *g);
 
+/* Misc. */
 extern void guestfs_set_verbose (guestfs_h *g, int verbose);
 extern int guestfs_get_verbose (guestfs_h *g);
 extern void guestfs_set_verbose (guestfs_h *g, int verbose);
 extern int guestfs_get_verbose (guestfs_h *g);
+extern void guestfs_set_autosync (guestfs_h *g, int a);
+extern int guestfs_get_autosync (guestfs_h *g);
 
 #include <guestfs-actions.h>
 
 
 #include <guestfs-actions.h>