diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml index 1ef8ba5b4..baff68ef6 100644 --- a/v2v/convert_linux.ml +++ b/v2v/convert_linux.ml @@ -56,8 +56,7 @@ let string_of_kernel_info ki = ki.ki_supports_virtio ki.ki_is_xen_kernel (* The conversion function. *) -let rec convert ~keep_serial_console verbose (g : G.guestfs) - inspect source = +let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source = (*----------------------------------------------------------------------*) (* Inspect the guest first. We already did some basic inspection in * the common v2v.ml code, but that has to deal with generic guests @@ -1242,3 +1241,13 @@ let rec convert ~keep_serial_console verbose (g : G.guestfs) } in guestcaps + +let () = + let matching = function + | { i_type = "linux"; + i_distro = ("fedora" + | "rhel" | "centos" | "scientificlinux" | "redhat-based" + | "sles" | "suse-based" | "opensuse") } -> true + | _ -> false + in + Modules_list.register_convert_module matching "enterprise-linux" convert diff --git a/v2v/convert_linux.mli b/v2v/convert_linux.mli index 71c64354f..d47028158 100644 --- a/v2v/convert_linux.mli +++ b/v2v/convert_linux.mli @@ -15,5 +15,3 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) - -val convert : keep_serial_console:bool -> bool -> Guestfs.guestfs -> Types.inspect -> Types.source -> Types.guestcaps diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml index 563070a51..939977059 100644 --- a/v2v/convert_windows.ml +++ b/v2v/convert_windows.ml @@ -41,7 +41,7 @@ module G = Guestfs type ('a, 'b) maybe = Either of 'a | Or of 'b -let convert verbose (g : G.guestfs) inspect source = +let convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source = (* Get the data directory. *) let virt_tools_data_dir = try Sys.getenv "VIRT_TOOLS_DATA_DIR" @@ -477,3 +477,10 @@ echo uninstalling Xen PV driver } in guestcaps + +let () = + let matching = function + | { i_type = "windows" } -> true + | _ -> false + in + Modules_list.register_convert_module matching "windows" convert diff --git a/v2v/convert_windows.mli b/v2v/convert_windows.mli index 1ea07c4e6..d47028158 100644 --- a/v2v/convert_windows.mli +++ b/v2v/convert_windows.mli @@ -15,5 +15,3 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) - -val convert : bool -> Guestfs.guestfs -> Types.inspect -> Types.source -> Types.guestcaps diff --git a/v2v/modules_list.ml b/v2v/modules_list.ml index 7fedc7714..18f555716 100644 --- a/v2v/modules_list.ml +++ b/v2v/modules_list.ml @@ -26,3 +26,20 @@ and register_output_module name = let input_modules () = List.sort compare !input_modules and output_modules () = List.sort compare !output_modules + +type conversion_fn = + verbose:bool -> keep_serial_console:bool -> + Guestfs.guestfs -> Types.inspect -> Types.source -> Types.guestcaps + +let convert_modules = ref [] + +let register_convert_module inspect_fn name conversion_fn = + convert_modules := (inspect_fn, (name, conversion_fn)) :: !convert_modules + +let find_convert_module inspect = + let rec loop = function + | [] -> raise Not_found + | (inspect_fn, ret) :: _ when inspect_fn inspect -> ret + | _ :: rest -> loop rest + in + loop !convert_modules diff --git a/v2v/modules_list.mli b/v2v/modules_list.mli index 805ba8d21..4c41cc579 100644 --- a/v2v/modules_list.mli +++ b/v2v/modules_list.mli @@ -16,7 +16,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) -(** List of input and output modules. *) +(** List of input, output and conversion modules. *) val register_input_module : string -> unit (** Register an input module by name. *) @@ -29,3 +29,17 @@ val input_modules : unit -> string list val output_modules : unit -> string list (** Return the list of output modules. *) + +type conversion_fn = + verbose:bool -> keep_serial_console:bool -> + Guestfs.guestfs -> Types.inspect -> Types.source -> Types.guestcaps + +val register_convert_module : (Types.inspect -> bool) -> string -> conversion_fn -> unit +(** [register_convert_module inspect_fn name fn] registers a + conversion function [fn] that can accept any guest that matches + the [inspect_fn] function. *) + +val find_convert_module : Types.inspect -> string * conversion_fn +(** [find_convert_module inspect] returns the name and conversion + function for the guest with inspection data in [inspect], else + throws [Not_found]. *) diff --git a/v2v/v2v.ml b/v2v/v2v.ml index 8138b535a..cff5562ef 100644 --- a/v2v/v2v.ml +++ b/v2v/v2v.ml @@ -192,19 +192,16 @@ let rec main () = msg (f_"Converting %s to run on KVM") prod ); - match inspect.i_type, inspect.i_distro with - | "linux", ("fedora" - | "rhel" | "centos" | "scientificlinux" | "redhat-based" - | "sles" | "suse-based" | "opensuse") -> - (* RHEV doesn't support serial console so remove any on conversion. *) - let keep_serial_console = output#keep_serial_console in - Convert_linux.convert ~keep_serial_console verbose g inspect source + (* RHEV doesn't support serial console so remove any on conversion. *) + let keep_serial_console = output#keep_serial_console in - | "windows", _ -> Convert_windows.convert verbose g inspect source - - | typ, distro -> - error (f_"virt-v2v is unable to convert this guest type (%s/%s)") - typ distro in + let conversion_name, convert = + try Modules_list.find_convert_module inspect + with Not_found -> + error (f_"virt-v2v is unable to convert this guest type (%s/%s)") + inspect.i_type inspect.i_distro in + if verbose then printf "picked conversion module %s\n%!" conversion_name; + convert ~verbose ~keep_serial_console g inspect source in if do_copy then ( (* Doing fstrim on all the filesystems reduces the transfer size