Revision 0288e7bf

b/lib/hypervisor/hv_kvm.py
1175 1175
      try:
1176 1176
        devlist = self._GetKVMOutput(kvm_path, self._KVMOPT_DEVICELIST)
1177 1177
        if self._VIRTIO_BLK_RE.search(devlist):
1178
          # TODO: uncomment when -device is used
1179
          # if_val = ",if=none"
1178
          if_val = ",if=none"
1180 1179
          # will be passed in -device option as driver
1181 1180
          device_driver = self._VIRTIO_BLK_PCI
1182 1181
      except errors.HypervisorError, _:
......
1211 1210
                  (dev_path, if_val, boot_val, cache_val)
1212 1211

  
1213 1212
      if device_driver:
1214
        pass
1213
        # block_devices are the 4th entry of runtime file that did not exist in
1214
        # the past. That means that cfdev should always have pci slot and
1215
        # _GenerateDeviceKVMId() will not raise a exception.
1216
        kvm_devid = _GenerateDeviceKVMId(constants.HOTPLUG_TARGET_DISK, cfdev)
1217
        drive_val += (",id=%s" % kvm_devid)
1218
        drive_val += (",bus=0,unit=%d" % cfdev.pci)
1219
        dev_val = ("%s,drive=%s,id=%s" %
1220
                   (device_driver, kvm_devid, kvm_devid))
1221
        dev_val += ",bus=pci.0,addr=%s" % hex(cfdev.pci)
1222
        dev_opts.extend(["-device", dev_val])
1223

  
1215 1224
      dev_opts.extend(["-drive", drive_val])
1216 1225

  
1217 1226
    return dev_opts
......
1552 1561
    if hvp[constants.HV_KVM_EXTRA]:
1553 1562
      kvm_cmd.extend(hvp[constants.HV_KVM_EXTRA].split(" "))
1554 1563

  
1564
    pci_reservations = bitarray(self._DEFAULT_PCI_RESERVATIONS)
1555 1565
    kvm_disks = []
1556
    for disk, dev_path in block_devices:
1557
      kvm_disks.append((disk, dev_path))
1566
    for disk, link_name in block_devices:
1567
      _UpdatePCISlots(disk, pci_reservations)
1568
      kvm_disks.append((disk, link_name))
1558 1569

  
1559 1570
    kvm_nics = []
1560 1571
    for nic in instance.nics:
1572
      _UpdatePCISlots(nic, pci_reservations)
1561 1573
      kvm_nics.append(nic)
1562 1574

  
1563 1575
    hvparams = hvp
......
1716 1728
        tapfds.append(tapfd)
1717 1729
        taps.append(tapname)
1718 1730
        if kvm_supports_netdev:
1719
          nic_val = "%s,mac=%s,netdev=netdev%s" % (nic_model, nic.mac, nic_seq)
1720
          tap_val = "type=tap,id=netdev%s,fd=%d%s" % (nic_seq, tapfd, tap_extra)
1731
          nic_val = "%s,mac=%s" % (nic_model, nic.mac)
1732
          try:
1733
            # kvm_nics already exist in old runtime files and thus there might
1734
            # be some entries without pci slot (therefore try: except:)
1735
            kvm_devid = _GenerateDeviceKVMId(constants.HOTPLUG_TARGET_NIC, nic)
1736
            netdev = kvm_devid
1737
            nic_val += (",id=%s,bus=pci.0,addr=%s" % (kvm_devid, hex(nic.pci)))
1738
          except errors.HotplugError:
1739
            netdev = "netdev%d" % nic_seq
1740
          nic_val += (",netdev=%s" % netdev)
1741
          tap_val = ("type=tap,id=%s,fd=%d%s" %
1742
                     (netdev, tapfd, tap_extra))
1721 1743
          kvm_cmd.extend(["-netdev", tap_val, "-device", nic_val])
1722 1744
        else:
1723 1745
          nic_val = "nic,vlan=%s,macaddr=%s,model=%s" % (nic_seq,

Also available in: Unified diff