[Libguestfs] [PATCH 05/11] v2v: xen: Replace qemu block ssh driver with nbdkit-ssh-plugin.

Richard W.M. Jones rjones at redhat.com
Mon Apr 8 11:10:11 UTC 2019


Initially this is a like-for-like replacement, but in future commits
this will allow us to implement:

 - password authentication (instead of SSH agent)

 - bandwidth throttling

 - readahead

Note this requires nbdkit >= 1.12.
---
 docs/guestfs-building.pod    |  5 +++-
 v2v/input_libvirt_xen_ssh.ml | 48 +++++++++---------------------------
 v2v/nbdkit.ml                |  4 +--
 3 files changed, 17 insertions(+), 40 deletions(-)

diff --git a/docs/guestfs-building.pod b/docs/guestfs-building.pod
index 47efe34a5..c9693d277 100644
--- a/docs/guestfs-building.pod
+++ b/docs/guestfs-building.pod
@@ -268,7 +268,7 @@ Optional.  Used only for testing.
 
 =item qemu-nbd
 
-=item nbdkit
+=item nbdkit E<ge> 1.12
 
 Optional.  qemu-nbd is used for testing.
 
@@ -276,6 +276,9 @@ L<virt-p2v(1)> requires either qemu-nbd or nbdkit, but these only need
 to be present on the virt-p2v ISO, they do not need to be installed at
 compile time.
 
+L<virt-v2v(1)> requires nbdkit E<ge> 1.12 for various input and output
+modes.
+
 =item uml_mkcow
 
 Optional.  For the L<UML backend|guestfs(3)/BACKEND>.
diff --git a/v2v/input_libvirt_xen_ssh.ml b/v2v/input_libvirt_xen_ssh.ml
index 6b77db029..cae6dac4d 100644
--- a/v2v/input_libvirt_xen_ssh.ml
+++ b/v2v/input_libvirt_xen_ssh.ml
@@ -50,18 +50,15 @@ object
                                     ?conn:input_conn guest in
     let source, disks = parse_libvirt_xml ?conn:input_conn xml in
 
+    let port =
+      match parsed_uri.uri_port with
+      | 0 | 22 -> None
+      | i -> Some (string_of_int i) in
+
+    let user = parsed_uri.uri_user in
+
     (* Map the <source/> filename (which is relative to the remote
-     * Xen server) to an ssh URI.  This is a JSON URI looking something
-     * like this:
-     *
-     * json: {
-     *   "file.driver": "ssh",
-     *   "file.user": "username",
-     *   "file.host": "xen-host",
-     *   "file.port": 1022,
-     *   "file.path": <remote-path>,
-     *   "file.host_key_check": "no"
-     * }
+     * Xen server) to an ssh URI pointing to nbdkit.
      *)
     let disks = List.map (
       function
@@ -69,32 +66,9 @@ object
         disk
       | { p_source_disk = disk; p_source = P_source_dev path }
       | { p_source_disk = disk; p_source = P_source_file path } ->
-        (* Construct the JSON parameters. *)
-        let json_params = [
-          "file.driver", JSON.String "ssh";
-          "file.path", JSON.String path;
-          "file.host", JSON.String server;
-          "file.host_key_check", JSON.String "no";
-        ] in
-
-        let json_params =
-          match parsed_uri.uri_port with
-          | 0 | 22 -> json_params
-          (* qemu will actually assert-fail if you send the port
-           * number as a string ...
-           *)
-          | i -> ("file.port", JSON.Int (Int64.of_int i)) :: json_params in
-
-        let json_params =
-          match parsed_uri.uri_user with
-          | None -> json_params
-          | Some user -> ("file.user", JSON.String user) :: json_params in
-
-        debug "ssh: json parameters: %s" (JSON.string_of_doc json_params);
-
-        (* Turn the JSON parameters into a 'json:' protocol string. *)
-        let qemu_uri = "json: " ^ JSON.string_of_doc json_params in
-
+         let nbdkit = Nbdkit.create_ssh ~password:NoPassword
+                                        ?port ~server ?user path in
+         let qemu_uri = Nbdkit.run nbdkit in
         { disk with s_qemu_uri = qemu_uri }
     ) disks in
 
diff --git a/v2v/nbdkit.ml b/v2v/nbdkit.ml
index 67e0d363a..e67a83b6a 100644
--- a/v2v/nbdkit.ml
+++ b/v2v/nbdkit.ml
@@ -26,8 +26,8 @@ open Unix_utils
 
 open Utils
 
-let nbdkit_min_version = (1, 2)
-let nbdkit_min_version_string = "1.2"
+let nbdkit_min_version = (1, 12)
+let nbdkit_min_version_string = "1.12"
 
 type password =
 | NoPassword                    (* no password option at all *)
-- 
2.20.1




More information about the Libguestfs mailing list