From: Richard W.M. Jones Date: Fri, 28 Jan 2011 15:28:25 +0000 (+0000) Subject: Add a new internal-autosync API to perform autosync. X-Git-Tag: 1.9.7~7 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=d2636b0984830d950423dadd936114ff242c4a00 Add a new internal-autosync API to perform autosync. Instead of explicitly calling umount-all; sync, we add a daemon function called internal-autosync which does the same. Apart from slightly simplifying the process of closing the handle, the main advantage is we can modify the daemon for the standalone case so that internal-autosync does not do the umount-all operation. --- diff --git a/daemon/sync.c b/daemon/sync.c index b848ab5..25c7de8 100644 --- a/daemon/sync.c +++ b/daemon/sync.c @@ -43,6 +43,23 @@ do_sync (void) return 0; } +/* Older versions of libguestfs used to issue separate 'umount_all' + * and 'sync' commands just before closing the handle. Since + * libguestfs 1.9.7 the library issues this 'internal_autosync' + * internal operation instead, allowing more control in the daemon. + */ +int +do_internal_autosync (void) +{ + int r; + + r = do_umount_all (); + + sync_disks (); + + return r; +} + /* This is a replacement for sync(2) which is called from * this file and from other places in the daemon. It works * on Windows too. diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 77f1358..0ae8790 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -282,8 +282,8 @@ If C then no options are added."); "set autosync mode", "\ If C is true, this enables autosync. Libguestfs will make a -best effort attempt to run C followed by -C when the handle is closed +best effort attempt to make filesystems consistent and synchronized +when the handle is closed (also if the program exits without closing handles). This is enabled by default (since libguestfs 1.5.24, previously it was @@ -3842,7 +3842,7 @@ pathnames, as in the example code above. For more details see L Autosync [see C, this is set by default on -handles] means that C is called when the handle +handles] can cause C to be called when the handle is closed which can also trigger these issues."); ("rmmountpoint", (RErr, [String "exemptpath"], []), 149, [], @@ -5776,6 +5776,16 @@ C and read the C and C values. These two numbers, multiplied together, give the resulting size of the minimal filesystem in bytes."); + ("internal_autosync", (RErr, [], []), 282, [NotInFish; NotInDocs], + [], + "internal autosync operation", + "\ +This command performs the autosync operation just before the +handle is closed. You should not call this command directly. +Instead, use the autosync flag (C) to +control whether or not this operation is performed when the +handle is closed."); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 1473a88..e01062f 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -281 +282 diff --git a/src/guestfs.c b/src/guestfs.c index 488b658..79fc5bf 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -189,10 +189,8 @@ guestfs_close (guestfs_h *g) guestfs___free_inspect_info (g); /* Try to sync if autosync flag is set. */ - if (g->autosync && g->state == READY) { - guestfs_umount_all (g); - guestfs_sync (g); - } + if (g->autosync && g->state == READY) + guestfs_internal_autosync (g); /* Remove any handlers that might be called back before we kill the * subprocess.