[Pkg-libvirt-commits] [libguestfs] 150/266: v2v: Replace strings with variants for extra type safety.
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:41:54 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.
commit 3903f97cb38dfb0beaf26e37fb4f4a7a45850a74
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Thu Aug 21 14:49:43 2014 +0100
v2v: Replace strings with variants for extra type safety.
No functional change.
---
v2v/convert_linux.ml | 14 ++++++++------
v2v/convert_windows.ml | 18 +++++++++---------
v2v/output_RHEV.ml | 13 +++++++------
v2v/output_libvirt.ml | 26 +++++++++++++++-----------
v2v/types.ml | 9 ++++++---
v2v/types.mli | 18 ++++++++++++++----
6 files changed, 59 insertions(+), 39 deletions(-)
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index d7343c6..5b2ec7c 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -1000,9 +1000,11 @@ let rec convert ~keep_serial_console verbose (g : G.guestfs)
true
and get_display_driver () =
- if family = `SUSE_family then "cirrus" else "qxl"
+ if family = `SUSE_family then Cirrus else QXL
and configure_display_driver video =
+ let video_driver = match video with QXL -> "qxl" | Cirrus -> "cirrus" in
+
let updated = ref false in
let xorg_conf =
@@ -1019,7 +1021,7 @@ let rec convert ~keep_serial_console verbose (g : G.guestfs)
let paths = g#aug_match ("/files" ^ xorg_conf ^ "/Device/Driver") in
Array.iter (
fun path ->
- g#aug_set path video;
+ g#aug_set path video_driver;
updated := true
) paths;
@@ -1040,7 +1042,7 @@ let rec convert ~keep_serial_console verbose (g : G.guestfs)
not (g#is_file ~followsymlinks:true "/usr/bin/X11/X") then
warning ~prog
(f_"The display driver was updated to '%s', but X11 does not seem to be installed in the guest. X may not function correctly.")
- video
+ video_driver
and remap_block_devices virtio =
(* This function's job is to iterate over boot configuration
@@ -1209,10 +1211,10 @@ let rec convert ~keep_serial_console verbose (g : G.guestfs)
remap_block_devices virtio;
let guestcaps = {
- gcaps_block_bus = if virtio then "virtio" else "ide";
- gcaps_net_bus = if virtio then "virtio" else "e1000";
- gcaps_acpi = acpi;
+ gcaps_block_bus = if virtio then Virtio_blk else IDE;
+ gcaps_net_bus = if virtio then Virtio_net else E1000;
gcaps_video = video;
+ gcaps_acpi = acpi;
} in
guestcaps
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index b3b3d50..546c164 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -253,38 +253,38 @@ echo uninstalling Xen PV driver
warning ~prog (f_"there are no virtio drivers available for this version of Windows (%d.%d %s). virt-v2v looks for drivers in %s\n\nThe guest will be configured to use slower emulated devices.")
inspect.i_major_version inspect.i_minor_version
inspect.i_arch virtio_win_dir;
- ( "ide", "rtl8139" )
+ ( IDE, RTL8139 )
| Some path ->
(* Can we install the block driver? *)
- let block =
+ let block : guestcaps_block_type =
let block_path = path // "viostor.sys" in
if not (Sys.file_exists block_path) then (
warning ~prog (f_"there is no viostor (virtio block device) driver for this version of Windows (%d.%d %s). virt-v2v looks for this driver here: %s\n\nThe guest will be configured to use a slower emulated device.")
inspect.i_major_version inspect.i_minor_version
inspect.i_arch block_path;
- "ide"
+ IDE
)
else (
let target = sprintf "%s/system32/drivers/viostor.sys" systemroot in
let target = g#case_sensitive_path target in
g#cp block_path target;
add_viostor_to_critical_device_database root current_cs;
- "virtio"
+ Virtio_blk
) in
(* Can we install the virtio-net driver? *)
- let net =
+ let net : guestcaps_net_type =
let net_path = path // "netkvm.inf" in
if not (Sys.file_exists net_path) then (
warning ~prog (f_"there is no virtio network driver for this version of Windows (%d.%d %s). virt-v2v looks for this driver here: %s\n\nThe guest will be configured to use a slower emulated device.")
inspect.i_major_version inspect.i_minor_version
inspect.i_arch net_path;
- "rtl8139"
+ RTL8139
)
else
(* It will be installed at firstboot. *)
- "virtio" in
+ Virtio_net in
(* Copy the drivers to the driverdir. They will be installed at
* firstboot.
@@ -470,11 +470,11 @@ echo uninstalling Xen PV driver
let guestcaps = {
gcaps_block_bus = block_driver;
gcaps_net_bus = net_driver;
- gcaps_acpi = true;
(* Old virt-v2v would always present a QXL video display to converted
* guests. Unclear if this is correct. XXX
*)
- gcaps_video = "qxl";
+ gcaps_video = QXL;
+ gcaps_acpi = true;
} in
guestcaps
diff --git a/v2v/output_RHEV.ml b/v2v/output_RHEV.ml
index 51daeba..41eafad 100644
--- a/v2v/output_RHEV.ml
+++ b/v2v/output_RHEV.ml
@@ -495,7 +495,8 @@ object
"ovf:volume-type", output_alloc_for_rhev;
"ovf:format", "http://en.wikipedia.org/wiki/Byte"; (* wtf? *)
"ovf:disk-interface",
- if guestcaps.gcaps_block_bus = "virtio" then "VirtIO" else "IDE";
+ (match guestcaps.gcaps_block_bus with
+ | Virtio_blk -> "VirtIO" | IDE -> "IDE");
"ovf:disk-type", "System"; (* RHBZ#744538 *)
"ovf:boot", if is_boot_drive then "True" else "False";
] in
@@ -558,13 +559,13 @@ object
let model =
match guestcaps.gcaps_net_bus with
- | "rtl8139" -> "1"
- | "e1000" -> "2"
- | "virtio" -> "3"
- | bus ->
+ | RTL8139 -> "1"
+ | E1000 -> "2"
+ | Virtio_net -> "3"
+ (*| bus ->
warning ~prog (f_"unknown NIC model %s for ethernet device %s. This NIC will be imported as rtl8139 instead.")
bus dev;
- "1" in
+ "1" *) in
let network = e "Network" ["ovf:name", vnet] [] in
append_child network network_section;
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index aaa3e4b..c55e7f1 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -45,7 +45,11 @@ let create_libvirt_xml ?pool source overlays guestcaps =
let disks =
let block_prefix =
- if guestcaps.gcaps_block_bus = "virtio" then "vd" else "hd" in
+ match guestcaps.gcaps_block_bus with
+ | Virtio_blk -> "vd" | IDE -> "hd" in
+ let block_bus =
+ match guestcaps.gcaps_block_bus with
+ | Virtio_blk -> "virtio" | IDE -> "ide" in
List.mapi (
fun i ov ->
e "disk" [
@@ -70,7 +74,7 @@ let create_libvirt_xml ?pool source overlays guestcaps =
);
e "target" [
"dev", block_prefix ^ (drive_name i);
- "bus", guestcaps.gcaps_block_bus;
+ "bus", block_bus;
] [];
]
) overlays in
@@ -82,8 +86,8 @@ let create_libvirt_xml ?pool source overlays guestcaps =
*)
let cdrom_bus, cdrom_block_prefix, cdrom_index =
match guestcaps.gcaps_block_bus with
- | "virtio" | "ide" -> "ide", "hd", ref 0
- | bus -> bus, "sd", ref (List.length overlays) in
+ | Virtio_blk | IDE -> "ide", "hd", ref 0
+ (* | bus -> bus, "sd", ref (List.length overlays) *) in
(* Floppy disks always occupy their own virtual bus. *)
let fd_bus = "fdc" and fd_index = ref 0 in
@@ -110,6 +114,9 @@ let create_libvirt_xml ?pool source overlays guestcaps =
) source.s_removables in
let nics =
+ let net_model =
+ match guestcaps.gcaps_net_bus with
+ | Virtio_net -> "virtio" | E1000 -> "e1000" | RTL8139 -> "rtl8139" in
List.map (
fun { s_mac = mac; s_vnet_type = vnet_type; s_vnet = vnet } ->
let vnet_type_str =
@@ -119,7 +126,7 @@ let create_libvirt_xml ?pool source overlays guestcaps =
let nic =
e "interface" [ "type", vnet_type_str ] [
e "source" [ vnet_type_str, vnet ] [];
- e "model" [ "type", guestcaps.gcaps_net_bus ] [];
+ e "model" [ "type", net_model ] [];
] in
(match mac with
@@ -136,15 +143,12 @@ let create_libvirt_xml ?pool source overlays guestcaps =
let video, graphics =
let video, graphics =
match guestcaps.gcaps_video with
- | "qxl" ->
+ | QXL ->
e "video" [ "type", "qxl"; "ram", "65536" ] [],
e "graphics" [ "type", "vnc" ] []
- | "cirrus" ->
+ | Cirrus ->
e "video" [ "type", "cirrus"; "vram", "9216" ] [],
- e "graphics" [ "type", "spice" ] []
- | video_type ->
- e "video" [ "type", video_type ] [],
- e "graphics" [ "type", video_type (* ? *) ] [] in
+ e "graphics" [ "type", "spice" ] [] in
append_attr ("heads", "1") video;
diff --git a/v2v/types.ml b/v2v/types.ml
index 018045a..d364e07 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -166,11 +166,14 @@ type inspect = {
}
type guestcaps = {
- gcaps_block_bus : string;
- gcaps_net_bus : string;
+ gcaps_block_bus : guestcaps_block_type;
+ gcaps_net_bus : guestcaps_net_type;
+ gcaps_video : guestcaps_video_type;
gcaps_acpi : bool;
- gcaps_video : string;
}
+and guestcaps_block_type = Virtio_blk | IDE
+and guestcaps_net_type = Virtio_net | E1000 | RTL8139
+and guestcaps_video_type = QXL | Cirrus
type output_rhev_params = {
image_uuid : string option;
diff --git a/v2v/types.mli b/v2v/types.mli
index cf934ea..daa8360 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -107,13 +107,23 @@ type inspect = {
(** Inspection information. *)
type guestcaps = {
- gcaps_block_bus : string; (** "virtio", "ide", possibly others *)
- gcaps_net_bus : string; (** "virtio", "e1000", possibly others *)
- gcaps_acpi : bool; (** guest supports acpi *)
- gcaps_video : string; (** "qxl", "cirrus" *)
+ gcaps_block_bus : guestcaps_block_type;
+ gcaps_net_bus : guestcaps_net_type;
+ gcaps_video : guestcaps_video_type;
+ (** Best block device, ntework device and video device guest can
+ access. These are determined during conversion by inspecting the
+ guest (and in some cases conversion can actually enhance these by
+ installing drivers). Thus this is not known until after
+ conversion. *)
+
+ gcaps_acpi : bool; (** True if guest supports acpi. *)
}
(** Guest capabilities after conversion. eg. Was virtio found or installed? *)
+and guestcaps_block_type = Virtio_blk | IDE
+and guestcaps_net_type = Virtio_net | E1000 | RTL8139
+and guestcaps_video_type = QXL | Cirrus
+
class virtual input : bool -> object
method virtual as_options : string
(** Converts the input object back to the equivalent command line options.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list