Commit 4b784cf8 authored by Miguel Di Ciurcio Filho's avatar Miguel Di Ciurcio Filho Committed by Guido Trotter
Browse files

kvm: Improve network syntax and tests

The current syntax when defining a NIC uses a pair of arguments, like this:

-net tap,vlan=0 -net nic,vlan=0,model=virtio

When using this pair, internally KVM will create a VLANState structure to send
ethernet frames between the guest NIC and the host tap device. This is
suboptimal and is going to be removed in the future. Plus, this combination
breaks vhost-net support.

The new syntax does not need the vlan craziness anymore, creating a direct 1:1
relationship between the backend device and the frontend device.

-netdev tap,id=netdev0 -device virtio-net-pci,mac=52:54:00:56:6c:55,netdev=netdev0

The current code does not verify if vhost_net is available before starting an
instance. All this tests are done verifying the KVM version installed on the
Signed-off-by: default avatarMiguel Di Ciurcio Filho <>
Signed-off-by: default avatarGuido Trotter <>
Reviewed-by: default avatarGuido Trotter <>
parent 3f2eba25
...@@ -722,6 +722,12 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -722,6 +722,12 @@ class KVMHypervisor(hv_base.BaseHypervisor):
kvm_cmd, kvm_nics, up_hvp = kvm_runtime kvm_cmd, kvm_nics, up_hvp = kvm_runtime
up_hvp = objects.FillDict(conf_hvp, up_hvp) up_hvp = objects.FillDict(conf_hvp, up_hvp)
kvm_version = self._GetKVMVersion()
if kvm_version:
_, v_major, v_min, v_rev = kvm_version
raise errors.HypervisorError("Unable to get KVM version")
# We know it's safe to run as a different user upon migration, so we'll use # We know it's safe to run as a different user upon migration, so we'll use
# the latest conf, from conf_hvp. # the latest conf, from conf_hvp.
security_model = conf_hvp[constants.HV_SECURITY_MODEL] security_model = conf_hvp[constants.HV_SECURITY_MODEL]
...@@ -737,19 +743,33 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -737,19 +743,33 @@ class KVMHypervisor(hv_base.BaseHypervisor):
tap_extra = "" tap_extra = ""
nic_type = up_hvp[constants.HV_NIC_TYPE] nic_type = up_hvp[constants.HV_NIC_TYPE]
if nic_type == constants.HT_NIC_PARAVIRTUAL: if nic_type == constants.HT_NIC_PARAVIRTUAL:
nic_model = "model=virtio" # From version 0.12.0, kvm uses a new sintax for network configuration.
if (v_major, v_min) >= (0,12):
nic_model = "virtio-net-pci"
nic_model = "virtio"
if up_hvp[constants.HV_VHOST_NET]: if up_hvp[constants.HV_VHOST_NET]:
# vhost_net is only available from version 0.13.0 or newer
if (v_major, v_min) >= (0,13):
tap_extra = ",vhost=on" tap_extra = ",vhost=on"
else: else:
nic_model = "model=%s" % nic_type raise errors.HypervisorError("vhost_net is configured"
" but it is not available")
nic_model = nic_type
for nic_seq, nic in enumerate(kvm_nics): for nic_seq, nic in enumerate(kvm_nics):
nic_val = "nic,vlan=%s,macaddr=%s,%s" % (nic_seq, nic.mac, nic_model)
script = self._WriteNetScriptFile(instance, nic_seq, nic) script = self._WriteNetScriptFile(instance, nic_seq, nic)
tap_val = "tap,vlan=%s,script=%s%s" % (nic_seq, script, tap_extra)
kvm_cmd.extend(["-net", nic_val])
kvm_cmd.extend(["-net", tap_val])
temp_files.append(script) temp_files.append(script)
if (v_major, v_min) >= (0,12):
nic_val = "%s,mac=%s,netdev=netdev%s" % (nic_model, nic.mac, nic_seq)
tap_val = "type=tap,id=netdev%s,script=%s%s" % (nic_seq, script, tap_extra)
kvm_cmd.extend(["-netdev", tap_val, "-device", nic_val])
nic_val = "nic,vlan=%s,macaddr=%s,model=%s" % (nic_seq, nic.mac, nic_model)
tap_val = "tap,vlan=%s,script=%s" % (nic_seq, script)
kvm_cmd.extend(["-net", tap_val, "-net", nic_val])
if incoming: if incoming:
target, port = incoming target, port = incoming
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment