[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [v2 RESEND PATCH] qemu: reduce packet loss rate for vm with macvtap passthrough mode in migration



Before libvirt that calls virNetDevMacVLanCreateWithVPortProfile sets mac address
or vlan of a Virtual Function(VF) linked to a macvtap passthrough device of migration
destination host in migration start step. If we ping the migrating vm,
we get the network does not pass. Because VFs of migration source and destination
have the same MAC address. The patch later calling qemuMigrationVPAssociatePortProfiles
sets mac address of VF in migration finish step instead of start step.
The patch aims to reduce packet loss rate.

Signed-off-by: ZhiPeng Lu <lu zhipeng zte com cn>
---
 src/qemu/qemu_migration.c   | 18 ++++++++++++++++--
 src/util/virnetdevmacvlan.c | 17 +++++++++++------
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 09adb04..795ed71 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5004,7 +5004,7 @@ qemuMigrationPerform(virQEMUDriverPtr driver,
 }
 
 static int
-qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def)
+qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def, const char *stateDir)
 {
     size_t i;
     int last_good_net = -1;
@@ -5013,6 +5013,20 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def)
     for (i = 0; i < def->nnets; i++) {
         net = def->nets[i];
         if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
+            if ((!virDomainNetGetActualVirtPortProfile(net) || (virDomainNetGetActualVirtPortProfile(net) &&
+                 virDomainNetGetActualVirtPortProfile(net)->virtPortType != VIR_NETDEV_VPORT_PROFILE_8021QBG &&
+                virDomainNetGetActualVirtPortProfile(net)->virtPortType != VIR_NETDEV_VPORT_PROFILE_8021QBH)) &&
+                virDomainNetGetActualDirectMode(net) ==
+                 VIR_NETDEV_MACVLAN_MODE_PASSTHRU) {
+                if (virNetDevSaveNetConfig(virDomainNetGetActualDirectDev(net),
+                    -1, stateDir, false) < 0) {
+                    goto err_exit;
+                }
+                if (virNetDevSetNetConfig(virDomainNetGetActualDirectDev(net),
+                    -1, NULL, virDomainNetGetActualVlan(net), &net->mac, false) < 0) {
+                    goto err_exit;
+                }
+            }
             if (virNetDevVPortProfileAssociate(net->ifname,
                                                virDomainNetGetActualVirtPortProfile(net),
                                                &net->mac,
@@ -5187,7 +5201,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
         goto endjob;
     }
 
-    if (qemuMigrationVPAssociatePortProfiles(vm->def) < 0)
+    if (qemuMigrationVPAssociatePortProfiles(vm->def, cfg->stateDir) < 0)
         goto endjob;
 
     if (mig->network && qemuDomainMigrateOPDRelocate(driver, vm, mig) < 0)
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 7222b0f..682dcd1 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -1020,12 +1020,17 @@ virNetDevMacVLanCreateWithVPortProfile(const char *ifnameRequested,
              */
             setVlan = false;
         }
-
-        if (virNetDevSaveNetConfig(linkdev, -1, stateDir, setVlan) < 0)
-           return -1;
-
-        if (virNetDevSetNetConfig(linkdev, -1, NULL, vlan, macaddress, setVlan) < 0)
-           return -1;
+        if (vmOp != VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_START &&
+            virtPortProfile && (virtPortProfile->virtPortType == VIR_NETDEV_VPORT_PROFILE_8021QBH ||
+            virtPortProfile->virtPortType == VIR_NETDEV_VPORT_PROFILE_8021QBG)) {
+            if (virNetDevSaveNetConfig(linkdev, -1, stateDir, setVlan) < 0) {
+                return -1;
+            }
+            if (virNetDevSetNetConfig(linkdev, -1, NULL, vlan, macaddress,
+                setVlan) < 0) {
+                return -1;
+            }
+        }
     }
 
     if (ifnameRequested) {
-- 
1.8.3.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]