commit 5f045eb857e5aa617689a5f9f4334a109234763b
Author: Apollon Oikonomopoulos <apoikos@gmail.com>
Date:   Fri Mar 28 18:07:53 2014 +0200

    (2.10) KVM: use running HVPs to calc blockdev options
    
    Commit 0fe22ad2 moved the call to _GenerateKVMBlockDevicesOptions() from
    _GenerateKVMRuntime() to _ExecuteKvmRuntime. However, while in
    _GenerateKVMRuntime() there is only one set of HVPs, those of the
    instance's configuration, in _ExecuteKVMRuntime there are two sets of
    HVPs:
    
      - The instance's configured HVPs
      - The HVPs the instance used when it was started
    
    Currently, _GenerateKVMBlockDevicesOptions() uses the first set of HVPs
    only, meaning that it will always read the configured HVPs. Since
    _ExecuteKVMRuntime() is also called at migration time, it should use the
    instance's running HVPs, otherwise migration while fail.
    
    The following scenario will lead to a crash on migration:
    
     1. Start the instance (assuming 'paravirtual' disk_type)
     2. gnt-instance modify -H disk_type=scsi <instance_name>
     3. gnt-instance migrate <instance_name>
    
    Step 3 will start the instance on the remote node with all disks
    configured as 'scsi' and qemu will crash post-migration.
    
    We fix this by making sure _GenerateKVMBlockDevicesOptions gets the
    running HVPs as well.
    
    Signed-off-by: Apollon Oikonomopoulos <apoikos@gmail.com>
    Signed-off-by: Thomas Thrainer <thomasth@google.com>
    Reviewed-by: Thomas Thrainer <thomasth@google.com>
    Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>

diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index c1bf74f..de15a89 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -1307,12 +1307,14 @@ class KVMHypervisor(hv_base.BaseHypervisor):
         data.append(info)
     return data
 
-  def _GenerateKVMBlockDevicesOptions(self, instance, kvm_disks,
+  def _GenerateKVMBlockDevicesOptions(self, instance, up_hvp, kvm_disks,
                                       kvmhelp, devlist):
     """Generate KVM options regarding instance's block devices.
 
     @type instance: L{objects.Instance}
     @param instance: the instance object
+    @type up_hvp: dict
+    @param up_hvp: the instance's runtime hypervisor parameters
     @type kvm_disks: list of tuples
     @param kvm_disks: list of tuples [(disk, link_name)..]
     @type kvmhelp: string
@@ -1323,12 +1325,11 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     @return: list of command line options eventually used by kvm executable
 
     """
-    hvp = instance.hvparams
-    kernel_path = hvp[constants.HV_KERNEL_PATH]
+    kernel_path = up_hvp[constants.HV_KERNEL_PATH]
     if kernel_path:
       boot_disk = False
     else:
-      boot_disk = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_DISK
+      boot_disk = up_hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_DISK
 
     # whether this is an older KVM version that uses the boot=on flag
     # on devices
@@ -1336,7 +1337,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
 
     dev_opts = []
     device_driver = None
-    disk_type = hvp[constants.HV_DISK_TYPE]
+    disk_type = up_hvp[constants.HV_DISK_TYPE]
     if disk_type == constants.HT_DISK_PARAVIRTUAL:
       if_val = ",if=%s" % self._VIRTIO
       try:
@@ -1349,7 +1350,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     else:
       if_val = ",if=%s" % disk_type
     # Cache mode
-    disk_cache = hvp[constants.HV_DISK_CACHE]
+    disk_cache = up_hvp[constants.HV_DISK_CACHE]
     if instance.disk_template in constants.DTS_EXT_MIRROR:
       if disk_cache != "none":
         # TODO: make this a hard error, instead of a silent overwrite
@@ -1903,6 +1904,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     devlist = self._GetKVMOutput(kvm_path, self._KVMOPT_DEVICELIST)
 
     bdev_opts = self._GenerateKVMBlockDevicesOptions(instance,
+                                                     up_hvp,
                                                      kvm_disks,
                                                      kvmhelp,
                                                      devlist)
