Improve copy function
authorRichard W.M. Jones <rjones@redhat.com>
Thu, 7 Feb 2008 18:55:26 +0000 (18:55 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Thu, 7 Feb 2008 18:55:26 +0000 (18:55 +0000)
 - Allow ssh compression to be disabled.
 - Optional label for the Back button.
 - Check return value from write syscall.
 - Print speed of copy in Mbps.
 - Documentation update.

virt-p2v
virt-p2v.1
virt-p2v.1.html
virt-p2v.1.txt
virt-p2v.pod

index d54da3a..ad9e159 100755 (executable)
--- a/virt-p2v
+++ b/virt-p2v
@@ -46,6 +46,7 @@ type state = { greeting : bool;
               architecture : architecture option;
               memory : int option; vcpus : int option;
               mac_address : string option;
+              compression : bool option;
             }
 and network = Auto
            | Shell
@@ -93,6 +94,7 @@ let defaults = {
   memory = None;
   vcpus = None;
   mac_address = None;
+  compression = None;
 }
 (* END OF CUSTOM virt-p2v SCRIPT SECTION.                               *)
 (*----------------------------------------------------------------------*)
@@ -199,11 +201,15 @@ let msgbox, yesno, inputbox, radiolist, checklist, form =
   in
 
   (* Handle the common parameters.  Note Continuation Passing Style. *)
-  let with_common cont ?(cancel=false) ?(backbutton=true) title =
+  let with_common cont
+      ?(cancel=false)
+      ?(backbutton=true) ?(backbutton_label="Back")
+      title =
     let params = ["--title"; title] in
     let params = if not cancel then "--nocancel" :: params else params in
     let params =
-      if backbutton then "--extra-button" :: "--extra-label" :: "Back" :: params
+      if backbutton then
+       "--extra-button" :: "--extra-label" :: backbutton_label :: params
       else params in
     cont params
   in
@@ -1023,6 +1029,19 @@ let rec main ttyname =
     | Back -> Prev
   in
 
+  let ask_compression state =
+    match
+    radiolist "Network compression" "Enable network compression" 10 50 2 [
+      "yes", "Yes, compress network traffic", state.compression <> Some false;
+      "no", "No, don't compress", state.compression = Some false
+    ]
+    with
+    | Yes ("no"::_) -> Next { state with compression = Some false }
+    | Yes _ -> Next { state with compression = Some true }
+    | No | Help | Error -> Ask_again
+    | Back -> Prev
+  in
+
   let ask_verify state =
     match
     yesno "Verify and proceed"
@@ -1037,7 +1056,8 @@ Hypervisor:   %s
 Architecture: %s
 Memory:       %s
 VCPUs:        %s
-MAC address:  %s"
+MAC address:  %s
+Compression:  %b"
          (Option.default "" state.remote_host)
          (Option.default "" state.remote_port)
          (Option.default "" state.remote_directory)
@@ -1061,6 +1081,7 @@ MAC address:  %s"
          | Some vcpus -> string_of_int vcpus | None -> "")
          (match state.mac_address with
          | Some "" -> "Random" | Some mac -> mac | None -> "")
+         (Option.default true state.compression)
       )
       21 50
     with
@@ -1097,6 +1118,7 @@ MAC address:  %s"
     ask_memory,        defaults.memory <> None,           dont_skip;
     ask_vcpus,         defaults.vcpus <> None,            dont_skip;
     ask_mac_address,   defaults.mac_address <> None,      dont_skip;
+    ask_compression,   defaults.compression <> None,      dont_skip;
     ask_verify,        not defaults.greeting,             dont_skip;
   |] in
 
@@ -1250,7 +1272,8 @@ MAC address:  %s"
 
   (* Functions to connect and disconnect from the remote system. *)
   let do_connect remote_name _ =
-    let cmd = sprintf "ssh -C -l %s -p %s %s \"cat > %s/%s\""
+    let cmd = sprintf "ssh%s -l %s -p %s %s \"cat > %s/%s\""
+      (if state.compression = Some false then "" else " -C")
       (quote remote_username) (quote remote_port) (quote remote_host)
       (quote remote_directory) (quote remote_name) in
     eprintf "connect: %s\n%!" cmd;
@@ -1459,7 +1482,8 @@ MAC address:  %s"
       let rec copy bytes_sent last_printed_at =
        let n = read fd buffer 0 bufsize in
        if n > 0 then (
-         ignore (write sock buffer 0 n);
+         let n' = write sock buffer 0 n in
+         if n <> n' then assert false; (* never, according to the manual *)
 
          let bytes_sent = Int64.add bytes_sent (Int64.of_int n) in
          let last_printed_at =
@@ -1468,19 +1492,20 @@ MAC address:  %s"
            if now -. last_printed_at > 5. then (
              let elapsed = Int64.to_float bytes_sent /. Int64.to_float size in
              let secs_elapsed = now -. start in
-             printf "%.0f%%" (100. *. elapsed);
+             printf "%.0f%% @ %.1f Mbps"
+               (100. *. elapsed)
+               (Int64.to_float bytes_sent/.secs_elapsed/.1_000_000. *. 8.);
              (* After 60 seconds has elapsed, start printing estimates. *)
              if secs_elapsed >= 60. then (
                let remaining = 1. -. elapsed in
                let secs_remaining = (remaining /. elapsed) *. secs_elapsed in
                if secs_remaining > 120. then
-                 printf " (about %.0f minutes remaining)          "
-                   (secs_remaining /. 60.)
+                 printf " (about %.0f minutes remaining)" (secs_remaining/.60.)
                else
-                 printf " (about %.0f seconds remaining)          "
+                 printf " (about %.0f seconds remaining)"
                    secs_remaining
              );
-             printf "\r%!";
+             printf "          \r%!";
              now
            )
            else last_printed_at in
@@ -1489,11 +1514,14 @@ MAC address:  %s"
        )
       in
       copy 0L start;
+      printf "\n\n%!"; (* because of the messages printed above *)
 
       (* Disconnect. *)
       do_disconnect conn
   ) devices_to_send;
 
+  (*printf "\n\nPress any key ...\n%!"; ignore (read_line ());*)
+
   (* Clean up and reboot. *)
   ignore (
     msgbox "virt-p2v completed"
index b03b428..9020837 100644 (file)
 .\" ========================================================================
 .\"
 .IX Title "VIRT-P2V 1"
-.TH VIRT-P2V 1 "2008-02-05" "virt-p2v-0.9.3" "Virtualization Support"
+.TH VIRT-P2V 1 "2008-02-07" "virt-p2v-0.9.3" "Virtualization Support"
 .SH "NAME"
 virt\-p2v \- P2V (physical to virtual machine) migration tool
 .SH "SUMMARY"
@@ -298,6 +298,16 @@ within the \f(CW\*(C`00:16:3e:..\*(C'\fR space reserved for Xen guests.  These \
 addresses are not tested for uniqueness so there is a very small
 chance that they could coincide, which would leave a guest unable to
 access the virtual network.
+.IP "Compression" 4
+.IX Item "Compression"
+Choose whether to enable or disable compression on disk images as they
+are copied across the network.
+.Sp
+If enabled, the \f(CW\*(C`\-C\*(C'\fR option is passed to \fIssh\fR\|(1).  On fast networks
+this can sometimes be slower.
+.Sp
+\&\s-1NB:\s0 The disk image is still stored uncompressed on the remote host
+however this option is set.
 .IP "Verify and proceed" 4
 .IX Item "Verify and proceed"
 In this step you are asked to verify the settings above.  If any are
@@ -541,6 +551,11 @@ will choose a random \s-1MAC\s0 address within the \f(CW\*(C`00:16:3e:..\*(C'\fR
 reserved for Xen guests.  These \s-1MAC\s0 addresses are not tested for
 uniqueness so there is a very small chance that they could coincide,
 which would leave a guest unable to access the virtual network.
+.ie n .IP """compression""" 4
+.el .IP "\f(CWcompression\fR" 4
+.IX Item "compression"
+Set this to \f(CW\*(C`Some false\*(C'\fR to disable compression, or \f(CW\*(C`Some true\*(C'\fR to
+enable compression, or \f(CW\*(C`None\*(C'\fR to ask the user.
 .Sh "\s-1ISO\s0 \s-1ATTACHMENTS\s0"
 .IX Subsection "ISO ATTACHMENTS"
 Rebuilding a custom \s-1ISO\s0 is time\-consuming.  You can make a \*(L"quick\*(R"
index 89e6f69..a4fa6e5 100644 (file)
@@ -278,6 +278,21 @@ chance that they could coincide, which would leave a guest unable to
 access the virtual network.</p>
 </dd>
 </li>
+<dt><strong><a name="item_compression">Compression</a></strong>
+
+<dd>
+<p>Choose whether to enable or disable compression on disk images as they
+are copied across the network.</p>
+</dd>
+<dd>
+<p>If enabled, the <code>-C</code> option is passed to <em>ssh(1)</em>.  On fast networks
+this can sometimes be slower.</p>
+</dd>
+<dd>
+<p>NB: The disk image is still stored uncompressed on the remote host
+however this option is set.</p>
+</dd>
+</li>
 <dt><strong><a name="item_verify_and_proceed">Verify and proceed</a></strong>
 
 <dd>
@@ -565,6 +580,13 @@ uniqueness so there is a very small chance that they could coincide,
 which would leave a guest unable to access the virtual network.</p>
 </dd>
 </li>
+<dt><strong><a name="item_compression"><code>compression</code></a></strong>
+
+<dd>
+<p>Set this to <code>Some false</code> to disable compression, or <code>Some true</code> to
+enable compression, or <code>None</code> to ask the user.</p>
+</dd>
+</li>
 </dl>
 <p>
 </p>
index 795e739..81ded16 100644 (file)
@@ -165,6 +165,16 @@ STANDARD USAGE
         chance that they could coincide, which would leave a guest unable to
         access the virtual network.
 
+    Compression
+        Choose whether to enable or disable compression on disk images as
+        they are copied across the network.
+
+        If enabled, the "-C" option is passed to ssh(1). On fast networks
+        this can sometimes be slower.
+
+        NB: The disk image is still stored uncompressed on the remote host
+        however this option is set.
+
     Verify and proceed
         In this step you are asked to verify the settings above. If any are
         incorrect, use the *Back* button to navigate back to the setting. If
@@ -368,6 +378,10 @@ BUILDING A CUSTOM LIVE CD
         uniqueness so there is a very small chance that they could coincide,
         which would leave a guest unable to access the virtual network.
 
+    "compression"
+        Set this to "Some false" to disable compression, or "Some true" to
+        enable compression, or "None" to ask the user.
+
   ISO ATTACHMENTS
     Rebuilding a custom ISO is time-consuming. You can make a "quick"
     developer ISO by updating an existing ISO image with a new custom
index 3018389..6978b2f 100644 (file)
@@ -187,6 +187,17 @@ addresses are not tested for uniqueness so there is a very small
 chance that they could coincide, which would leave a guest unable to
 access the virtual network.
 
+=item Compression
+
+Choose whether to enable or disable compression on disk images as they
+are copied across the network.
+
+If enabled, the C<-C> option is passed to L<ssh(1)>.  On fast networks
+this can sometimes be slower.
+
+NB: The disk image is still stored uncompressed on the remote host
+however this option is set.
+
 =item Verify and proceed
 
 In this step you are asked to verify the settings above.  If any are
@@ -436,6 +447,11 @@ reserved for Xen guests.  These MAC addresses are not tested for
 uniqueness so there is a very small chance that they could coincide,
 which would leave a guest unable to access the virtual network.
 
+=item C<compression>
+
+Set this to C<Some false> to disable compression, or C<Some true> to
+enable compression, or C<None> to ask the user.
+
 =back
 
 =head2 ISO ATTACHMENTS