[pve-devel] [PATCH 2/2] add virtio-vhost-user nic support
Alexandre Derumier
aderumier at odiso.com
Mon May 9 05:03:01 CEST 2016
vm config:
net0: virtio-vhost-user=66:32:37:61:66:64,bridge=vmbr0,tag=10
numa: 1
hugepages: 1
virtio-vhost-user is userland only, so no tap interface
Numa need to be enabled, and all vm memory is mapped to hugepages
The qemu netdev script/downscript don't work with vhost-user
System configuration:
Openvswitch need to have dpdk enabled
/etc/default/openvswitch-switch
--------------------------------
DPDK_OPTS='--dpdk --socket-mem=1024 -c 0x1 -n 4'
ovs switch need to have datapath_type=netdev
/etc/network/interfaces
-----------------------
auto vmbr0
iface vmbr10 inet manual
ovs_type OVSBridge
ovs_ports eth0
ovs_extra set bridge vmbr10 datapath_type=netdev
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/QemuServer.pm | 44 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 41 insertions(+), 3 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 08ad61f..e794fa0 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -570,7 +570,7 @@ for (my $i = 0; $i < $MAX_NUMA; $i++) {
my $nic_model_list = ['rtl8139', 'ne2k_pci', 'e1000', 'pcnet', 'virtio',
'ne2k_isa', 'i82551', 'i82557b', 'i82559er', 'vmxnet3',
- 'e1000-82540em', 'e1000-82544gc', 'e1000-82545em'];
+ 'e1000-82540em', 'e1000-82544gc', 'e1000-82545em', 'virtio-vhost-user'];
my $nic_model_list_txt = join(' ', sort @$nic_model_list);
my $net_fmt = {
@@ -1582,7 +1582,7 @@ sub print_netdevice_full {
my $bootorder = $conf->{boot} || $confdesc->{boot}->{default};
my $device = $net->{model};
- if ($net->{model} eq 'virtio') {
+ if ($net->{model} =~ m/^virtio/) {
$device = 'virtio-net-pci';
};
@@ -1639,7 +1639,13 @@ sub print_netdev_full {
my $script = $hotplug ? "pve-bridge-hotplug" : "pve-bridge";
if ($net->{bridge}) {
- $netdev = "type=tap,id=$netid,ifname=${ifname},script=/var/lib/qemu-server/$script,downscript=/var/lib/qemu-server/pve-bridgedown$vhostparam";
+
+ if ($net->{model} eq 'virtio-vhost-user') {
+ $netdev = "type=vhost-user,id=$netid,chardev=charvhostuser$i,vhostforce";
+ } else {
+ $netdev = "type=tap,id=$netid,ifname=${ifname},script=/var/lib/qemu-server/$script,downscript=/var/lib/qemu-server/pve-bridgedown$vhostparam";
+ }
+
} else {
$netdev = "type=user,id=$netid,hostname=$vmname";
}
@@ -3390,6 +3396,12 @@ sub config_to_command {
$bootindex_hash->{n} += 1;
}
+ if ($d->{model} eq 'virtio-vhost-user') {
+ die "Hugepages needs to be enabled to use vhost-user nics" if !$conf->{hugepages};
+ my $vhostuser = "vhost-user".$vmid."i".$i;
+ push @$devices, '-chardev', "socket,id=charvhostuser$i,path=/var/run/openvswitch/$vhostuser";
+ }
+
my $netdevfull = print_netdev_full($vmid,$conf,$d,"net$i");
push @$devices, '-netdev', $netdevfull;
@@ -4603,6 +4615,21 @@ sub vm_start {
}
}
+ #ovs vhost-user
+ for (my $i = 0; $i < $MAX_NETS; $i++) {
+ next if !$conf->{"net$i"};
+ my $d = parse_net($conf->{"net$i"});
+ next if !$d;
+ if ($d->{model} eq 'virtio-vhost-user') {
+ my $interface = "vhost-user".$vmid."i".$i;
+ #remove old uncleaned port
+ if(-e "/var/run/openvswitch/$interface") {
+ run_command("/usr/bin/ovs-vsctl del-port $interface", outfunc => sub {}, errfunc => sub {});
+ }
+ PVE::Network::ovs_bridge_add_port($d->{bridge}, $interface, $d->{vlan}, 'dpdkvhostuser', $d->{trunks});
+ }
+ }
+
PVE::Storage::activate_volumes($storecfg, $vollist);
if (!check_running($vmid, 1) && -d "/sys/fs/cgroup/systemd/qemu.slice/$vmid.scope") {
@@ -4782,6 +4809,17 @@ sub vm_stop_cleanup {
unlink "/var/run/qemu-server/${vmid}.$ext";
}
+ #ovs vhost-user
+ for (my $i = 0; $i < $MAX_NETS; $i++) {
+ next if !$conf->{"net$i"};
+ my $d = parse_net($conf->{"net$i"});
+ next if !$d;
+ if ($d->{model} eq 'virtio-vhost-user') {
+ my $ovsintport = "vhost-user".$vmid."i".$i;
+ run_command("/usr/bin/ovs-vsctl del-port $ovsintport", outfunc => sub {}, errfunc => sub {});
+ }
+ }
+
vmconfig_apply_pending($vmid, $conf, $storecfg) if $apply_pending_changes;
};
warn $@ if $@; # avoid errors - just warn
--
2.1.4
More information about the pve-devel
mailing list