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@xxxxxxxxxx> --- src/qemu/qemu_migration.c | 17 +++++++++++++++-- src/util/virnetdevmacvlan.c | 17 +++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 09adb04..0308043 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,19 @@ 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) != VIR_NETDEV_VPORT_PROFILE_8021QBG && + virDomainNetGetActualVirtPortProfile(net) != 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 +5200,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..fc08c43 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 == VIR_NETDEV_VPORT_PROFILE_8021QBH || + virtPortProfile == 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 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list