Revision 4a44d8aa

b/lib/hypervisor/hv_kvm.py
90 90

  
91 91
# below constants show the format of runtime file
92 92
# the nics are in second possition, while the disks in 4th (last)
93
# moreover disk entries are stored in tupples of L{objects.Disk}, dev_path
93
# moreover disk entries are stored as a list of in tuples
94
# (L{objects.Disk}, link_name)
94 95
_KVM_NICS_RUNTIME_INDEX = 1
95 96
_KVM_DISKS_RUNTIME_INDEX = 3
96 97
_DEVICE_RUNTIME_INDEX = {
......
198 199
  """
199 200
  loaded_runtime = serializer.Load(serialized_runtime)
200 201
  if len(loaded_runtime) == 3:
201
    serialized_blockdevs = []
202
    serialized_disks = []
202 203
    kvm_cmd, serialized_nics, hvparams = loaded_runtime
203 204
  else:
204
    kvm_cmd, serialized_nics, hvparams, serialized_blockdevs = loaded_runtime
205
    kvm_cmd, serialized_nics, hvparams, serialized_disks = loaded_runtime
205 206

  
206 207
  kvm_nics = [objects.NIC.FromDict(snic) for snic in serialized_nics]
207
  block_devices = [(objects.Disk.FromDict(sdisk), link)
208
                   for sdisk, link in serialized_blockdevs]
208
  kvm_disks = [(objects.Disk.FromDict(sdisk), link)
209
               for sdisk, link in serialized_disks]
209 210

  
210
  return (kvm_cmd, kvm_nics, hvparams, block_devices)
211
  return (kvm_cmd, kvm_nics, hvparams, kvm_disks)
211 212

  
212 213

  
213 214
def _GetTunFeatures(fd, _ioctl=fcntl.ioctl):
......
1184 1185
        data.append(info)
1185 1186
    return data
1186 1187

  
1187
  def _GenerateKVMBlockDevicesOptions(self, instance, block_devices,
1188
  def _GenerateKVMBlockDevicesOptions(self, instance, kvm_disks,
1188 1189
                                      kvmhelp, devlist):
1189 1190
    """Generate KVM options regarding instance's block devices.
1190 1191

  
1191 1192
    @type instance: L{objects.Instance}
1192 1193
    @param instance: the instance object
1193
    @type block_devices: list of tuples
1194
    @param block_devices: list of tuples [(disk, link_name, uri)..]
1194
    @type kvm_disks: list of tuples
1195
    @param kvm_disks: list of tuples [(disk, link_name)..]
1195 1196
    @type kvmhelp: string
1196 1197
    @param kvmhelp: output of kvm --help
1197 1198
    @type devlist: string
......
1206 1207
      boot_disk = False
1207 1208
    else:
1208 1209
      boot_disk = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_DISK
1209
    kvm_path = hvp[constants.HV_KVM_PATH]
1210 1210

  
1211 1211
    # whether this is an older KVM version that uses the boot=on flag
1212 1212
    # on devices
......
1239 1239
      cache_val = ",cache=%s" % disk_cache
1240 1240
    else:
1241 1241
      cache_val = ""
1242
    for cfdev, dev_path in block_devices:
1242
    for cfdev, link_name in kvm_disks:
1243 1243
      if cfdev.mode != constants.DISK_RDWR:
1244 1244
        raise errors.HypervisorError("Instance has read-only disks which"
1245 1245
                                     " are not supported by KVM")
......
1254 1254
                  (dev_path, if_val, boot_val, cache_val)
1255 1255

  
1256 1256
      if device_driver:
1257
        # block_devices are the 4th entry of runtime file that did not exist in
1257
        # kvm_disks are the 4th entry of runtime file that did not exist in
1258 1258
        # the past. That means that cfdev should always have pci slot and
1259 1259
        # _GenerateDeviceKVMId() will not raise a exception.
1260 1260
        kvm_devid = _GenerateDeviceKVMId(constants.HOTPLUG_TARGET_DISK, cfdev)
......
1644 1644
    """Save an instance's KVM runtime
1645 1645

  
1646 1646
    """
1647
    kvm_cmd, kvm_nics, hvparams, block_devices = kvm_runtime
1647
    kvm_cmd, kvm_nics, hvparams, kvm_disks = kvm_runtime
1648 1648

  
1649 1649
    serialized_nics = [nic.ToDict() for nic in kvm_nics]
1650
    serialized_blockdevs = [(blk.ToDict(), link)
1651
                            for blk, link in block_devices]
1650
    serialized_disks = [(blk.ToDict(), link)
1651
                            for blk, link in kvm_disks]
1652 1652
    serialized_form = serializer.Dump((kvm_cmd, serialized_nics, hvparams,
1653
                                      serialized_blockdevs))
1653
                                      serialized_disks))
1654 1654

  
1655 1655
    self._WriteKVMRuntime(instance.name, serialized_form)
1656 1656

  
......
1686 1686
    if not self._InstancePidAlive(name)[2]:
1687 1687
      raise errors.HypervisorError("Failed to start instance %s" % name)
1688 1688

  
1689
  # 52/50 local variables
1689
  # too many local variables
1690 1690
  # pylint: disable=R0914
1691 1691
  def _ExecuteKVMRuntime(self, instance, kvm_runtime, kvmhelp, incoming=None):
1692 1692
    """Execute a KVM cmd, after completing it with some last minute data.
......
1711 1711

  
1712 1712
    temp_files = []
1713 1713

  
1714
    kvm_cmd, kvm_nics, up_hvp, block_devices = kvm_runtime
1714
    kvm_cmd, kvm_nics, up_hvp, kvm_disks = kvm_runtime
1715 1715
    # the first element of kvm_cmd is always the path to the kvm binary
1716 1716
    kvm_path = kvm_cmd[0]
1717 1717
    up_hvp = objects.FillDict(conf_hvp, up_hvp)
......
1826 1826
      self._ConfigureNIC(instance, nic_seq, nic, taps[nic_seq])
1827 1827

  
1828 1828
    bdev_opts = self._GenerateKVMBlockDevicesOptions(instance,
1829
                                                     block_devices,
1829
                                                     kvm_disks,
1830 1830
                                                     kvmhelp,
1831 1831
                                                     devlist)
1832 1832
    kvm_cmd.extend(bdev_opts)

Also available in: Unified diff