mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0158-v2v-efi-Model-firmware-in-source-metadata.patch

ffd6ed
From 3a6b509b9468c8698917c13aa3d6dd35c77299f0 Mon Sep 17 00:00:00 2001
ffd6ed
From: "Richard W.M. Jones" <rjones@redhat.com>
ffd6ed
Date: Thu, 30 Apr 2015 13:44:35 +0100
ffd6ed
Subject: [PATCH] v2v: efi: Model firmware in source metadata.
ffd6ed
ffd6ed
Also modify the input_* drivers so they pull out the firmware from the
ffd6ed
metadata.  Currently this is only possible for `-i ova', since libvirt
ffd6ed
does not expose it (RHBZ#1217444).
ffd6ed
ffd6ed
(cherry picked from commit ef77725081331b0a1b84ca32f6cb38a91873989f)
ffd6ed
---
ffd6ed
 v2v/input_disk.ml                     |  1 +
ffd6ed
 v2v/input_libvirtxml.ml               |  1 +
ffd6ed
 v2v/input_ova.ml                      | 12 ++++++++++++
ffd6ed
 v2v/test-v2v-i-ova-formats.expected   |  1 +
ffd6ed
 v2v/test-v2v-i-ova-formats.ovf        |  2 +-
ffd6ed
 v2v/test-v2v-i-ova-gz.expected        |  1 +
ffd6ed
 v2v/test-v2v-i-ova-two-disks.expected |  1 +
ffd6ed
 v2v/test-v2v-print-source.sh          |  1 +
ffd6ed
 v2v/types.ml                          | 12 ++++++++++++
ffd6ed
 v2v/types.mli                         | 10 ++++++++++
ffd6ed
 10 files changed, 41 insertions(+), 1 deletion(-)
ffd6ed
ffd6ed
diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
ffd6ed
index c308907..453268a 100644
ffd6ed
--- a/v2v/input_disk.ml
ffd6ed
+++ b/v2v/input_disk.ml
ffd6ed
@@ -85,6 +85,7 @@ class input_disk verbose input_format disk = object
ffd6ed
       s_memory = 2048L *^ 1024L *^ 1024L; (* 2048 MB *)
ffd6ed
       s_vcpu = 1;                         (* 1 vCPU is a safe default *)
ffd6ed
       s_features = [ "acpi"; "apic"; "pae" ];
ffd6ed
+      s_firmware = UnknownFirmware;       (* causes virt-v2v to autodetect *)
ffd6ed
       s_display =
ffd6ed
         Some { s_display_type = Window; s_keymap = None; s_password = None;
ffd6ed
                s_listen = LNone; s_port = None };
ffd6ed
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
ffd6ed
index 9834313..0f21bb3 100644
ffd6ed
--- a/v2v/input_libvirtxml.ml
ffd6ed
+++ b/v2v/input_libvirtxml.ml
ffd6ed
@@ -348,6 +348,7 @@ let parse_libvirt_xml ?conn ~verbose xml =
ffd6ed
     s_memory = memory;
ffd6ed
     s_vcpu = vcpu;
ffd6ed
     s_features = features;
ffd6ed
+    s_firmware = UnknownFirmware; (* XXX until RHBZ#1217444 is fixed *)
ffd6ed
     s_display = display;
ffd6ed
     s_sound = sound;
ffd6ed
     s_disks = [];
ffd6ed
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
ffd6ed
index 84ac57e..8deedda 100644
ffd6ed
--- a/v2v/input_ova.ml
ffd6ed
+++ b/v2v/input_ova.ml
ffd6ed
@@ -176,6 +176,8 @@ object
ffd6ed
     Xml.xpath_register_ns xpathctx
ffd6ed
       "rasd" "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData";
ffd6ed
     Xml.xpath_register_ns xpathctx
ffd6ed
+      "vmw" "http://www.vmware.com/schema/ovf";
ffd6ed
+    Xml.xpath_register_ns xpathctx
ffd6ed
       "vssd" "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData";
ffd6ed
 
ffd6ed
     let xpath_to_string expr default =
ffd6ed
@@ -211,6 +213,15 @@ object
ffd6ed
     (* Search for number of vCPUs. *)
ffd6ed
     let vcpu = xpath_to_int "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:ResourceType/text()=3]/rasd:VirtualQuantity/text()" 1 in
ffd6ed
 
ffd6ed
+    (* BIOS or EFI firmware? *)
ffd6ed
+    let firmware = xpath_to_string "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/vmw:Config[@vmw:key=\"firmware\"]/@vmw:value" "bios" in
ffd6ed
+    let firmware =
ffd6ed
+      match firmware with
ffd6ed
+      | "bios" -> BIOS
ffd6ed
+      | "efi" -> UEFI
ffd6ed
+      | s ->
ffd6ed
+         error (f_"unknown Config:firmware value %s (expected \"bios\" or \"efi\")") s in
ffd6ed
+
ffd6ed
     (* Helper function to return the parent controller of a disk. *)
ffd6ed
     let parent_controller id =
ffd6ed
       let expr = sprintf "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:InstanceID/text()=%d]/rasd:ResourceType/text()" id in
ffd6ed
@@ -358,6 +369,7 @@ object
ffd6ed
       s_memory = memory;
ffd6ed
       s_vcpu = vcpu;
ffd6ed
       s_features = []; (* XXX *)
ffd6ed
+      s_firmware = firmware;
ffd6ed
       s_display = None; (* XXX *)
ffd6ed
       s_sound = None;
ffd6ed
       s_disks = disks;
ffd6ed
diff --git a/v2v/test-v2v-i-ova-formats.expected b/v2v/test-v2v-i-ova-formats.expected
ffd6ed
index 68a761e..22e6136 100644
ffd6ed
--- a/v2v/test-v2v-i-ova-formats.expected
ffd6ed
+++ b/v2v/test-v2v-i-ova-formats.expected
ffd6ed
@@ -5,6 +5,7 @@ hypervisor type: vmware
ffd6ed
          memory: 1073741824 (bytes)
ffd6ed
        nr vCPUs: 1
ffd6ed
    CPU features: 
ffd6ed
+       firmware: uefi
ffd6ed
         display: 
ffd6ed
           sound: 
ffd6ed
 disks:
ffd6ed
diff --git a/v2v/test-v2v-i-ova-formats.ovf b/v2v/test-v2v-i-ova-formats.ovf
ffd6ed
index 3c685f4..4827c7e 100644
ffd6ed
--- a/v2v/test-v2v-i-ova-formats.ovf
ffd6ed
+++ b/v2v/test-v2v-i-ova-formats.ovf
ffd6ed
@@ -118,7 +118,7 @@
ffd6ed
       </Item>
ffd6ed
       <vmw:Config ovf:required="false" vmw:key="cpuHotAddEnabled" vmw:value="false"/>
ffd6ed
       <vmw:Config ovf:required="false" vmw:key="cpuHotRemoveEnabled" vmw:value="false"/>
ffd6ed
-      <vmw:Config ovf:required="false" vmw:key="firmware" vmw:value="bios"/>
ffd6ed
+      <vmw:Config ovf:required="false" vmw:key="firmware" vmw:value="efi"/>
ffd6ed
       <vmw:Config ovf:required="false" vmw:key="virtualICH7MPresent" vmw:value="false"/>
ffd6ed
       <vmw:Config ovf:required="false" vmw:key="virtualSMCPresent" vmw:value="false"/>
ffd6ed
       <vmw:Config ovf:required="false" vmw:key="memoryHotAddEnabled" vmw:value="false"/>
ffd6ed
diff --git a/v2v/test-v2v-i-ova-gz.expected b/v2v/test-v2v-i-ova-gz.expected
ffd6ed
index 4eeb74d..e6ef699 100644
ffd6ed
--- a/v2v/test-v2v-i-ova-gz.expected
ffd6ed
+++ b/v2v/test-v2v-i-ova-gz.expected
ffd6ed
@@ -5,6 +5,7 @@ hypervisor type: vmware
ffd6ed
          memory: 1073741824 (bytes)
ffd6ed
        nr vCPUs: 1
ffd6ed
    CPU features: 
ffd6ed
+       firmware: bios
ffd6ed
         display: 
ffd6ed
           sound: 
ffd6ed
 disks:
ffd6ed
diff --git a/v2v/test-v2v-i-ova-two-disks.expected b/v2v/test-v2v-i-ova-two-disks.expected
ffd6ed
index f54f370..c45f266 100644
ffd6ed
--- a/v2v/test-v2v-i-ova-two-disks.expected
ffd6ed
+++ b/v2v/test-v2v-i-ova-two-disks.expected
ffd6ed
@@ -5,6 +5,7 @@ hypervisor type: vmware
ffd6ed
          memory: 1073741824 (bytes)
ffd6ed
        nr vCPUs: 1
ffd6ed
    CPU features: 
ffd6ed
+       firmware: bios
ffd6ed
         display: 
ffd6ed
           sound: 
ffd6ed
 disks:
ffd6ed
diff --git a/v2v/test-v2v-print-source.sh b/v2v/test-v2v-print-source.sh
ffd6ed
index 5abd391..e7a8382 100755
ffd6ed
--- a/v2v/test-v2v-print-source.sh
ffd6ed
+++ b/v2v/test-v2v-print-source.sh
ffd6ed
@@ -58,6 +58,7 @@ hypervisor type: test
ffd6ed
          memory: 1073741824 (bytes)
ffd6ed
        nr vCPUs: 1
ffd6ed
    CPU features: 
ffd6ed
+       firmware: unknown
ffd6ed
         display: 
ffd6ed
           sound: 
ffd6ed
 disks:
ffd6ed
diff --git a/v2v/types.ml b/v2v/types.ml
ffd6ed
index 00ff526..d173c91 100644
ffd6ed
--- a/v2v/types.ml
ffd6ed
+++ b/v2v/types.ml
ffd6ed
@@ -27,12 +27,17 @@ type source = {
ffd6ed
   s_memory : int64;
ffd6ed
   s_vcpu : int;
ffd6ed
   s_features : string list;
ffd6ed
+  s_firmware : source_firmware;
ffd6ed
   s_display : source_display option;
ffd6ed
   s_sound : source_sound option;
ffd6ed
   s_disks : source_disk list;
ffd6ed
   s_removables : source_removable list;
ffd6ed
   s_nics : source_nic list;
ffd6ed
 }
ffd6ed
+and source_firmware =
ffd6ed
+  | BIOS
ffd6ed
+  | UEFI
ffd6ed
+  | UnknownFirmware
ffd6ed
 and source_disk = {
ffd6ed
   s_disk_id : int;
ffd6ed
   s_qemu_uri : string;
ffd6ed
@@ -77,6 +82,7 @@ hypervisor type: %s
ffd6ed
          memory: %Ld (bytes)
ffd6ed
        nr vCPUs: %d
ffd6ed
    CPU features: %s
ffd6ed
+       firmware: %s
ffd6ed
         display: %s
ffd6ed
           sound: %s
ffd6ed
 disks:
ffd6ed
@@ -91,6 +97,7 @@ NICs:
ffd6ed
     s.s_memory
ffd6ed
     s.s_vcpu
ffd6ed
     (String.concat "," s.s_features)
ffd6ed
+    (string_of_source_firmware s.s_firmware)
ffd6ed
     (match s.s_display with
ffd6ed
     | None -> ""
ffd6ed
     | Some display -> string_of_source_display display)
ffd6ed
@@ -101,6 +108,11 @@ NICs:
ffd6ed
     (String.concat "\n" (List.map string_of_source_removable s.s_removables))
ffd6ed
     (String.concat "\n" (List.map string_of_source_nic s.s_nics))
ffd6ed
 
ffd6ed
+and string_of_source_firmware = function
ffd6ed
+  | BIOS -> "bios"
ffd6ed
+  | UEFI -> "uefi"
ffd6ed
+  | UnknownFirmware -> "unknown"
ffd6ed
+
ffd6ed
 and string_of_source_disk { s_qemu_uri = qemu_uri; s_format = format;
ffd6ed
                             s_controller = controller } =
ffd6ed
   sprintf "\t%s%s%s"
ffd6ed
diff --git a/v2v/types.mli b/v2v/types.mli
ffd6ed
index 1b3a9cf..ade1edb 100644
ffd6ed
--- a/v2v/types.mli
ffd6ed
+++ b/v2v/types.mli
ffd6ed
@@ -27,6 +27,7 @@ type source = {
ffd6ed
   s_memory : int64;                     (** Memory size (bytes). *)
ffd6ed
   s_vcpu : int;                         (** Number of CPUs. *)
ffd6ed
   s_features : string list;             (** Machine features. *)
ffd6ed
+  s_firmware : source_firmware;         (** Firmware (BIOS or EFI). *)
ffd6ed
   s_display : source_display option;    (** Guest display. *)
ffd6ed
   s_sound : source_sound option;        (** Sound card. *)
ffd6ed
   s_disks : source_disk list;           (** Disk images. *)
ffd6ed
@@ -35,6 +36,15 @@ type source = {
ffd6ed
 }
ffd6ed
 (** The source: metadata, disk images. *)
ffd6ed
 
ffd6ed
+and source_firmware =
ffd6ed
+  | BIOS                                (** PC BIOS or default firmware *)
ffd6ed
+  | UEFI                                (** UEFI *)
ffd6ed
+  | UnknownFirmware                     (** Unknown: try to autodetect. *)
ffd6ed
+(** The firmware from the source metadata.  Note that
ffd6ed
+    [UnknownFirmware] state corresponds to disks (where we have no
ffd6ed
+    metadata) and temporarily also to libvirt because of
ffd6ed
+    RHBZ#1217444. *)
ffd6ed
+
ffd6ed
 and source_disk = {
ffd6ed
   s_disk_id : int;                      (** A unique ID for each source disk. *)
ffd6ed
   s_qemu_uri : string;                  (** QEMU URI of source disk. *)
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed