Blame SOURCES/0121-v2v-Fix-conversion-of-floppy-removable-devices-RHBZ-.patch

e76f14
From 8bd7c9c0d10699757e4edd6d3b5b9ae8667fb4a4 Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Wed, 22 Jun 2016 15:04:26 +0100
e76f14
Subject: [PATCH] v2v: Fix conversion of floppy removable devices
e76f14
 (RHBZ#1309706).
e76f14
e76f14
The previous code treated floppy disks and CD-ROMs as the same kind of
e76f14
thing, resulting in malformed libvirt XML.  You would see the
e76f14
following error when importing a guest into libvirt:
e76f14
e76f14
  error: Failed to define domain from /tmp/v2vlibvirt063486.xml
e76f14
  error: internal error: Invalid floppy device name: hdb
e76f14
e76f14
because we incorrectly generated this bogus libvirt XML fragment:
e76f14
e76f14
  <disk device='floppy' type='file'>
e76f14
    <driver name='qemu' type='raw'/>
e76f14
    <target dev='hdb' bus='ide'/>
e76f14
  </disk>
e76f14
e76f14
This commit models floppy devices as a distinct type, occupying their
e76f14
own bus ("/dev/fdX").  When writing to libvirt, we generate correct
e76f14
XML fragments, looking like this:
e76f14
e76f14
  <disk device='floppy' type='file'>
e76f14
    <driver name='qemu' type='raw'/>
e76f14
    <target dev='fda'/>
e76f14
  </disk>
e76f14
e76f14
Miscellaneous other changes were required in the code.  There is also
e76f14
a regression test (see following commit).
e76f14
e76f14
Note this ignores floppy disks in '-o qemu' mode.
e76f14
e76f14
(cherry picked from commit b9613acb94e3328204d96efab0dfc8b8ed1d3368)
e76f14
---
e76f14
 v2v/input_libvirtxml.ml      |  1 +
e76f14
 v2v/output_libvirt.ml        |  6 ++++--
e76f14
 v2v/output_qemu.ml           |  4 ++++
e76f14
 v2v/target_bus_assignment.ml | 20 ++++++++++++--------
e76f14
 v2v/test-v2v-i-ova.xml       |  2 +-
e76f14
 v2v/types.ml                 |  1 +
e76f14
 v2v/types.mli                | 10 +++++++---
e76f14
 7 files changed, 30 insertions(+), 14 deletions(-)
e76f14
e76f14
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
e76f14
index 1202302..a547edd 100644
e76f14
--- a/v2v/input_libvirtxml.ml
e76f14
+++ b/v2v/input_libvirtxml.ml
e76f14
@@ -297,6 +297,7 @@ let parse_libvirt_xml ?conn xml =
e76f14
         | Some s when String.is_prefix s "sd" -> get_drive_slot s 2
e76f14
         | Some s when String.is_prefix s "vd" -> get_drive_slot s 2
e76f14
         | Some s when String.is_prefix s "xvd" -> get_drive_slot s 3
e76f14
+        | Some s when String.is_prefix s "fd" -> get_drive_slot s 2
e76f14
         | Some s ->
e76f14
            warning (f_"<target dev='%s'> was ignored because the device name could not be recognized") s;
e76f14
            None in
e76f14
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
e76f14
index 05ad931..5a404ee 100644
e76f14
--- a/v2v/output_libvirt.ml
e76f14
+++ b/v2v/output_libvirt.ml
e76f14
@@ -173,7 +173,6 @@ let create_libvirt_xml ?pool source target_buses guestcaps
e76f14
           e "driver" [ "name", "qemu"; "type", "raw" ] [];
e76f14
           e "target" [
e76f14
             "dev", drive_prefix ^ drive_name i;
e76f14
-            "bus", bus_name
e76f14
           ] []
e76f14
         ]
e76f14
     in
e76f14
@@ -187,7 +186,10 @@ let create_libvirt_xml ?pool source target_buses guestcaps
e76f14
                     target_buses.target_ide_bus);
e76f14
       Array.to_list
e76f14
         (Array.mapi (make_disk "scsi" "sd")
e76f14
-                    target_buses.target_scsi_bus)
e76f14
+                    target_buses.target_scsi_bus);
e76f14
+      Array.to_list
e76f14
+        (Array.mapi (make_disk "floppy" "fd")
e76f14
+                    target_buses.target_floppy_bus)
e76f14
     ] in
e76f14
   append devices disks;
e76f14
 
e76f14
diff --git a/v2v/output_qemu.ml b/v2v/output_qemu.ml
e76f14
index d079ccd..94f80c2 100644
e76f14
--- a/v2v/output_qemu.ml
e76f14
+++ b/v2v/output_qemu.ml
e76f14
@@ -137,6 +137,10 @@ object
e76f14
     in
e76f14
     Array.iteri make_scsi target_buses.target_scsi_bus;
e76f14
 
e76f14
+    (* XXX Highly unlikely that anyone cares, but the current
e76f14
+     * code ignores target_buses.target_floppy_bus.
e76f14
+     *)
e76f14
+
e76f14
     let net_bus =
e76f14
       match guestcaps.gcaps_net_bus with
e76f14
       | Virtio_net -> "virtio-net-pci"
e76f14
diff --git a/v2v/target_bus_assignment.ml b/v2v/target_bus_assignment.ml
e76f14
index 5ad8582..bce3a88 100644
e76f14
--- a/v2v/target_bus_assignment.ml
e76f14
+++ b/v2v/target_bus_assignment.ml
e76f14
@@ -21,11 +21,11 @@ open Common_gettext.Gettext
e76f14
 
e76f14
 open Types
e76f14
 
e76f14
-(* XXX This doesn't do the right thing for PC legacy floppy devices. *)
e76f14
 let rec target_bus_assignment source targets guestcaps =
e76f14
   let virtio_blk_bus = ref [| |]
e76f14
   and ide_bus = ref [| |]
e76f14
-  and scsi_bus = ref [| |] in
e76f14
+  and scsi_bus = ref [| |]
e76f14
+  and floppy_bus = ref [| |] in
e76f14
 
e76f14
   (* Add the fixed disks (targets) to either the virtio-blk or IDE bus,
e76f14
    * depending on whether the guest has virtio drivers or not.
e76f14
@@ -65,11 +65,14 @@ let rec target_bus_assignment source targets guestcaps =
e76f14
       fun r ->
e76f14
         let t = BusSlotRemovable r in
e76f14
         let bus =
e76f14
-          match r.s_removable_controller with
e76f14
-          | None -> ide_bus (* Wild guess, but should be safe. *)
e76f14
-          | Some Source_virtio_blk -> virtio_blk_bus
e76f14
-          | Some Source_IDE -> ide_bus
e76f14
-          | Some Source_SCSI -> scsi_bus in
e76f14
+          match r.s_removable_type with
e76f14
+          | Floppy -> floppy_bus
e76f14
+          | CDROM ->
e76f14
+             match r.s_removable_controller with
e76f14
+             | None -> ide_bus (* Wild guess, but should be safe. *)
e76f14
+             | Some Source_virtio_blk -> virtio_blk_bus
e76f14
+             | Some Source_IDE -> ide_bus
e76f14
+             | Some Source_SCSI -> scsi_bus in
e76f14
 
e76f14
         match r.s_removable_slot with
e76f14
         | None ->
e76f14
@@ -88,7 +91,8 @@ let rec target_bus_assignment source targets guestcaps =
e76f14
 
e76f14
   { target_virtio_blk_bus = !virtio_blk_bus;
e76f14
     target_ide_bus = !ide_bus;
e76f14
-    target_scsi_bus = !scsi_bus }
e76f14
+    target_scsi_bus = !scsi_bus;
e76f14
+    target_floppy_bus = !floppy_bus }
e76f14
 
e76f14
 (* Insert a slot into the bus array, making the array bigger if necessary. *)
e76f14
 and insert bus i slot =
e76f14
diff --git a/v2v/test-v2v-i-ova.xml b/v2v/test-v2v-i-ova.xml
e76f14
index bb765e3..6dcfc31 100644
e76f14
--- a/v2v/test-v2v-i-ova.xml
e76f14
+++ b/v2v/test-v2v-i-ova.xml
e76f14
@@ -27,7 +27,7 @@
e76f14
     </disk>
e76f14
     <disk device='floppy' type='file'>
e76f14
       <driver name='qemu' type='raw'/>
e76f14
-      <target dev='hdb' bus='ide'/>
e76f14
+      <target dev='fda'/>
e76f14
     </disk>
e76f14
     <interface type='network'>
e76f14
       <source network='Ethernet 1'/>
e76f14
diff --git a/v2v/types.ml b/v2v/types.ml
e76f14
index d082594..7491be4 100644
e76f14
--- a/v2v/types.ml
e76f14
+++ b/v2v/types.ml
e76f14
@@ -363,6 +363,7 @@ type target_buses = {
e76f14
   target_virtio_blk_bus : target_bus_slot array;
e76f14
   target_ide_bus : target_bus_slot array;
e76f14
   target_scsi_bus : target_bus_slot array;
e76f14
+  target_floppy_bus : target_bus_slot array;
e76f14
 }
e76f14
 
e76f14
 and target_bus_slot =
e76f14
diff --git a/v2v/types.mli b/v2v/types.mli
e76f14
index 18ac138..c1cb245 100644
e76f14
--- a/v2v/types.mli
e76f14
+++ b/v2v/types.mli
e76f14
@@ -254,10 +254,11 @@ type target_buses = {
e76f14
   target_virtio_blk_bus : target_bus_slot array;
e76f14
   target_ide_bus : target_bus_slot array;
e76f14
   target_scsi_bus : target_bus_slot array;
e76f14
+  target_floppy_bus : target_bus_slot array;
e76f14
 }
e76f14
 (** Mapping of fixed and removable disks to buses.
e76f14
 
e76f14
-    As shown in the diagram below, there are (currently) three buses
e76f14
+    As shown in the diagram below, there are (currently) four buses
e76f14
     attached to the target VM.  Each contains a chain of fixed or
e76f14
     removable disks.  Slots can also be empty.
e76f14
 
e76f14
@@ -276,8 +277,11 @@ type target_buses = {
e76f14
    ├────┤ hda ├───┤ hdb ├───┤ hdc ├───┤ hdd │  IDE bus
e76f14
    │    └─────┘   └─────┘   └─────┘   └─────┘
e76f14
    │    ┌─────┐   ┌─────┐
e76f14
-   └────┤  -  ├───┤ vdb │  Virtio-blk bus
e76f14
-        └─────┘   └─────┘
e76f14
+   ├────┤  -  ├───┤ vdb │  Virtio-blk bus
e76f14
+   │    └─────┘   └─────┘
e76f14
+   │    ┌─────┐
e76f14
+   └────┤ fda │  Floppy disks
e76f14
+        └─────┘
e76f14
 v}
e76f14
  *)
e76f14
 
e76f14
-- 
e76f14
1.8.3.1
e76f14