(2.10) Some fixes in _GenerateKVMBlockDevicesOptions()
authorDimitris Aragiorgis <dimara@grnet.gr>
Thu, 10 Oct 2013 13:00:44 +0000 (16:00 +0300)
committerDimitris Aragiorgis <dimara@grnet.gr>
Thu, 27 Mar 2014 07:56:59 +0000 (09:56 +0200)
* Add docstring.
* fix missed usecase of boot_disk=False if kernel_path is given.
* Use devlist arg in GenerateKVMBlockDeviceOptions()
  This is previously calculated in _ExecuteKVMRuntime()
  so there is no need to rerun the same command.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/hypervisor/hv_kvm.py

index e2f4599..1564309 100644 (file)
@@ -1184,10 +1184,28 @@ class KVMHypervisor(hv_base.BaseHypervisor):
         data.append(info)
     return data
 
-  def _GenerateKVMBlockDevicesOptions(self, instance, block_devices, kvmhelp):
+  def _GenerateKVMBlockDevicesOptions(self, instance, block_devices,
+                                      kvmhelp, devlist):
+    """Generate KVM options regarding instance's block devices.
 
+    @type instance: L{objects.Instance}
+    @param instance: the instance object
+    @type block_devices: list of tuples
+    @param block_devices: list of tuples [(disk, link_name, uri)..]
+    @type kvmhelp: string
+    @param kvmhelp: output of kvm --help
+    @type devlist: string
+    @param devlist: output of kvm -device ?
+    @rtype: list
+    @return: list of command line options eventually used by kvm executable
+
+    """
     hvp = instance.hvparams
-    boot_disk = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_DISK
+    kernel_path = hvp[constants.HV_KERNEL_PATH]
+    if kernel_path:
+      boot_disk = False
+    else:
+      boot_disk = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_DISK
     kvm_path = hvp[constants.HV_KVM_PATH]
 
     # whether this is an older KVM version that uses the boot=on flag
@@ -1200,7 +1218,6 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     if disk_type == constants.HT_DISK_PARAVIRTUAL:
       if_val = ",if=%s" % self._VIRTIO
       try:
-        devlist = self._GetKVMOutput(kvm_path, self._KVMOPT_DEVICELIST)
         if self._VIRTIO_BLK_RE.search(devlist):
           if_val = ",if=none"
           # will be passed in -device option as driver
@@ -1720,6 +1737,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     # related parameters we'll use up_hvp
     tapfds = []
     taps = []
+    devlist = self._GetKVMOutput(kvm_path, self._KVMOPT_DEVICELIST)
     if not kvm_nics:
       kvm_cmd.extend(["-net", "none"])
     else:
@@ -1729,7 +1747,6 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       if nic_type == constants.HT_NIC_PARAVIRTUAL:
         nic_model = self._VIRTIO
         try:
-          devlist = self._GetKVMOutput(kvm_path, self._KVMOPT_DEVICELIST)
           if self._VIRTIO_NET_RE.search(devlist):
             nic_model = self._VIRTIO_NET_PCI
             vnet_hdr = up_hvp[constants.HV_VNET_HDR]
@@ -1810,7 +1827,8 @@ class KVMHypervisor(hv_base.BaseHypervisor):
 
     bdev_opts = self._GenerateKVMBlockDevicesOptions(instance,
                                                      block_devices,
-                                                     kvmhelp)
+                                                     kvmhelp,
+                                                     devlist)
     kvm_cmd.extend(bdev_opts)
     # CPU affinity requires kvm to start paused, so we set this flag if the
     # instance is not already paused and if we are not going to accept a