|
|
ffd6ed |
From a71e0ff19b9cbb8942fbeacecd317ba888452b16 Mon Sep 17 00:00:00 2001
|
|
|
ffd6ed |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
ffd6ed |
Date: Wed, 24 Dec 2014 18:10:37 +0000
|
|
|
ffd6ed |
Subject: [PATCH] v2v: Reduce use of polymorphic variants.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
Ordinary variants prevent coding errors.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
(cherry picked from commit 3a080c3fbffa5846f71528c6fd978be7853b33b8)
|
|
|
ffd6ed |
---
|
|
|
ffd6ed |
v2v/convert_linux.ml | 6 +++---
|
|
|
ffd6ed |
v2v/input_disk.ml | 2 +-
|
|
|
ffd6ed |
v2v/input_libvirtxml.ml | 20 ++++++++++----------
|
|
|
ffd6ed |
v2v/input_ova.ml | 8 ++++----
|
|
|
ffd6ed |
v2v/output_libvirt.ml | 4 ++--
|
|
|
ffd6ed |
v2v/output_qemu.ml | 6 +++---
|
|
|
ffd6ed |
v2v/types.ml | 18 ++++++++++--------
|
|
|
ffd6ed |
v2v/types.mli | 13 ++++++++-----
|
|
|
ffd6ed |
8 files changed, 41 insertions(+), 36 deletions(-)
|
|
|
ffd6ed |
|
|
|
ffd6ed |
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
|
|
|
ffd6ed |
index 67de2b1..718ddaf 100644
|
|
|
ffd6ed |
--- a/v2v/convert_linux.ml
|
|
|
ffd6ed |
+++ b/v2v/convert_linux.ml
|
|
|
ffd6ed |
@@ -1269,9 +1269,9 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
|
|
|
ffd6ed |
fun i disk ->
|
|
|
ffd6ed |
let block_prefix_before_conversion =
|
|
|
ffd6ed |
match disk.s_controller with
|
|
|
ffd6ed |
- | Some `IDE -> ide_block_prefix
|
|
|
ffd6ed |
- | Some `SCSI -> "sd"
|
|
|
ffd6ed |
- | Some `Virtio_blk -> "vd"
|
|
|
ffd6ed |
+ | Some Source_IDE -> ide_block_prefix
|
|
|
ffd6ed |
+ | Some Source_SCSI -> "sd"
|
|
|
ffd6ed |
+ | Some Source_virtio_blk -> "vd"
|
|
|
ffd6ed |
| None ->
|
|
|
ffd6ed |
(* This is basically a guess. It assumes the source used IDE. *)
|
|
|
ffd6ed |
ide_block_prefix in
|
|
|
ffd6ed |
diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
|
|
|
ffd6ed |
index 8393786..98b321c 100644
|
|
|
ffd6ed |
--- a/v2v/input_disk.ml
|
|
|
ffd6ed |
+++ b/v2v/input_disk.ml
|
|
|
ffd6ed |
@@ -86,7 +86,7 @@ class input_disk verbose input_format disk = object
|
|
|
ffd6ed |
s_vcpu = 1; (* 1 vCPU is a safe default *)
|
|
|
ffd6ed |
s_features = [ "acpi"; "apic"; "pae" ];
|
|
|
ffd6ed |
s_display =
|
|
|
ffd6ed |
- Some { s_display_type = `Window; s_keymap = None; s_password = None };
|
|
|
ffd6ed |
+ Some { s_display_type = Window; s_keymap = None; s_password = None };
|
|
|
ffd6ed |
s_disks = [disk];
|
|
|
ffd6ed |
s_removables = [];
|
|
|
ffd6ed |
s_nics = [network];
|
|
|
ffd6ed |
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
|
|
|
ffd6ed |
index d1146f9..8057a00 100644
|
|
|
ffd6ed |
--- a/v2v/input_libvirtxml.ml
|
|
|
ffd6ed |
+++ b/v2v/input_libvirtxml.ml
|
|
|
ffd6ed |
@@ -96,10 +96,10 @@ let parse_libvirt_xml ~verbose xml =
|
|
|
ffd6ed |
match xpath_to_string "@type" "" with
|
|
|
ffd6ed |
| "" -> None
|
|
|
ffd6ed |
| "vnc" ->
|
|
|
ffd6ed |
- Some { s_display_type = `VNC;
|
|
|
ffd6ed |
+ Some { s_display_type = VNC;
|
|
|
ffd6ed |
s_keymap = keymap; s_password = password }
|
|
|
ffd6ed |
| "spice" ->
|
|
|
ffd6ed |
- Some { s_display_type = `Spice;
|
|
|
ffd6ed |
+ Some { s_display_type = Spice;
|
|
|
ffd6ed |
s_keymap = keymap; s_password = password }
|
|
|
ffd6ed |
| "sdl"|"desktop" as t ->
|
|
|
ffd6ed |
warning ~prog (f_"virt-v2v does not support local displays, so <graphics type='%s'> in the input libvirt XML was ignored") t;
|
|
|
ffd6ed |
@@ -138,9 +138,9 @@ let parse_libvirt_xml ~verbose xml =
|
|
|
ffd6ed |
let target_bus = xpath_to_string "target/@bus" "" in
|
|
|
ffd6ed |
match target_bus with
|
|
|
ffd6ed |
| "" -> None
|
|
|
ffd6ed |
- | "ide" -> Some `IDE
|
|
|
ffd6ed |
- | "scsi" -> Some `SCSI
|
|
|
ffd6ed |
- | "virtio" -> Some `Virtio_blk
|
|
|
ffd6ed |
+ | "ide" -> Some Source_IDE
|
|
|
ffd6ed |
+ | "scsi" -> Some Source_SCSI
|
|
|
ffd6ed |
+ | "virtio" -> Some Source_virtio_blk
|
|
|
ffd6ed |
| _ -> None in
|
|
|
ffd6ed |
|
|
|
ffd6ed |
let format =
|
|
|
ffd6ed |
@@ -202,15 +202,15 @@ let parse_libvirt_xml ~verbose xml =
|
|
|
ffd6ed |
let target_bus = xpath_to_string "target/@bus" "" in
|
|
|
ffd6ed |
match target_bus with
|
|
|
ffd6ed |
| "" -> None
|
|
|
ffd6ed |
- | "ide" -> Some `IDE
|
|
|
ffd6ed |
- | "scsi" -> Some `SCSI
|
|
|
ffd6ed |
- | "virtio" -> Some `Virtio_blk
|
|
|
ffd6ed |
+ | "ide" -> Some Source_IDE
|
|
|
ffd6ed |
+ | "scsi" -> Some Source_SCSI
|
|
|
ffd6ed |
+ | "virtio" -> Some Source_virtio_blk
|
|
|
ffd6ed |
| _ -> None in
|
|
|
ffd6ed |
|
|
|
ffd6ed |
let typ =
|
|
|
ffd6ed |
match xpath_to_string "@device" "" with
|
|
|
ffd6ed |
- | "cdrom" -> `CDROM
|
|
|
ffd6ed |
- | "floppy" -> `Floppy
|
|
|
ffd6ed |
+ | "cdrom" -> CDROM
|
|
|
ffd6ed |
+ | "floppy" -> Floppy
|
|
|
ffd6ed |
| _ -> assert false (* libxml2 error? *) in
|
|
|
ffd6ed |
|
|
|
ffd6ed |
let disk =
|
|
|
ffd6ed |
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
|
|
|
ffd6ed |
index e2a1243..211db43 100644
|
|
|
ffd6ed |
--- a/v2v/input_ova.ml
|
|
|
ffd6ed |
+++ b/v2v/input_ova.ml
|
|
|
ffd6ed |
@@ -167,8 +167,8 @@ object
|
|
|
ffd6ed |
|
|
|
ffd6ed |
(* 6: iscsi controller, 5: ide *)
|
|
|
ffd6ed |
match controller with
|
|
|
ffd6ed |
- | 6 -> Some `SCSI
|
|
|
ffd6ed |
- | 5 -> Some `IDE
|
|
|
ffd6ed |
+ | 6 -> Some Source_SCSI
|
|
|
ffd6ed |
+ | 5 -> Some Source_IDE
|
|
|
ffd6ed |
| 0 ->
|
|
|
ffd6ed |
warning ~prog (f_"ova disk has no parent controller, please report this as a bug supplying the *.ovf file extracted from the ova");
|
|
|
ffd6ed |
None
|
|
|
ffd6ed |
@@ -272,8 +272,8 @@ object
|
|
|
ffd6ed |
|
|
|
ffd6ed |
let typ =
|
|
|
ffd6ed |
match id with
|
|
|
ffd6ed |
- | 14 -> `Floppy
|
|
|
ffd6ed |
- | 15 | 16 -> `CDROM
|
|
|
ffd6ed |
+ | 14 -> Floppy
|
|
|
ffd6ed |
+ | 15 | 16 -> CDROM
|
|
|
ffd6ed |
| _ -> assert false in
|
|
|
ffd6ed |
let disk = {
|
|
|
ffd6ed |
s_removable_type = typ;
|
|
|
ffd6ed |
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
|
|
|
ffd6ed |
index 7f9a3a0..f4e480a 100644
|
|
|
ffd6ed |
--- a/v2v/output_libvirt.ml
|
|
|
ffd6ed |
+++ b/v2v/output_libvirt.ml
|
|
|
ffd6ed |
@@ -164,7 +164,7 @@ let create_libvirt_xml ?pool source targets guestcaps target_features =
|
|
|
ffd6ed |
|
|
|
ffd6ed |
List.map (
|
|
|
ffd6ed |
function
|
|
|
ffd6ed |
- | { s_removable_type = `CDROM } ->
|
|
|
ffd6ed |
+ | { s_removable_type = CDROM } ->
|
|
|
ffd6ed |
let i = !cdrom_index in
|
|
|
ffd6ed |
incr cdrom_index;
|
|
|
ffd6ed |
let name = cdrom_block_prefix ^ drive_name i in
|
|
|
ffd6ed |
@@ -173,7 +173,7 @@ let create_libvirt_xml ?pool source targets guestcaps target_features =
|
|
|
ffd6ed |
e "target" [ "dev", name; "bus", cdrom_bus ] []
|
|
|
ffd6ed |
]
|
|
|
ffd6ed |
|
|
|
ffd6ed |
- | { s_removable_type = `Floppy } ->
|
|
|
ffd6ed |
+ | { s_removable_type = Floppy } ->
|
|
|
ffd6ed |
let i = !fd_index in
|
|
|
ffd6ed |
incr fd_index;
|
|
|
ffd6ed |
let name = "fd" ^ drive_name i in
|
|
|
ffd6ed |
diff --git a/v2v/output_qemu.ml b/v2v/output_qemu.ml
|
|
|
ffd6ed |
index 9c17121..4b1d69a 100644
|
|
|
ffd6ed |
--- a/v2v/output_qemu.ml
|
|
|
ffd6ed |
+++ b/v2v/output_qemu.ml
|
|
|
ffd6ed |
@@ -90,11 +90,11 @@ object
|
|
|
ffd6ed |
| None -> ()
|
|
|
ffd6ed |
| Some display ->
|
|
|
ffd6ed |
(match display.s_display_type with
|
|
|
ffd6ed |
- | `Window ->
|
|
|
ffd6ed |
+ | Window ->
|
|
|
ffd6ed |
fpf "%s-display gtk" nl
|
|
|
ffd6ed |
- | `VNC ->
|
|
|
ffd6ed |
+ | VNC ->
|
|
|
ffd6ed |
fpf "%s-display vnc=:0" nl
|
|
|
ffd6ed |
- | `Spice ->
|
|
|
ffd6ed |
+ | Spice ->
|
|
|
ffd6ed |
fpf "%s-spice port=5900,addr=127.0.0.1" nl
|
|
|
ffd6ed |
);
|
|
|
ffd6ed |
fpf "%s-vga %s" nl
|
|
|
ffd6ed |
diff --git a/v2v/types.ml b/v2v/types.ml
|
|
|
ffd6ed |
index 28d62fc..97120c2 100644
|
|
|
ffd6ed |
--- a/v2v/types.ml
|
|
|
ffd6ed |
+++ b/v2v/types.ml
|
|
|
ffd6ed |
@@ -38,11 +38,12 @@ and source_disk = {
|
|
|
ffd6ed |
s_format : string option;
|
|
|
ffd6ed |
s_controller : s_controller option;
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
-and s_controller = [`IDE | `SCSI | `Virtio_blk]
|
|
|
ffd6ed |
+and s_controller = Source_IDE | Source_SCSI | Source_virtio_blk
|
|
|
ffd6ed |
and source_removable = {
|
|
|
ffd6ed |
- s_removable_type : [`CDROM|`Floppy];
|
|
|
ffd6ed |
+ s_removable_type : s_removable_type;
|
|
|
ffd6ed |
s_removable_controller : s_controller option;
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
+and s_removable_type = CDROM | Floppy
|
|
|
ffd6ed |
and source_nic = {
|
|
|
ffd6ed |
s_mac : string option;
|
|
|
ffd6ed |
s_vnet : string;
|
|
|
ffd6ed |
@@ -51,10 +52,11 @@ and source_nic = {
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
and vnet_type = Bridge | Network
|
|
|
ffd6ed |
and source_display = {
|
|
|
ffd6ed |
- s_display_type : [`Window|`VNC|`Spice];
|
|
|
ffd6ed |
+ s_display_type : s_display_type;
|
|
|
ffd6ed |
s_keymap : string option;
|
|
|
ffd6ed |
s_password : string option;
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
+and s_display_type = Window | VNC | Spice
|
|
|
ffd6ed |
|
|
|
ffd6ed |
let rec string_of_source s =
|
|
|
ffd6ed |
sprintf " source name: %s
|
|
|
ffd6ed |
@@ -94,14 +96,14 @@ and string_of_source_disk { s_qemu_uri = qemu_uri; s_format = format;
|
|
|
ffd6ed |
| Some controller -> " [" ^ string_of_controller controller ^ "]")
|
|
|
ffd6ed |
|
|
|
ffd6ed |
and string_of_controller = function
|
|
|
ffd6ed |
- | `IDE -> "ide"
|
|
|
ffd6ed |
- | `SCSI -> "scsi"
|
|
|
ffd6ed |
- | `Virtio_blk -> "virtio"
|
|
|
ffd6ed |
+ | Source_IDE -> "ide"
|
|
|
ffd6ed |
+ | Source_SCSI -> "scsi"
|
|
|
ffd6ed |
+ | Source_virtio_blk -> "virtio"
|
|
|
ffd6ed |
|
|
|
ffd6ed |
and string_of_source_removable { s_removable_type = typ;
|
|
|
ffd6ed |
s_removable_controller = controller } =
|
|
|
ffd6ed |
sprintf "\t%s%s"
|
|
|
ffd6ed |
- (match typ with `CDROM -> "CD-ROM" | `Floppy -> "Floppy")
|
|
|
ffd6ed |
+ (match typ with CDROM -> "CD-ROM" | Floppy -> "Floppy")
|
|
|
ffd6ed |
(match controller with
|
|
|
ffd6ed |
| None -> ""
|
|
|
ffd6ed |
| Some controller -> " [" ^ string_of_controller controller ^ "]")
|
|
|
ffd6ed |
@@ -117,7 +119,7 @@ and string_of_source_nic { s_mac = mac; s_vnet = vnet; s_vnet_type = typ } =
|
|
|
ffd6ed |
and string_of_source_display { s_display_type = typ;
|
|
|
ffd6ed |
s_keymap = keymap; s_password = password } =
|
|
|
ffd6ed |
sprintf "%s%s%s"
|
|
|
ffd6ed |
- (match typ with `Window -> "window" | `VNC -> "vnc" | `Spice -> "spice")
|
|
|
ffd6ed |
+ (match typ with Window -> "window" | VNC -> "vnc" | Spice -> "spice")
|
|
|
ffd6ed |
(match keymap with None -> "" | Some km -> " " ^ km)
|
|
|
ffd6ed |
(match password with None -> "" | Some _ -> " with password")
|
|
|
ffd6ed |
|
|
|
ffd6ed |
diff --git a/v2v/types.mli b/v2v/types.mli
|
|
|
ffd6ed |
index 07eec98..3d65596 100644
|
|
|
ffd6ed |
--- a/v2v/types.mli
|
|
|
ffd6ed |
+++ b/v2v/types.mli
|
|
|
ffd6ed |
@@ -42,19 +42,21 @@ and source_disk = {
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
(** A source disk. *)
|
|
|
ffd6ed |
|
|
|
ffd6ed |
-and s_controller = [`IDE | `SCSI | `Virtio_blk]
|
|
|
ffd6ed |
+and s_controller = Source_IDE | Source_SCSI | Source_virtio_blk
|
|
|
ffd6ed |
(** Source disk controller.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
For the purposes of this field, we can treat virtio-scsi as
|
|
|
ffd6ed |
- [`SCSI]. However we don't support conversions from virtio in any
|
|
|
ffd6ed |
+ [SCSI]. However we don't support conversions from virtio in any
|
|
|
ffd6ed |
case so virtio is here only to make it work for testing. *)
|
|
|
ffd6ed |
|
|
|
ffd6ed |
and source_removable = {
|
|
|
ffd6ed |
- s_removable_type : [`CDROM|`Floppy]; (** Type. *)
|
|
|
ffd6ed |
+ s_removable_type : s_removable_type; (** Type. *)
|
|
|
ffd6ed |
s_removable_controller : s_controller option; (** Controller, eg. IDE, SCSI.*)
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
(** Removable media. *)
|
|
|
ffd6ed |
|
|
|
ffd6ed |
+and s_removable_type = CDROM | Floppy
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
and source_nic = {
|
|
|
ffd6ed |
s_mac : string option; (** MAC address. *)
|
|
|
ffd6ed |
s_vnet : string; (** Source network name. *)
|
|
|
ffd6ed |
@@ -65,11 +67,12 @@ and source_nic = {
|
|
|
ffd6ed |
and vnet_type = Bridge | Network
|
|
|
ffd6ed |
|
|
|
ffd6ed |
and source_display = {
|
|
|
ffd6ed |
- s_display_type : [`Window|`VNC|`Spice]; (** Display type. *)
|
|
|
ffd6ed |
- s_keymap : string option; (** Guest keymap. *)
|
|
|
ffd6ed |
+ s_display_type : s_display_type; (** Display type. *)
|
|
|
ffd6ed |
+ s_keymap : string option; (** Guest keymap. *)
|
|
|
ffd6ed |
s_password : string option; (** If required, password to access
|
|
|
ffd6ed |
the display. *)
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
+and s_display_type = Window | VNC | Spice
|
|
|
ffd6ed |
|
|
|
ffd6ed |
val string_of_source : source -> string
|
|
|
ffd6ed |
val string_of_source_disk : source_disk -> string
|
|
|
ffd6ed |
--
|
|
|
ffd6ed |
1.8.3.1
|
|
|
ffd6ed |
|