1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun============ 4*4882a593SmuzhiyunNET_FAILOVER 5*4882a593Smuzhiyun============ 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunOverview 8*4882a593Smuzhiyun======== 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunThe net_failover driver provides an automated failover mechanism via APIs 11*4882a593Smuzhiyunto create and destroy a failover master netdev and manages a primary and 12*4882a593Smuzhiyunstandby slave netdevs that get registered via the generic failover 13*4882a593Smuzhiyuninfrastructure. 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunThe failover netdev acts a master device and controls 2 slave devices. The 16*4882a593Smuzhiyunoriginal paravirtual interface is registered as 'standby' slave netdev and 17*4882a593Smuzhiyuna passthru/vf device with the same MAC gets registered as 'primary' slave 18*4882a593Smuzhiyunnetdev. Both 'standby' and 'failover' netdevs are associated with the same 19*4882a593Smuzhiyun'pci' device. The user accesses the network interface via 'failover' netdev. 20*4882a593SmuzhiyunThe 'failover' netdev chooses 'primary' netdev as default for transmits when 21*4882a593Smuzhiyunit is available with link up and running. 22*4882a593Smuzhiyun 23*4882a593SmuzhiyunThis can be used by paravirtual drivers to enable an alternate low latency 24*4882a593Smuzhiyundatapath. It also enables hypervisor controlled live migration of a VM with 25*4882a593Smuzhiyundirect attached VF by failing over to the paravirtual datapath when the VF 26*4882a593Smuzhiyunis unplugged. 27*4882a593Smuzhiyun 28*4882a593Smuzhiyunvirtio-net accelerated datapath: STANDBY mode 29*4882a593Smuzhiyun============================================= 30*4882a593Smuzhiyun 31*4882a593Smuzhiyunnet_failover enables hypervisor controlled accelerated datapath to virtio-net 32*4882a593Smuzhiyunenabled VMs in a transparent manner with no/minimal guest userspace changes. 33*4882a593Smuzhiyun 34*4882a593SmuzhiyunTo support this, the hypervisor needs to enable VIRTIO_NET_F_STANDBY 35*4882a593Smuzhiyunfeature on the virtio-net interface and assign the same MAC address to both 36*4882a593Smuzhiyunvirtio-net and VF interfaces. 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunHere is an example XML snippet that shows such configuration. 39*4882a593Smuzhiyun:: 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun <interface type='network'> 42*4882a593Smuzhiyun <mac address='52:54:00:00:12:53'/> 43*4882a593Smuzhiyun <source network='enp66s0f0_br'/> 44*4882a593Smuzhiyun <target dev='tap01'/> 45*4882a593Smuzhiyun <model type='virtio'/> 46*4882a593Smuzhiyun <driver name='vhost' queues='4'/> 47*4882a593Smuzhiyun <link state='down'/> 48*4882a593Smuzhiyun <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/> 49*4882a593Smuzhiyun </interface> 50*4882a593Smuzhiyun <interface type='hostdev' managed='yes'> 51*4882a593Smuzhiyun <mac address='52:54:00:00:12:53'/> 52*4882a593Smuzhiyun <source> 53*4882a593Smuzhiyun <address type='pci' domain='0x0000' bus='0x42' slot='0x02' function='0x5'/> 54*4882a593Smuzhiyun </source> 55*4882a593Smuzhiyun <address type='pci' domain='0x0000' bus='0x00' slot='0x0b' function='0x0'/> 56*4882a593Smuzhiyun </interface> 57*4882a593Smuzhiyun 58*4882a593SmuzhiyunBooting a VM with the above configuration will result in the following 3 59*4882a593Smuzhiyunnetdevs created in the VM. 60*4882a593Smuzhiyun:: 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun 4: ens10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 63*4882a593Smuzhiyun link/ether 52:54:00:00:12:53 brd ff:ff:ff:ff:ff:ff 64*4882a593Smuzhiyun inet 192.168.12.53/24 brd 192.168.12.255 scope global dynamic ens10 65*4882a593Smuzhiyun valid_lft 42482sec preferred_lft 42482sec 66*4882a593Smuzhiyun inet6 fe80::97d8:db2:8c10:b6d6/64 scope link 67*4882a593Smuzhiyun valid_lft forever preferred_lft forever 68*4882a593Smuzhiyun 5: ens10nsby: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master ens10 state UP group default qlen 1000 69*4882a593Smuzhiyun link/ether 52:54:00:00:12:53 brd ff:ff:ff:ff:ff:ff 70*4882a593Smuzhiyun 7: ens11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master ens10 state UP group default qlen 1000 71*4882a593Smuzhiyun link/ether 52:54:00:00:12:53 brd ff:ff:ff:ff:ff:ff 72*4882a593Smuzhiyun 73*4882a593Smuzhiyunens10 is the 'failover' master netdev, ens10nsby and ens11 are the slave 74*4882a593Smuzhiyun'standby' and 'primary' netdevs respectively. 75*4882a593Smuzhiyun 76*4882a593SmuzhiyunLive Migration of a VM with SR-IOV VF & virtio-net in STANDBY mode 77*4882a593Smuzhiyun================================================================== 78*4882a593Smuzhiyun 79*4882a593Smuzhiyunnet_failover also enables hypervisor controlled live migration to be supported 80*4882a593Smuzhiyunwith VMs that have direct attached SR-IOV VF devices by automatic failover to 81*4882a593Smuzhiyunthe paravirtual datapath when the VF is unplugged. 82*4882a593Smuzhiyun 83*4882a593SmuzhiyunHere is a sample script that shows the steps to initiate live migration on 84*4882a593Smuzhiyunthe source hypervisor. 85*4882a593Smuzhiyun:: 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun # cat vf_xml 88*4882a593Smuzhiyun <interface type='hostdev' managed='yes'> 89*4882a593Smuzhiyun <mac address='52:54:00:00:12:53'/> 90*4882a593Smuzhiyun <source> 91*4882a593Smuzhiyun <address type='pci' domain='0x0000' bus='0x42' slot='0x02' function='0x5'/> 92*4882a593Smuzhiyun </source> 93*4882a593Smuzhiyun <address type='pci' domain='0x0000' bus='0x00' slot='0x0b' function='0x0'/> 94*4882a593Smuzhiyun </interface> 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun # Source Hypervisor 97*4882a593Smuzhiyun #!/bin/bash 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun DOMAIN=fedora27-tap01 100*4882a593Smuzhiyun PF=enp66s0f0 101*4882a593Smuzhiyun VF_NUM=5 102*4882a593Smuzhiyun TAP_IF=tap01 103*4882a593Smuzhiyun VF_XML= 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun MAC=52:54:00:00:12:53 106*4882a593Smuzhiyun ZERO_MAC=00:00:00:00:00:00 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun virsh domif-setlink $DOMAIN $TAP_IF up 109*4882a593Smuzhiyun bridge fdb del $MAC dev $PF master 110*4882a593Smuzhiyun virsh detach-device $DOMAIN $VF_XML 111*4882a593Smuzhiyun ip link set $PF vf $VF_NUM mac $ZERO_MAC 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun virsh migrate --live $DOMAIN qemu+ssh://$REMOTE_HOST/system 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun # Destination Hypervisor 116*4882a593Smuzhiyun #!/bin/bash 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun virsh attach-device $DOMAIN $VF_XML 119*4882a593Smuzhiyun virsh domif-setlink $DOMAIN $TAP_IF down 120