psss / rpms / libguestfs

Forked from rpms/libguestfs 5 years ago
Clone
Blob Blame History Raw
From 5cfe8a0e678468318d8af403c197367979ba62a0 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 22 Oct 2013 22:28:27 +0100
Subject: [PATCH] builder: Add --no-sync option to avoid sync on exit.

(cherry picked from commit 3f46a92ed5737bb8d75630a39729f95bc96417f6)
---
 builder/builder.ml       |  5 +++--
 builder/cmdline.ml       |  6 +++++-
 builder/virt-builder.pod | 17 +++++++++++++++++
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/builder/builder.ml b/builder/builder.ml
index 477fc3e..7a46174 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -38,7 +38,7 @@ let main () =
     attach, cache, check_signature, curl, debug, delete, edit, fingerprint,
     firstboot, run, format, gpg, hostname, install, list_long, network, output,
     password_crypto, quiet, root_password, scrub, scrub_logfile, size, source,
-    upload =
+    sync, upload =
     parse_cmdline () in
 
   (* Timestamped messages in ordinary, non-debug non-quiet mode. *)
@@ -727,7 +727,8 @@ exec >>%s 2>&1
    * and therefore bypasses the host cache).  In general you should not
    * use cache=none.
    *)
-  Fsync.file output;
+  if sync then
+    Fsync.file output;
 
   (* Now that we've finished the build, don't delete the output file on
    * exit.
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
index 780e171..41d2a64 100644
--- a/builder/cmdline.ml
+++ b/builder/cmdline.ml
@@ -161,6 +161,8 @@ let parse_cmdline () =
     with Not_found -> "http://libguestfs.org/download/builder/index.asc" in
   let source = ref source in
 
+  let sync = ref true in
+
   let upload = ref [] in
   let add_upload arg =
     let i =
@@ -232,6 +234,7 @@ let parse_cmdline () =
     "--scrub",   Arg.String add_scrub,      "name" ^ " " ^ s_"Scrub a file";
     "--size",    Arg.String set_size,       "size" ^ " " ^ s_"Set output disk size";
     "--source",  Arg.Set_string source,     "URL" ^ " " ^ s_"Set source URL";
+    "--no-sync", Arg.Clear sync,            " " ^ s_"Do not fsync output file on exit";
     "--upload",  Arg.String add_upload,     "file:dest" ^ " " ^ s_"Upload file to dest";
     "-v",        Arg.Set debug,             " " ^ s_"Enable debugging messages";
     "--verbose", Arg.Set debug,             ditto;
@@ -287,6 +290,7 @@ read the man page virt-builder(1).
   let scrub_logfile = !scrub_logfile in
   let size = !size in
   let source = !source in
+  let sync = !sync in
   let upload = List.rev !upload in
 
   (* Check options. *)
@@ -343,4 +347,4 @@ read the man page virt-builder(1).
   attach, cache, check_signature, curl, debug, delete, edit, fingerprint,
   firstboot, run, format, gpg, hostname, install, list_long, network, output,
   password_crypto, quiet, root_password, scrub, scrub_logfile, size, source,
-  upload
+  sync, upload
diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod
index 094b327..c3ea581 100644
--- a/builder/virt-builder.pod
+++ b/builder/virt-builder.pod
@@ -410,6 +410,23 @@ You don't have a host network (eg. in secure/restricted environments).
 
 =back
 
+=item B<--no-sync>
+
+Do not sync the output file on exit.
+
+Virt-builder fsync's the output file or disk image when it exits.
+
+The reason is that qemu/KVM's default caching mode is C<none> or
+C<directsync>, both of which bypass the host page cache.  Therefore
+these would not work correctly if you immediately started the guest
+after running virt-builder - they would not see the complete output
+file.  (Note that you should not use these caching modes - they are
+fundamentally broken for this and other reasons.)
+
+If you are not using these broken caching modes, you can use
+I<--no-sync> to avoid this unnecessary sync and gain considerable
+extra performance.
+
 =item B<--notes> os-version
 
 List any notes associated with this guest, then exit (this does not do
-- 
1.8.3.1