From bded1ee8373d81137615dacf07abad8193d0454a Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 5 Apr 2019 11:27:21 +0100 Subject: [PATCH] v2v: -i libvirtxml: Replace qemu block curl driver with nbdkit-curl-plugin. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ‘virt-v2v -i libvirtxml’ has a little-known feature where it can read network disks over HTTP or HTTPS. This can be used to test VMware conversions without needing VMware, although as far as I can tell the current test suite does not use the feature. This commit changes this functionality to use nbdkit-curl-plugin instead of the qemu curl driver. This change shouldn't affect functionality. The readahead size is changed from a fixed 1M buffer to using the readahead filter which is self-configuring. See also commit 38bf2a0f97c2e814d28c447ff6856bdd2d68df36 which originally introduced this functionality in 2017. --- v2v/parse_libvirt_xml.ml | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/v2v/parse_libvirt_xml.ml b/v2v/parse_libvirt_xml.ml index 95273c89c..97d8a5cd8 100644 --- a/v2v/parse_libvirt_xml.ml +++ b/v2v/parse_libvirt_xml.ml @@ -46,31 +46,6 @@ let get_drive_slot str offset = warning (f_"could not parse device name ‘%s’ from the source libvirt XML") str; None -(* Create a JSON URI for qemu referring to a remote CURL (http/https) - * resource. See also [v2v/vCenter.ml]. - *) -let create_curl_qemu_uri driver host port path = - let url = - let port = - match driver, port with - | _, None -> "" - | "https", Some 443 -> "" - | "http", Some 80 -> "" - | _, Some port when port >= 1 -> ":" ^ string_of_int port - | _, Some port -> invalid_arg "invalid port number in libvirt XML" in - sprintf "%s://%s%s%s" driver host port (uri_quote path) in - - let json_params = [ - "file.driver", JSON.String driver; (* "http" or "https" *) - "file.url", JSON.String url; - "file.timeout", JSON.Int 2000_L; - "file.readahead", JSON.Int (1024_L *^ 1024_L); - (* "file.sslverify", JSON.String "off"; XXX *) - ] in - - (* Turn the JSON parameters into a 'json:' protocol string. *) - "json: " ^ JSON.string_of_doc json_params - let parse_libvirt_xml ?conn xml = debug "libvirt xml is:\n%s" xml; @@ -334,7 +309,18 @@ let parse_libvirt_xml ?conn xml = * without needing VMware around. *) let path = Option.default "" (xpath_string "source/@name") in - let qemu_uri = create_curl_qemu_uri driver host port path in + let url = + let port = + match driver, port with + | _, None -> "" + | "https", Some 443 -> "" + | "http", Some 80 -> "" + | _, Some port when port >= 1 -> ":" ^ string_of_int port + | _, Some port -> + invalid_arg "invalid port number in libvirt XML" in + sprintf "%s://%s%s%s" driver host port (uri_quote path) in + let nbdkit = Nbdkit.create_curl ~password:NoPassword url in + let qemu_uri = Nbdkit.run nbdkit in add_disk qemu_uri format controller P_dont_rewrite | Some protocol, _, _ -> warning (f_" with was ignored")