Revision 0f4117c9 lib/hypervisor/hv_kvm.py

b/lib/hypervisor/hv_kvm.py
1152 1152
      try:
1153 1153
        devlist = self._GetKVMOutput(kvm_path, self._KVMOPT_DEVICELIST)
1154 1154
        if self._VIRTIO_BLK_RE.search(devlist):
1155
          # TODO: uncomment when -device is used
1156
          # if_val = ",if=none"
1155
          if_val = ",if=none"
1157 1156
          # will be passed in -device option as driver
1158 1157
          device_driver = self._VIRTIO_BLK_PCI
1159 1158
      except errors.HypervisorError, _:
......
1188 1187
                  (dev_path, if_val, boot_val, cache_val)
1189 1188

  
1190 1189
      if device_driver:
1191
        pass
1190
        # block_devices are the 4th entry of runtime file that did not exist in
1191
        # the past. That means that cfdev should always have pci slot and
1192
        # _GenerateDeviceKVMId() will not raise a exception.
1193
        kvm_devid = _GenerateDeviceKVMId(constants.HOTPLUG_TARGET_DISK, cfdev)
1194
        drive_val += (",id=%s" % kvm_devid)
1195
        drive_val += (",bus=0,unit=%d" % cfdev.pci)
1196
        dev_val = ("%s,drive=%s,id=%s" %
1197
                   (device_driver, kvm_devid, kvm_devid))
1198
        dev_val += ",bus=pci.0,addr=%s" % hex(cfdev.pci)
1199
        dev_opts.extend(["-device", dev_val])
1200

  
1192 1201
      dev_opts.extend(["-drive", drive_val])
1193 1202

  
1194 1203
    return dev_opts
......
1529 1538
    if hvp[constants.HV_KVM_EXTRA]:
1530 1539
      kvm_cmd.extend(hvp[constants.HV_KVM_EXTRA].split(" "))
1531 1540

  
1541
    pci_reservations = bitarray(self._DEFAULT_PCI_RESERVATIONS)
1532 1542
    kvm_disks = []
1533 1543
    for disk, dev_path in block_devices:
1544
      _UpdatePCISlots(disk, pci_reservations)
1534 1545
      kvm_disks.append((disk, dev_path))
1535 1546

  
1536 1547
    kvm_nics = []
1537 1548
    for nic in instance.nics:
1549
      _UpdatePCISlots(nic, pci_reservations)
1538 1550
      kvm_nics.append(nic)
1539 1551

  
1540 1552
    hvparams = hvp
......
1703 1715
        tapfds.append(tapfd)
1704 1716
        taps.append(tapname)
1705 1717
        if kvm_supports_netdev:
1706
          nic_val = "%s,mac=%s,netdev=netdev%s" % (nic_model, nic.mac, nic_seq)
1707
          tap_val = "type=tap,id=netdev%s,fd=%d%s" % (nic_seq, tapfd, tap_extra)
1718
          nic_val = "%s,mac=%s" % (nic_model, nic.mac)
1719
          try:
1720
            # kvm_nics already exist in old runtime files and thus there might
1721
            # be some entries without pci slot (therefore try: except:)
1722
            kvm_devid = _GenerateDeviceKVMId(constants.HOTPLUG_TARGET_NIC, nic)
1723
            netdev = kvm_devid
1724
            nic_val += (",id=%s,bus=pci.0,addr=%s" % (kvm_devid, hex(nic.pci)))
1725
          except errors.HotplugError:
1726
            netdev = "netdev%d" % nic_seq
1727
          nic_val += (",netdev=%s" % netdev)
1728
          tap_val = ("type=tap,id=%s,fd=%d%s" %
1729
                     (netdev, tapfd, tap_extra))
1708 1730
          kvm_cmd.extend(["-netdev", tap_val, "-device", nic_val])
1709 1731
        else:
1710 1732
          nic_val = "nic,vlan=%s,macaddr=%s,model=%s" % (nic_seq,

Also available in: Unified diff