From 069cfbf14b42ca123e663142b79db80080ea38cf Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 7 Jan 2009 17:01:25 +0000
Subject: [PATCH] Simplify hypervisor block_devices structure

This is a partial forward-port of commit 1136 on the 1.2 branch:

  The hypervisor doesn't need to be passed the whole block device
  structure, so we'll just give it the block device name on the local
  node, and the name as seen by the instance. This will make it easier to
  manipulate it later without messing with the block devices (eg. by
  changing the system name to a symlink to the name itself).

  Since the HVM hypervisor changes the "virtual" name a note is added
  calling for a redesign that doesn't need this change, as different
  hypervisors and emulation types will anyway have different names for
  exported devices.

  Reviewed-by: iustinp

The changes in this patch compared to the original are:
  - we keep passing the original disk object, not for its iv_name, but
    for it's physical_id which is needed by the file driver (this could
    be fixed maybe)
  - we don't use the iv_name anymore, since in 2.0 we already use the
    index of the device

Original-Author: ultrotter
---
 lib/backend.py           | 6 +++---
 lib/hypervisor/hv_kvm.py | 4 ++--
 lib/hypervisor/hv_xen.py | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index 55aae5ddb..ed72b29b9 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -741,8 +741,8 @@ def _GatherBlockDevs(instance):
 
   @type instance: L{objects.Instance}
   @param instance: the instance whose disks we shoul assemble
-  @rtype: list of L{bdev.BlockDev}
-  @return: list of the block devices
+  @rtype: list
+  @return: list of (disk_object, device_path)
 
   """
   block_devices = []
@@ -752,7 +752,7 @@ def _GatherBlockDevs(instance):
       raise errors.BlockDeviceError("Block device '%s' is not set up." %
                                     str(disk))
     device.Open()
-    block_devices.append((disk, device))
+    block_devices.append((disk, device.dev_path))
   return block_devices
 
 
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index f3f5b4eca..c40b5e3f9 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -203,7 +203,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
         nic_seq += 1
 
     boot_drive = True
-    for cfdev, rldev in block_devices:
+    for cfdev, dev_path in block_devices:
       # TODO: handle FD_LOOP and FD_BLKTAP (?)
       if boot_drive:
         boot_val = ',boot=on'
@@ -214,7 +214,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       # TODO: handle different if= types
       if_val = ',if=virtio'
 
-      drive_val = 'file=%s,format=raw%s%s' % (rldev.dev_path, if_val, boot_val)
+      drive_val = 'file=%s,format=raw%s%s' % (dev_path, if_val, boot_val)
       kvm_cmd.extend(['-drive', drive_val])
 
     kvm_cmd.extend(['-kernel', instance.hvparams[constants.HV_KERNEL_PATH]])
diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index c4aebf382..a0a59ad34 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -256,12 +256,12 @@ class XenHypervisor(hv_base.BaseHypervisor):
     # FIXME: instead of this hardcoding here, each of PVM/HVM should
     # directly export their info (currently HVM will just sed this info)
     namespace = ["sd" + chr(i + ord('a')) for i in range(24)]
-    for sd_name, (cfdev, rldev) in zip(namespace, block_devices):
+    for sd_name, (cfdev, dev_path) in zip(namespace, block_devices):
       if cfdev.dev_type == constants.LD_FILE:
         line = "'%s:%s,%s,w'" % (FILE_DRIVER_MAP[cfdev.physical_id[0]],
-                                 rldev.dev_path, sd_name)
+                                 dev_path, sd_name)
       else:
-        line = "'phy:%s,%s,w'" % (rldev.dev_path, sd_name)
+        line = "'phy:%s,%s,w'" % (dev_path, sd_name)
       disk_data.append(line)
 
     return disk_data
-- 
GitLab