|
|
e76f14 |
From 6d2cf9eebf4bddbf868aae7e80a2a0f3b22c4545 Mon Sep 17 00:00:00 2001
|
|
|
e76f14 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
e76f14 |
Date: Sun, 24 Apr 2016 11:36:20 +0100
|
|
|
e76f14 |
Subject: [PATCH] v2v: target_bus_assignment: Various refactorings.
|
|
|
e76f14 |
|
|
|
e76f14 |
No functional change.
|
|
|
e76f14 |
|
|
|
e76f14 |
(cherry picked from commit c1adbe61dfd23ba28e286e0ecaf97bba6de9cdcd)
|
|
|
e76f14 |
---
|
|
|
e76f14 |
v2v/target_bus_assignment.ml | 28 +++++++++++++++++-----------
|
|
|
e76f14 |
1 file changed, 17 insertions(+), 11 deletions(-)
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/v2v/target_bus_assignment.ml b/v2v/target_bus_assignment.ml
|
|
|
e76f14 |
index eb3ed58..0546004 100644
|
|
|
e76f14 |
--- a/v2v/target_bus_assignment.ml
|
|
|
e76f14 |
+++ b/v2v/target_bus_assignment.ml
|
|
|
e76f14 |
@@ -34,13 +34,16 @@ let rec target_bus_assignment source targets guestcaps =
|
|
|
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 |
*)
|
|
|
e76f14 |
- iteri (
|
|
|
e76f14 |
- fun i t ->
|
|
|
e76f14 |
- let t = BusSlotTarget t in
|
|
|
e76f14 |
+ let () =
|
|
|
e76f14 |
+ let bus =
|
|
|
e76f14 |
match guestcaps.gcaps_block_bus with
|
|
|
e76f14 |
- | Virtio_blk -> insert virtio_blk_bus i t
|
|
|
e76f14 |
- | IDE -> insert ide_bus i t
|
|
|
e76f14 |
- ) targets;
|
|
|
e76f14 |
+ | Virtio_blk -> virtio_blk_bus
|
|
|
e76f14 |
+ | IDE -> ide_bus in
|
|
|
e76f14 |
+ iteri (
|
|
|
e76f14 |
+ fun i t ->
|
|
|
e76f14 |
+ let t = BusSlotTarget t in
|
|
|
e76f14 |
+ insert bus i t
|
|
|
e76f14 |
+ ) targets in
|
|
|
e76f14 |
|
|
|
e76f14 |
(* Now try to add the removable disks to the bus at the same slot
|
|
|
e76f14 |
* they originally occupied, but if the slot is occupied, emit a
|
|
|
e76f14 |
@@ -48,15 +51,16 @@ let rec target_bus_assignment source targets guestcaps =
|
|
|
e76f14 |
*)
|
|
|
e76f14 |
List.iter (
|
|
|
e76f14 |
fun r ->
|
|
|
e76f14 |
+ let t = BusSlotRemovable r in
|
|
|
e76f14 |
let bus = 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_slot with
|
|
|
e76f14 |
- | None -> ignore (insert_after bus 0 (BusSlotRemovable r))
|
|
|
e76f14 |
+ | None -> ignore (insert_after bus 0 t)
|
|
|
e76f14 |
| Some desired_slot_nr ->
|
|
|
e76f14 |
- if not (insert_after bus desired_slot_nr (BusSlotRemovable r)) then
|
|
|
e76f14 |
+ if not (insert_after bus desired_slot_nr t) then
|
|
|
e76f14 |
warning (f_"removable %s device in slot %d clashes with another disk, so it has been moved to a higher numbered slot on the same bus. This may mean that this removable device has a different name inside the guest (for example a CD-ROM originally called /dev/hdc might move to /dev/hdd, or from D: to E: on a Windows guest).")
|
|
|
e76f14 |
(match r.s_removable_type with
|
|
|
e76f14 |
| CDROM -> s_"CD-ROM"
|
|
|
e76f14 |
@@ -77,16 +81,18 @@ and insert bus i slot =
|
|
|
e76f14 |
Array.blit oldbus 0 !bus 0 oldlen
|
|
|
e76f14 |
);
|
|
|
e76f14 |
assert (!bus.(i) = BusSlotEmpty);
|
|
|
e76f14 |
- Array.set !bus i slot
|
|
|
e76f14 |
+ !bus.(i) <- slot
|
|
|
e76f14 |
|
|
|
e76f14 |
(* Insert a slot into the bus, but if the desired slot is not empty, then
|
|
|
e76f14 |
* increment the slot number until we find an empty one. Returns
|
|
|
e76f14 |
* true if we got the desired slot.
|
|
|
e76f14 |
*)
|
|
|
e76f14 |
and insert_after bus i slot =
|
|
|
e76f14 |
- let len = Array.length !bus in
|
|
|
e76f14 |
- if i >= len || Array.get !bus i = BusSlotEmpty then (
|
|
|
e76f14 |
+ if slot_is_empty bus i then (
|
|
|
e76f14 |
insert bus i slot; true
|
|
|
e76f14 |
) else (
|
|
|
e76f14 |
ignore (insert_after bus (i+1) slot); false
|
|
|
e76f14 |
)
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+(* Return true if slot i is empty in the bus. *)
|
|
|
e76f14 |
+and slot_is_empty bus i = i >= Array.length !bus || !bus.(i) = BusSlotEmpty
|
|
|
e76f14 |
--
|
|
|
7af31e |
1.8.3.1
|
|
|
e76f14 |
|