[Pkg-libvirt-commits] [libguestfs] 15/66: v2v: Remove source.s_arch field and find architecture through inspection.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:47:37 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.54-1
in repository libguestfs.

commit f61832b17aba2b9bf52899cf79b1a602f65a2968
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Sat Sep 20 08:53:38 2014 +0100

    v2v: Remove source.s_arch field and find architecture through inspection.
    
    Previously we required that the source hypervisor knew the
    architecture of the guest, and passed that through to KVM.
    
    However this was error-prone for several reasons:
    
     - OVF (-i ova) doesn't define the architecture
    
     - Disk images (-i disk) don't have an associated architecture
    
     - Libvirt XML sometimes lacks the <type arch=...> field, especially
       for RHEL 5-era libvirt.
    
     - It might not be set correctly for the guest.
    
    We know the real architecture from inspection of the guest, so use
    that instead.
---
 v2v/convert_linux.ml             | 1 +
 v2v/convert_windows.ml           | 1 +
 v2v/input_disk.ml                | 1 -
 v2v/input_libvirtxml.ml          | 4 ----
 v2v/input_ova.ml                 | 1 -
 v2v/output_glance.ml             | 2 +-
 v2v/output_libvirt.ml            | 2 +-
 v2v/test-v2v-print-source.sh     | 1 -
 v2v/test-v2v-real-conversions.sh | 2 +-
 v2v/types.ml                     | 4 +---
 v2v/types.mli                    | 4 ++--
 v2v/utils.ml                     | 9 +++++++++
 v2v/virt-v2v.pod                 | 2 +-
 13 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index e0ba28c..fb254b1 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -1362,6 +1362,7 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
     gcaps_block_bus = if virtio then Virtio_blk else IDE;
     gcaps_net_bus = if virtio then Virtio_net else E1000;
     gcaps_video = video;
+    gcaps_arch = Utils.kvm_arch inspect.i_arch;
     gcaps_acpi = acpi;
   } in
 
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index 9399770..901cdb5 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -473,6 +473,7 @@ echo uninstalling Xen PV driver
      * guests.  Unclear if this is correct.  XXX
      *)
     gcaps_video = QXL;
+    gcaps_arch = Utils.kvm_arch inspect.i_arch;
     gcaps_acpi = true;
   } in
 
diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
index 65fffa2..d79b23e 100644
--- a/v2v/input_disk.ml
+++ b/v2v/input_disk.ml
@@ -83,7 +83,6 @@ class input_disk verbose input_format disk = object
       s_name = name; s_orig_name = name;
       s_memory = 2048L *^ 1024L *^ 1024L; (* 2048 MB *)
       s_vcpu = 1;                         (* 1 vCPU is a safe default *)
-      s_arch = Config.host_cpu;
       s_features = [ "acpi"; "apic"; "pae" ];
       s_display = None;
       s_disks = [disk];
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
index 1745ec4..e67a494 100644
--- a/v2v/input_libvirtxml.ml
+++ b/v2v/input_libvirtxml.ml
@@ -62,14 +62,11 @@ let parse_libvirt_xml ~verbose
   let memory = xpath_to_int "/domain/memory/text()" (1024 * 1024) in
   let memory = Int64.of_int memory *^ 1024L in
   let vcpu = xpath_to_int "/domain/vcpu/text()" 1 in
-  let arch = xpath_to_string "/domain/os/type/@arch" "" in
 
   if dom_type = "" then
     error (f_"in the libvirt XML metadata, <domain type='...'> is missing or empty");
   if name = "" then
     error (f_"in the libvirt XML metadata, <name> is missing or empty");
-  if arch = "" then
-    error (f_"in the libvirt XML metadata, <os><type arch='...'> is missing or empty");
 
   let features =
     let features = ref [] in
@@ -249,7 +246,6 @@ let parse_libvirt_xml ~verbose
     s_name = name; s_orig_name = name;
     s_memory = memory;
     s_vcpu = vcpu;
-    s_arch = arch;
     s_features = features;
     s_display = display;
     s_disks = disks;
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index 2737718..f7089b6 100644
--- a/v2v/input_ova.ml
+++ b/v2v/input_ova.ml
@@ -206,7 +206,6 @@ object
       s_orig_name = name;
       s_memory = memory;
       s_vcpu = cpu;
-      s_arch = "x86_64"; (* XXX: no architucture in ovf, this entry will be overritten at os inspection via libguestfs *)
       s_features = []; (* FIXME: *)
       s_display = None; (* FIXME: *)
       s_disks = !disks;
diff --git a/v2v/output_glance.ml b/v2v/output_glance.ml
index 936f1d5..c2b1a32 100644
--- a/v2v/output_glance.ml
+++ b/v2v/output_glance.ml
@@ -83,7 +83,7 @@ object
       | Virtio_net -> "virtio"
       | E1000 -> "e1000"
       | RTL8139 -> "rtl8139");
-      "architecture", source.s_arch;
+      "architecture", guestcaps.gcaps_arch;
       "hypervisor_type", "kvm";
       "vm_mode", "hvm";
       "os_type", inspect.i_type;
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index 927beba..59a390f 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -186,7 +186,7 @@ let create_libvirt_xml ?pool source targets guestcaps =
       e "currentMemory" ["unit", "KiB"] [PCData (Int64.to_string memory_k)];
       e "vcpu" [] [PCData (string_of_int source.s_vcpu)];
       e "os" [] [
-        e "type" ["arch", source.s_arch] [PCData "hvm"];
+        e "type" ["arch", guestcaps.gcaps_arch] [PCData "hvm"];
       ];
       e "features" [] (List.map (fun s -> e s [] []) features);
 
diff --git a/v2v/test-v2v-print-source.sh b/v2v/test-v2v-print-source.sh
index a3baca7..82b2550 100755
--- a/v2v/test-v2v-print-source.sh
+++ b/v2v/test-v2v-print-source.sh
@@ -57,7 +57,6 @@ if [ "$(cat $d/output)" != "    source name: windows
 hypervisor type: test
          memory: 1073741824 (bytes)
        nr vCPUs: 1
-           arch: i686
    CPU features: 
         display: 
 disks:
diff --git a/v2v/test-v2v-real-conversions.sh b/v2v/test-v2v-real-conversions.sh
index e4e4a67..bb98488 100755
--- a/v2v/test-v2v-real-conversions.sh
+++ b/v2v/test-v2v-real-conversions.sh
@@ -45,7 +45,7 @@ for file in *.img; do
   <name>$n</name>
   <memory>1048576</memory>
   <os>
-    <type arch='$(uname -m)'>hvm</type>
+    <type>hvm</type>
     <boot dev='hd'/>
   </os>
   <devices>
diff --git a/v2v/types.ml b/v2v/types.ml
index 166733d..95b56f0 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -26,7 +26,6 @@ type source = {
   s_orig_name : string;
   s_memory : int64;
   s_vcpu : int;
-  s_arch : string;
   s_features : string list;
   s_display : source_display option;
   s_disks : source_disk list;
@@ -60,7 +59,6 @@ let rec string_of_source s =
 hypervisor type: %s
          memory: %Ld (bytes)
        nr vCPUs: %d
-           arch: %s
    CPU features: %s
         display: %s
 disks:
@@ -74,7 +72,6 @@ NICs:
     s.s_dom_type
     s.s_memory
     s.s_vcpu
-    s.s_arch
     (String.concat "," s.s_features)
     (match s.s_display with
     | None -> ""
@@ -184,6 +181,7 @@ type guestcaps = {
   gcaps_block_bus : guestcaps_block_type;
   gcaps_net_bus : guestcaps_net_type;
   gcaps_video : guestcaps_video_type;
+  gcaps_arch : string;
   gcaps_acpi : bool;
 }
 and guestcaps_block_type = Virtio_blk | IDE
diff --git a/v2v/types.mli b/v2v/types.mli
index 90c8274..d947bf8 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -26,7 +26,6 @@ type source = {
                                             still saved here). *)
   s_memory : int64;                     (** Memory size (bytes). *)
   s_vcpu : int;                         (** Number of CPUs. *)
-  s_arch : string;                      (** Architecture. *)
   s_features : string list;             (** Machine features. *)
   s_display : source_display option;    (** Guest display. *)
   s_disks : source_disk list;           (** Disk images. *)
@@ -129,7 +128,8 @@ type guestcaps = {
       installing drivers).  Thus this is not known until after
       conversion. *)
 
-  gcaps_acpi : bool;           (** True if guest supports acpi. *)
+  gcaps_arch : string;      (** Architecture that KVM must emulate. *)
+  gcaps_acpi : bool;        (** True if guest supports acpi. *)
 }
 (** Guest capabilities after conversion.  eg. Was virtio found or installed? *)
 
diff --git a/v2v/utils.ml b/v2v/utils.ml
index dd46835..7757be5 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -63,6 +63,15 @@ let uri_quote str =
 
 external drive_name : int -> string = "v2v_utils_drive_name"
 
+(* Map guest architecture found by inspection to the architecture
+ * that KVM must emulate.  Note for x86 we assume a 64 bit hypervisor.
+ *)
+let kvm_arch = function
+  | "i386" | "i486" | "i586" | "i686"
+  | "x86_64" -> "x86_64"
+  | "unknown" -> "x86_64" (* most likely *)
+  | arch -> arch
+
 let compare_app2_versions app1 app2 =
   let i = compare app1.Guestfs.app2_epoch app2.Guestfs.app2_epoch in
   if i <> 0 then i
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index 827648b..3e7ce9e 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -822,7 +822,7 @@ that instead.
    <memory>1048576</memory>
    <vcpu>2</vcpu>
    <os>
-     <type arch='x86_64'>hvm</type>
+     <type>hvm</type>
      <boot dev='hd'/>
    </os>
    <features>

-- 
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