Revision f0db563d lib/hypervisor/hv_kvm.py

b/lib/hypervisor/hv_kvm.py
543 543
    constants.HV_KVM_MACHINE_VERSION: hv_base.NO_CHECK,
544 544
    }
545 545

  
546
  _VIRTIO = "virtio"
547
  _VIRTIO_NET_PCI = "virtio-net-pci"
548

  
546 549
  _MIGRATION_STATUS_RE = re.compile("Migration\s+status:\s+(\w+)",
547 550
                                    re.M | re.I)
548 551
  _MIGRATION_PROGRESS_RE = \
......
569 572
  _ENABLE_KVM_RE = re.compile(r"^-enable-kvm\s", re.M)
570 573
  _DISABLE_KVM_RE = re.compile(r"^-disable-kvm\s", re.M)
571 574
  _NETDEV_RE = re.compile(r"^-netdev\s", re.M)
575
  _NEW_VIRTIO_RE = re.compile(r"^name \"%s\"" % _VIRTIO_NET_PCI, re.M)
572 576
  # match  -drive.*boot=on|off on different lines, but in between accept only
573 577
  # dashes not preceeded by a new line (which would mean another option
574 578
  # different than -drive is starting)
......
584 588
  # Supported kvm options to get output from
585 589
  _KVMOPT_HELP = "help"
586 590
  _KVMOPT_MLIST = "mlist"
591
  _KVMOPT_DEVICELIST = "devicelist"
587 592
  _KVMOPTS_CMDS = {
588 593
    _KVMOPT_HELP: ["--help"],
589 594
    _KVMOPT_MLIST: ["-M", "?"],
595
    _KVMOPT_DEVICELIST: ["-device", "?"],
590 596
  }
591 597

  
592 598
  def __init__(self):
......
1466 1472
    temp_files = []
1467 1473

  
1468 1474
    kvm_cmd, kvm_nics, up_hvp = kvm_runtime
1475
    # the first element of kvm_cmd is always the path to the kvm binary
1476
    kvm_path = kvm_cmd[0]
1469 1477
    up_hvp = objects.FillDict(conf_hvp, up_hvp)
1470 1478

  
1471
    _, v_major, v_min, _ = self._ParseKVMVersion(kvmhelp)
1472

  
1473 1479
    # We know it's safe to run as a different user upon migration, so we'll use
1474 1480
    # the latest conf, from conf_hvp.
1475 1481
    security_model = conf_hvp[constants.HV_SECURITY_MODEL]
......
1498 1504
      tap_extra = ""
1499 1505
      nic_type = up_hvp[constants.HV_NIC_TYPE]
1500 1506
      if nic_type == constants.HT_NIC_PARAVIRTUAL:
1501
        # From version 0.12.0, kvm uses a new sintax for network configuration.
1502
        if (v_major, v_min) >= (0, 12):
1503
          nic_model = "virtio-net-pci"
1504
          vnet_hdr = True
1505
        else:
1506
          nic_model = "virtio"
1507
        nic_model = self._VIRTIO
1508
        try:
1509
          devlist = self._GetKVMOutput(kvm_path, self._KVMOPT_DEVICELIST)
1510
          if self._NEW_VIRTIO_RE.search(devlist):
1511
            nic_model = self._VIRTIO_NET_PCI
1512
            vnet_hdr = True
1513
        except errors.HypervisorError, _:
1514
          # Older versions of kvm don't support DEVICE_LIST, but they don't
1515
          # have new virtio syntax either.
1516
          pass
1507 1517

  
1508 1518
        if up_hvp[constants.HV_VHOST_NET]:
1509 1519
          # check for vhost_net support

Also available in: Unified diff